index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. //0.3.1设置站点基本信息
  90. templateBaseStore.setWebSiteInfo(responseStatus.data as IWebSiteBase)
  91. websiteId.value = responseStatus.data.website_head.id;//获得网站id
  92. //0.3.2设置皮肤id
  93. skinId.value = templateBaseStore.webSiteInfo.website_foot.foot_info.template_id;
  94. console.log("当前的网站id:"+responseStatus.data.website_head.id)
  95. //0.3.3设置seo信息
  96. let seoTitle = templateBaseStore.webSiteInfo.website_head.title;
  97. let seoDescription = templateBaseStore.webSiteInfo.website_head.description;
  98. let seoKeywords = templateBaseStore.webSiteInfo.website_head.keywords;
  99. let seoSuffix = templateBaseStore.webSiteInfo.website_head.suffix;
  100. let seoName = templateBaseStore.webSiteInfo.website_head.website_name;
  101. useHead({
  102. title: seoTitle + "_" + seoSuffix,
  103. meta: [
  104. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  105. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  106. ]
  107. });
  108. }else if(responseStatus.code == 0){
  109. navigateTo('/404?findPage=index')
  110. }
  111. } catch (error) {
  112. navigateTo('/404?findPage=index')
  113. }
  114. //1.获得基本信息单元 end---------------------------------------->
  115. //2.页面数据 start---------------------------------------->
  116. //2.1获得页面数据
  117. const templateData = ref<any[]>([])
  118. const adData = ref<any[]>([]);
  119. try {
  120. const response = await requestDataPromise('/client/indexData', {
  121. method: 'POST',
  122. body: {
  123. 'website_id':websiteId.value,
  124. 'getpage':'index'
  125. },
  126. });
  127. console.log(response)
  128. if(response.code == 200){
  129. //页面数据
  130. templateData.value = response.data.template.index;
  131. //广告数据
  132. adData.value.push(response.data.ad.top)
  133. for(let item of response.data.ad.index){
  134. adData.value.push(item)
  135. }
  136. templateBaseStore.setAdList(adData.value)
  137. }else if(response.code == 0){
  138. //第一种情况,code为0 跳转到404
  139. navigateTo('/404?findPage=index')
  140. }
  141. }catch (error) {
  142. //第二种情况,服务器无响应 跳转到404
  143. navigateTo('/404?findPage=index')
  144. }
  145. //2.页面数据 end---------------------------------------->
  146. </script>
  147. <style lang="less" scoped>
  148. @import url('@/assets/css/index.less');
  149. </style>