detail.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. <!-- 推荐阅读 -->
  49. <div class="recommendRead" v-if="newsDetail.commendArticle != false">
  50. <div class="recommendReadTitle">
  51. 推荐阅读
  52. </div>
  53. <div class="recommendReadList">
  54. <div class="recommendReadListTitle" v-for="(item, index) in newsDetail.commendArticle"
  55. :key="item.id">
  56. <a :href="`/${item.alias_pinyin}/${item.id}.html`" v-if="index < 3">
  57. {{ item.title }}
  58. </a>
  59. <span v-if="index < 3">{{ getTime(item.created_at, "month", 1) }}</span>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <div class="innerRight">
  65. <!-- 热点资讯1 -->
  66. <div class="hotList1">
  67. <DetailHotNews></DetailHotNews>
  68. </div>
  69. <!-- 热点资讯2 -->
  70. <div class="hotList2">
  71. <DetailHotNews2></DetailHotNews2>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. <!-- 列表页广告二 -->
  77. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  78. <!-- 页面底部 -->
  79. <HomeFoot1></HomeFoot1>
  80. </template>
  81. <script setup>
  82. //1.页面依赖 start ---------------------------------------->
  83. import { onMounted } from 'vue'
  84. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  85. import { ArrowRight } from '@element-plus/icons-vue'
  86. //1.页面依赖 end ---------------------------------------->
  87. //2.页面路径 start ---------------------------------------->
  88. const targetSegment = getRoutePath(1);
  89. let routeId;
  90. //通过导航路径反向查询导航id
  91. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  92. method: 'GET',
  93. query: {
  94. 'pinyin': targetSegment,
  95. },
  96. });
  97. if (getRouteId.code == 200) {
  98. routeId = getRouteId.data.category_id
  99. } else {
  100. console.log("错误位置:获得页面路径")
  101. }
  102. //2.页面路径 start ---------------------------------------->
  103. //3.面包屑 start ---------------------------------------->
  104. const route = useRoute();
  105. const articleId = parseInt(route.params.id); //获得该页面的id
  106. //3.1 获得父级栏目的名称、id
  107. const parent_name = ref([]);
  108. const parent_id = ref([]);
  109. const parent_pinyin = ref("");
  110. const parent_children_count = ref(0)
  111. let getParentNav = async () => {
  112. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  113. method: 'GET',
  114. query: {
  115. 'catid': routeId
  116. },
  117. });
  118. if (listData.code == 200) {
  119. console.log(778899)
  120. console.log(listData.data)
  121. parent_name.value = listData.data.alias;
  122. parent_id.value = listData.data.parent_id;
  123. parent_pinyin.value = listData.data.aLIas_pinyin;
  124. parent_children_count.value = listData.data.children_count;
  125. } else {
  126. console.log("错误位置:获取面包屑导航")
  127. }
  128. }
  129. getParentNav();
  130. //3.页面依赖 end ---------------------------------------->
  131. //4.页面数据 start ---------------------------------------->
  132. //4.1 资讯详情
  133. const newsDetail = ref({})
  134. const routeNewsTtitle = ref("");
  135. //4.2 发布日期
  136. const time = ref("");
  137. //4.3 路径
  138. const routLevelTitle = ref("");
  139. const routLevelId = ref("");
  140. //4.4 是否展示投票
  141. const articleChoice = ref(false);
  142. //4.5 获取详情
  143. async function getPageData() {
  144. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  145. method: 'GET',
  146. query: {
  147. 'articleid': articleId
  148. },
  149. });
  150. if (mkdata.code == 200) {
  151. //判断是否显示投票
  152. if (mkdata.data.is_survey == 1) {
  153. console.log("本篇文章含有投票!")
  154. articleChoice.value = true;
  155. }
  156. //获取内容
  157. newsDetail.value = mkdata.data;
  158. //获取路径
  159. routLevelTitle.value = newsDetail.value.cat_name;
  160. routLevelId.value = newsDetail.value.category_id;
  161. //获取发布时间
  162. time.value = newsDetail.value.updated_at.split(' ')[0];
  163. //修正标题长度
  164. if (newsDetail.value.title.length >= 30) {
  165. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  166. } else {
  167. routeNewsTtitle.value = newsDetail.value.title
  168. }
  169. } else {
  170. console.log("错误位置:获取详情内容")
  171. }
  172. }
  173. getPageData();
  174. //4.页面数据 end ---------------------------------------->
  175. //5.广告 start ---------------------------------------->
  176. let adImg1 = ref([]);
  177. let adImg2 = ref([]);
  178. onMounted(async () => {
  179. const { $webUrl, $CwebUrl } = useNuxtApp();
  180. //广告1
  181. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_detail_0001`
  182. const responseAd1 = await fetch(url, {
  183. headers: {
  184. 'Content-Type': 'application/json',
  185. 'Userurl': $CwebUrl,
  186. 'Origin': $CwebUrl
  187. }
  188. });
  189. const resultAd1 = await responseAd1.json();
  190. adImg1.value = resultAd1.data[0];
  191. //广告2
  192. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_detail_0002`
  193. const responseAd2 = await fetch(url2, {
  194. headers: {
  195. 'Content-Type': 'application/json',
  196. 'Userurl': $CwebUrl,
  197. 'Origin': $CwebUrl
  198. }
  199. });
  200. const resultAd2 = await responseAd2.json();
  201. adImg2.value = resultAd2.data[0];
  202. })
  203. //5.广告 end ---------------------------------------->
  204. //6.设置seo信息 start---------------------------------------->
  205. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  206. method: 'GET',
  207. query: {
  208. 'articleid': articleId
  209. },
  210. });
  211. if (setData.code == 200) {
  212. let seoTitle = setData.data.title;
  213. let seoDescription = setData.data.introduce;
  214. let seoKeywords = setData.data.keyword;
  215. let seoSuffix = setData.data.suffix;
  216. let seoName = setData.data.website_name;
  217. useSeoMeta({
  218. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  219. meta: [
  220. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  221. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  222. ]
  223. });
  224. } else {
  225. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  226. console.log("错误位置:设置详情页面SEO数据")
  227. console.log("后端错误反馈:", setData.message)
  228. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  229. }
  230. //6.设置seo信息 end---------------------------------------->
  231. //8.页面图片放大 start---------------------------------------->
  232. const previewVisible = ref(false)
  233. const selectedImage = ref(' ')
  234. const openPreview = (event) => {
  235. if (event.target.tagName === 'IMG') {
  236. selectedImage.value = event.target.src;
  237. previewVisible.value = true;
  238. }
  239. }
  240. const closePreview = () => {
  241. previewVisible.value = false;
  242. }
  243. //8.页面图片放大 end---------------------------------------->
  244. </script>
  245. <style lang="less" scoped>
  246. @import url('@/assets/css/detail.less');
  247. </style>