index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <!-- 头部 -->
  3. <templateHead></templateHead>
  4. <!-- 菜单 -->
  5. <templateMenu></templateMenu>
  6. <!-- 内容 -->
  7. <div v-for="(item,index) in templateData" :key="index">
  8. <!--1.广告通栏-->
  9. <div v-if="item.sectorName=='adSector'">
  10. <templateAd :skinId="skinId" :adData="adData" :adTag="item.ad.ad_tag"></templateAd>
  11. </div>
  12. <!--2.头条通栏 data返回值错误 没有依照level字段返回 而是返回了政策法规-->
  13. <div v-if="item.sectorName=='headLineSector'">
  14. <templateHeadline :skinId="skinId" :templateData="item.componentList"></templateHeadline>
  15. </div>
  16. <!--3.轮播图通栏 data返回值错误 没有依照level字段返回 而是返回了政策法规-->
  17. <div v-if="item.sectorName=='bannerSector'">
  18. <templateBanner :skinId="skinId" :templateData="item.componentList"></templateBanner>
  19. </div>
  20. <!--4.静态外链通栏-->
  21. <div v-if="item.sectorName=='linkSector'">
  22. <templateStaticLink :skinId="skinId"></templateStaticLink>
  23. </div>
  24. <!--5.图文组合1 标题字段缺少is_url / children_count-->
  25. <div v-if="item.sectorName=='manyPictureSector'">
  26. <templateNewSector1 :skinId="skinId" :templateData="item.componentList"></templateNewSector1>
  27. </div>
  28. <!--6.图文组合2 标题字段缺少is_url / children_count-->
  29. <div v-if="item.sectorName=='commentSector'">
  30. <templateNewSector2 :skinId="skinId" :templateData="item.componentList"></templateNewSector2>
  31. </div>
  32. <!--7.图文组合3 标题字段缺少is_url / children_count-->
  33. <div v-if="item.sectorName=='listSector'">
  34. <templateNewSector3 :skinId="skinId" :templateData="item.componentList"></templateNewSector3>
  35. </div>
  36. <!--8.图文混合模块 标题字段缺少is_url / children_count-->
  37. <div v-if="item.sectorName=='onlyImgSector'">
  38. <templateNewAndAd :skinId="skinId" :templateData="item.componentList" :adData="adData" :adTag="item.ad.ad_tag"></templateNewAndAd>
  39. </div>
  40. </div>
  41. <!-- 底部 -->
  42. <templateFoot></templateFoot>
  43. </template>
  44. <script setup lang="ts">
  45. import type { IWebSiteBase } from '@/utils/dataInterface'
  46. //0.加载全局模板组件 start---------------------------------------->
  47. //0.1 全局通栏
  48. import templateHead from '@/components/template/sector/head/1200x200/1.vue'
  49. import templateMenu from '@/components/template/sector/menu/1200x130/1.vue'
  50. import templateFoot from '@/components/template/sector/foot/1200x580/1.vue'
  51. //0.2 局部通栏
  52. //0.2.1 广告组件
  53. import templateAd from '@/components/template/sector/body/ad/1200x90/1.vue'
  54. //0.2.2 网站头条
  55. import templateHeadline from '@/components/template/sector/body/index/headLine/1200x140/1.vue'
  56. //0.2.3 轮播图
  57. import templateBanner from '@/components/template/sector/body/index/banner/1200x410/1.vue'
  58. //0.2.4 静态外链通栏
  59. import templateStaticLink from '@/components/template/sector/body/index/link/1200x230/1.vue'
  60. //0.2.5 图文组合1
  61. import templateNewSector1 from '@/components/template/sector/body/index/list/1200x470/1.vue'
  62. //0.2.6 图文组合2
  63. import templateNewSector2 from '@/components/template/sector/body/index/list/1200x470/2.vue'
  64. //0.2.7 图文组合3
  65. import templateNewSector3 from '@/components/template/sector/body/index/list/1200x980/1.vue'
  66. //0.2.8 图文与广告组合
  67. import templateNewAndAd from '@/components/template/sector/body/index/list/1200x480/1.vue'
  68. // //0.加载全局模板组件 end---------------------------------------->
  69. //1.获得基本信息单元 start---------------------------------------->
  70. //1.1获得页面依赖
  71. import { ref } from 'vue';
  72. //1.2获得pinia源
  73. import { useTemplateBaseStore } from '@/stores/templateBase'
  74. const templateBaseStore:any = useTemplateBaseStore()
  75. //1.3获得该页的皮肤id - 在每个组件中也是同样的获得方法
  76. const skinId = ref<number>(0)
  77. const websiteId = ref<number>(0)
  78. //1.4获得站点基本信息
  79. try {
  80. const responseStatus:any = await requestDataPromise('/web/getWebsiteAllinfo', {
  81. method: 'GET',
  82. query: {
  83. 'link_textnum':24,
  84. 'link_imgnum':18,
  85. 'link_footnum':4
  86. },
  87. });
  88. if (responseStatus.code == 200) {
  89. if(responseStatus.data.website_foot.foot_info.status == 1){
  90. //网站模板已停用,直接转入404页面
  91. navigateTo('/error?findPage=index')
  92. }else{
  93. //0.3.1设置站点基本信息
  94. templateBaseStore.setWebSiteInfo(responseStatus.data as IWebSiteBase)
  95. websiteId.value = responseStatus.data.website_head.id;//获得网站id
  96. //0.3.2设置皮肤id
  97. skinId.value = templateBaseStore.webSiteInfo.website_foot.foot_info.template_id;
  98. console.log("当前的网站id:"+responseStatus.data.website_head.id)
  99. //0.3.3设置seo信息
  100. let seoTitle = templateBaseStore.webSiteInfo.website_head.title;
  101. let seoDescription = templateBaseStore.webSiteInfo.website_head.description;
  102. let seoKeywords = templateBaseStore.webSiteInfo.website_head.keywords;
  103. let seoSuffix = templateBaseStore.webSiteInfo.website_head.suffix;
  104. let seoName = templateBaseStore.webSiteInfo.website_head.website_name;
  105. useHead({
  106. title: seoTitle + "_" + seoSuffix,
  107. meta: [
  108. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  109. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  110. ]
  111. });
  112. }
  113. }else if(responseStatus.code == 0){
  114. navigateTo('/error?findPage=index')
  115. }
  116. } catch (error) {
  117. navigateTo('/error?findPage=index')
  118. }
  119. //1.获得基本信息单元 end---------------------------------------->
  120. //2.页面数据 start---------------------------------------->
  121. //2.1获得页面数据
  122. const templateData = ref<any[]>([])
  123. const adData = ref<any[]>([]);
  124. try {
  125. const response = await requestDataPromise('/client/indexData', {
  126. method: 'POST',
  127. body: {
  128. 'website_id':websiteId.value,
  129. 'getpage':'index'
  130. },
  131. });
  132. console.log(response)
  133. if(response.code == 200){
  134. //页面数据
  135. templateData.value = response.data.template.index;
  136. //是否启用搜索功能
  137. templateBaseStore.setIsSearch(response.data.isSearch)
  138. //广告数据
  139. adData.value.push(response.data.ad.top)
  140. for(let item of response.data.ad.index){
  141. adData.value.push(item)
  142. }
  143. templateBaseStore.setAdList(adData.value)
  144. }else if(response.code == 0){
  145. //第一种情况,code为0 跳转到404
  146. navigateTo('/error?findPage=index')
  147. }
  148. }catch (error) {
  149. //第二种情况,服务器无响应 跳转到404
  150. navigateTo('/error?findPage=index')
  151. }
  152. //2.页面数据 end---------------------------------------->
  153. </script>
  154. <style lang="less" scoped>
  155. @import url('@/assets/css/index.less');
  156. </style>