detail.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation></HomePageNavigation>
  6. <!-- 列表页广告一 -->
  7. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  8. <!-- 资讯列表 -->
  9. <div class="newsDetail">
  10. <div class="inner">
  11. <div class="innerLeft">
  12. <!-- 面包屑导航 -->
  13. <div class="breadcrumb">
  14. <div class="inner">
  15. <span class="location">当前位置:</span>
  16. <el-breadcrumb :separator-icon="ArrowRight">
  17. <el-breadcrumb-item>
  18. <NuxtLink to="/">首页</NuxtLink>
  19. </el-breadcrumb-item>
  20. <el-breadcrumb-item v-if="parent_name != ''">
  21. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  22. </el-breadcrumb-item>
  23. <el-breadcrumb-item>{{ getTitleLength(routeNewsTtitle, 20) }}</el-breadcrumb-item>
  24. </el-breadcrumb>
  25. </div>
  26. </div>
  27. <div class="LeftTop">
  28. <h1>{{ newsDetail.title }}</h1>
  29. <p>
  30. 来源: <span>{{ newsDetail.copyfrom }}</span>
  31. 作者: <span>{{ newsDetail.author }}</span>
  32. 发布时间: <span>{{ time }}</span>
  33. </p>
  34. </div>
  35. <div class="leftBottom" v-html="newsDetail.content" v-if="newsDetail.content" @click="openPreview">
  36. </div>
  37. <div v-if="previewVisible" class="preview-modal" @click="closePreview">
  38. <img :src="selectedImage" alt="Preview">
  39. </div>
  40. <!-- 免责声明: -->
  41. <div class="disclaimer" v-if="newsDetail.copyfrom != '本网'">
  42. <p>原文链接:{{ newsDetail.fromurl }}</p>
  43. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  44. </div>
  45. <div v-if="articleChoice">
  46. <HomeSurveyvote></HomeSurveyvote>
  47. </div>
  48. </div>
  49. <div class="innerRight">
  50. <!-- 热点资讯1 -->
  51. <div class="hotList1">
  52. <DetailHotNews></DetailHotNews>
  53. </div>
  54. <!-- 热点资讯2 -->
  55. <div class="hotList2">
  56. <DetailHotNews2></DetailHotNews2>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- 列表页广告二 -->
  62. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  63. <!-- 页面底部 -->
  64. <HomeFoot1></HomeFoot1>
  65. </template>
  66. <script setup>
  67. //1.页面依赖 start ---------------------------------------->
  68. import { onMounted } from 'vue'
  69. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  70. import { ArrowRight } from '@element-plus/icons-vue'
  71. //1.页面依赖 end ---------------------------------------->
  72. //2.页面路径 start ---------------------------------------->
  73. const targetSegment = getRoutePath(1);
  74. let routeId;
  75. //通过导航路径反向查询导航id
  76. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  77. method: 'GET',
  78. query: {
  79. 'pinyin': targetSegment,
  80. },
  81. });
  82. if (getRouteId.code == 200) {
  83. routeId = getRouteId.data.category_id
  84. } else {
  85. console.log("错误位置:获得页面路径")
  86. }
  87. //2.页面路径 start ---------------------------------------->
  88. //3.面包屑 start ---------------------------------------->
  89. const route = useRoute();
  90. const articleId = parseInt(route.params.id); //获得该页面的id
  91. //3.1 获得父级栏目的名称、id
  92. const parent_name = ref([]);
  93. const parent_id = ref([]);
  94. const parent_pinyin = ref("");
  95. const parent_children_count = ref(0)
  96. let getParentNav = async () => {
  97. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  98. method: 'GET',
  99. query: {
  100. 'catid': routeId
  101. },
  102. });
  103. if (listData.code == 200) {
  104. console.log(778899)
  105. console.log(listData.data)
  106. parent_name.value = listData.data.alias;
  107. parent_id.value = listData.data.parent_id;
  108. parent_pinyin.value = listData.data.aLIas_pinyin;
  109. parent_children_count.value = listData.data.children_count;
  110. } else {
  111. console.log("错误位置:获取面包屑导航")
  112. }
  113. }
  114. getParentNav();
  115. //3.页面依赖 end ---------------------------------------->
  116. //4.页面数据 start ---------------------------------------->
  117. //4.1 资讯详情
  118. const newsDetail = ref({})
  119. const routeNewsTtitle = ref("");
  120. //4.2 发布日期
  121. const time = ref("");
  122. //4.3 路径
  123. const routLevelTitle = ref("");
  124. const routLevelId = ref("");
  125. //4.4 是否展示投票
  126. const articleChoice = ref(false);
  127. //4.5 获取详情
  128. async function getPageData() {
  129. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  130. method: 'GET',
  131. query: {
  132. 'articleid': articleId
  133. },
  134. });
  135. if (mkdata.code == 200) {
  136. //判断是否显示投票
  137. if (mkdata.data.is_survey == 1) {
  138. console.log("本篇文章含有投票!")
  139. articleChoice.value = true;
  140. }
  141. //获取内容
  142. newsDetail.value = mkdata.data;
  143. //获取路径
  144. routLevelTitle.value = newsDetail.value.cat_name;
  145. routLevelId.value = newsDetail.value.category_id;
  146. //获取发布时间
  147. time.value = newsDetail.value.updated_at.split(' ')[0];
  148. //修正标题长度
  149. if (newsDetail.value.title.length >= 30) {
  150. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  151. } else {
  152. routeNewsTtitle.value = newsDetail.value.title
  153. }
  154. } else {
  155. console.log("错误位置:获取详情内容")
  156. }
  157. }
  158. getPageData();
  159. //4.页面数据 end ---------------------------------------->
  160. //5.广告 start ---------------------------------------->
  161. let adImg1 = ref([]);
  162. let adImg2 = ref([]);
  163. onMounted(async () => {
  164. const { $webUrl, $CwebUrl } = useNuxtApp();
  165. //广告1
  166. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_detail_0001`
  167. const responseAd1 = await fetch(url, {
  168. headers: {
  169. 'Content-Type': 'application/json',
  170. 'Userurl': $CwebUrl,
  171. 'Origin': $CwebUrl
  172. }
  173. });
  174. const resultAd1 = await responseAd1.json();
  175. adImg1.value = resultAd1.data[0];
  176. //广告2
  177. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_detail_0002`
  178. const responseAd2 = await fetch(url2, {
  179. headers: {
  180. 'Content-Type': 'application/json',
  181. 'Userurl': $CwebUrl,
  182. 'Origin': $CwebUrl
  183. }
  184. });
  185. const resultAd2 = await responseAd2.json();
  186. adImg2.value = resultAd2.data[0];
  187. })
  188. //5.广告 end ---------------------------------------->
  189. //6.设置seo信息 start---------------------------------------->
  190. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  191. method: 'GET',
  192. query: {
  193. 'articleid': articleId
  194. },
  195. });
  196. if (setData.code == 200) {
  197. let seoTitle = setData.data.title;
  198. let seoDescription = setData.data.introduce;
  199. let seoKeywords = setData.data.keyword;
  200. let seoSuffix = setData.data.suffix;
  201. let seoName = setData.data.website_name;
  202. useSeoMeta({
  203. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  204. meta: [
  205. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  206. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  207. ]
  208. });
  209. } else {
  210. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  211. console.log("错误位置:设置详情页面SEO数据")
  212. console.log("后端错误反馈:", setData.message)
  213. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  214. }
  215. //6.设置seo信息 end---------------------------------------->
  216. //8.页面图片放大 start---------------------------------------->
  217. const previewVisible = ref(false)
  218. const selectedImage = ref(' ')
  219. const openPreview = (event) => {
  220. if (event.target.tagName === 'IMG') {
  221. selectedImage.value = event.target.src;
  222. previewVisible.value = true;
  223. }
  224. }
  225. const closePreview = () => {
  226. previewVisible.value = false;
  227. }
  228. //8.页面图片放大 end---------------------------------------->
  229. </script>
  230. <style lang="less" scoped>
  231. @import url('@/assets/css/detail.less');
  232. </style>