detail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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 breadcrumb_phone_none">
  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="breadcrumb_box breadcrumb_pc_none">
  28. <span class=" ">当前位置:</span>
  29. <NuxtLink to="/">首页</NuxtLink>
  30. <span class=" ">&gt;</span>
  31. <NuxtLink :to="`/${parent_pinyin}/index.html`" v-if="parent_name != ''"> {{ parent_name }}</NuxtLink>
  32. <span class=" " v-if="parent_name != ''">&gt;</span>
  33. <span class=" ">
  34. {{ routeNewsTtitle }}
  35. </span>
  36. </div>
  37. <div class="LeftTop">
  38. <h1>{{ newsDetail.title }}</h1>
  39. <p class="phone_none">
  40. 来源: <span>{{ newsDetail.copyfrom }}</span>
  41. 作者: <span>{{ newsDetail.author }}</span>
  42. 发布时间: <span>{{ time }}</span>
  43. </p>
  44. <p class="pc_none">
  45. <span>{{ newsDetail.copyfrom }}</span>
  46. <span>{{ newsDetail.author }}</span>
  47. <span>{{ time }}</span>
  48. </p>
  49. </div>
  50. <div class="leftBottom" v-html="newsDetail.content" v-if="newsDetail.content" @click="openPreview">
  51. </div>
  52. <div v-if="previewVisible" class="preview-modal" @click="closePreview">
  53. <img :src="selectedImage" alt="Preview">
  54. </div>
  55. <!-- 免责声明: -->
  56. <div class="disclaimer" v-if="newsDetail.copyfrom != '本网'">
  57. <p>原文链接:{{ newsDetail.fromurl }}</p>
  58. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  59. </div>
  60. <div v-if="articleChoice">
  61. <HomeSurveyvote></HomeSurveyvote>
  62. </div>
  63. <!-- 推荐阅读 -->
  64. <div class="recommendRead" v-if="newsDetail.commendArticle != false">
  65. <div class="recommendReadTitle phone_none">
  66. 推荐阅读
  67. </div>
  68. <div class="phone_box_1_head pc_none">
  69. <a class="" title="">推荐阅读</a>
  70. </div>
  71. <div class="recommendReadList">
  72. <div class="recommendReadListTitle" v-for="(item, index) in newsDetail.commendArticle"
  73. :key="item.id">
  74. <a :href="`/${item.alias_pinyin}/${item.id}.html`" v-if="index < 3">
  75. {{ item.title }}
  76. </a>
  77. <span v-if="index < 3">{{ getTime(item.created_at, "month", 1) }}</span>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. <div class="innerRight">
  83. <!-- 热点资讯1 -->
  84. <div class="hotList1">
  85. <DetailHotNews></DetailHotNews>
  86. </div>
  87. <!-- 热点资讯2 -->
  88. <div class="hotList2">
  89. <DetailHotNews2></DetailHotNews2>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. <!-- 列表页广告二 -->
  95. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  96. <!-- 页面底部 -->
  97. <HomeFoot1></HomeFoot1>
  98. </template>
  99. <script setup>
  100. //1.页面依赖 start ---------------------------------------->
  101. import { onMounted } from 'vue'
  102. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  103. import { ArrowRight } from '@element-plus/icons-vue'
  104. //1.页面依赖 end ---------------------------------------->
  105. //2.页面路径 start ---------------------------------------->
  106. const targetSegment = getRoutePath(1);
  107. let routeId;
  108. //通过导航路径反向查询导航id
  109. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  110. method: 'GET',
  111. query: {
  112. 'pinyin': targetSegment,
  113. },
  114. });
  115. if (getRouteId.code == 200) {
  116. routeId = getRouteId.data.category_id
  117. } else {
  118. console.log("错误位置:获得页面路径")
  119. }
  120. //2.页面路径 start ---------------------------------------->
  121. //3.面包屑 start ---------------------------------------->
  122. const route = useRoute();
  123. const articleId = parseInt(route.params.id); //获得该页面的id
  124. //3.1 获得父级栏目的名称、id
  125. const parent_name = ref([]);
  126. const parent_id = ref([]);
  127. const parent_pinyin = ref("");
  128. const parent_children_count = ref(0)
  129. let getParentNav = async () => {
  130. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  131. method: 'GET',
  132. query: {
  133. 'catid': routeId
  134. },
  135. });
  136. if (listData.code == 200) {
  137. console.log(778899)
  138. console.log(listData.data)
  139. parent_name.value = listData.data.alias;
  140. parent_id.value = listData.data.parent_id;
  141. parent_pinyin.value = listData.data.aLIas_pinyin;
  142. parent_children_count.value = listData.data.children_count;
  143. } else {
  144. console.log("错误位置:获取面包屑导航")
  145. }
  146. }
  147. getParentNav();
  148. //3.页面依赖 end ---------------------------------------->
  149. //4.页面数据 start ---------------------------------------->
  150. //4.1 资讯详情
  151. const newsDetail = ref({})
  152. const routeNewsTtitle = ref("");
  153. //4.2 发布日期
  154. const time = ref("");
  155. //4.3 路径
  156. const routLevelTitle = ref("");
  157. const routLevelId = ref("");
  158. //4.4 是否展示投票
  159. const articleChoice = ref(false);
  160. //4.5 获取详情
  161. async function getPageData() {
  162. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  163. method: 'GET',
  164. query: {
  165. 'articleid': articleId
  166. },
  167. });
  168. if (mkdata.code == 200) {
  169. //判断是否显示投票
  170. if (mkdata.data.is_survey == 1) {
  171. console.log("本篇文章含有投票!")
  172. articleChoice.value = true;
  173. }
  174. //获取内容
  175. newsDetail.value = mkdata.data;
  176. //获取路径
  177. routLevelTitle.value = newsDetail.value.cat_name;
  178. routLevelId.value = newsDetail.value.category_id;
  179. //获取发布时间
  180. time.value = newsDetail.value.updated_at.split(' ')[0];
  181. //修正标题长度
  182. if (newsDetail.value.title.length >= 30) {
  183. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  184. } else {
  185. routeNewsTtitle.value = newsDetail.value.title
  186. }
  187. } else {
  188. console.log("错误位置:获取详情内容")
  189. }
  190. }
  191. getPageData();
  192. //4.页面数据 end ---------------------------------------->
  193. //5.广告 start ---------------------------------------->
  194. let adImg1 = ref([]);
  195. let adImg2 = ref([]);
  196. onMounted(async () => {
  197. const { $webUrl, $CwebUrl } = useNuxtApp();
  198. //广告1
  199. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_detail_0001`
  200. const responseAd1 = await fetch(url, {
  201. headers: {
  202. 'Content-Type': 'application/json',
  203. 'Userurl': $CwebUrl,
  204. 'Origin': $CwebUrl
  205. }
  206. });
  207. const resultAd1 = await responseAd1.json();
  208. adImg1.value = resultAd1.data[0];
  209. //广告2
  210. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_detail_0002`
  211. const responseAd2 = await fetch(url2, {
  212. headers: {
  213. 'Content-Type': 'application/json',
  214. 'Userurl': $CwebUrl,
  215. 'Origin': $CwebUrl
  216. }
  217. });
  218. const resultAd2 = await responseAd2.json();
  219. adImg2.value = resultAd2.data[0];
  220. })
  221. //5.广告 end ---------------------------------------->
  222. //6.设置seo信息 start---------------------------------------->
  223. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  224. method: 'GET',
  225. query: {
  226. 'articleid': articleId
  227. },
  228. });
  229. if (setData.code == 200) {
  230. let seoTitle = setData.data.title;
  231. let seoDescription = setData.data.introduce;
  232. let seoKeywords = setData.data.keyword;
  233. let seoSuffix = setData.data.suffix;
  234. let seoName = setData.data.website_name;
  235. useSeoMeta({
  236. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  237. meta: [
  238. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  239. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  240. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  241. ]
  242. });
  243. } else {
  244. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  245. // console.log("错误位置:设置详情页面SEO数据")
  246. // console.log("后端错误反馈:", setData.message)
  247. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  248. }
  249. //6.设置seo信息 end---------------------------------------->
  250. //8.页面图片放大 start---------------------------------------->
  251. const previewVisible = ref(false)
  252. const selectedImage = ref(' ')
  253. const openPreview = (event) => {
  254. if (event.target.tagName === 'IMG') {
  255. selectedImage.value = event.target.src;
  256. previewVisible.value = true;
  257. }
  258. }
  259. const closePreview = () => {
  260. previewVisible.value = false;
  261. }
  262. //8.页面图片放大 end---------------------------------------->
  263. </script>
  264. <style lang="less" scoped>
  265. @import url('@/assets/css/detail.less');
  266. </style>
  267. <style lang="less" scoped>
  268. @media screen and (min-width:801px){/*pc*/
  269. .breadcrumb_pc_none{display:none!important;}
  270. .pc_none{display:none;}
  271. }
  272. @media screen and (max-width:800px){/*ipad_phone*/
  273. .index_3_box_vote{overflow:hidden;margin-top:39px;}
  274. .index_3_box_vote .inquire{margin-top:15px;height:auto;}
  275. .index_3_box_vote .inquire p{height:auto;padding:0;font-size:14px;
  276. margin:0px 0px 5px 18px;}
  277. .index_3_box_vote .inquire .radio .el-radio.el-radio--large .el-radio__label span{font-size:14px;}
  278. .index_3_box_vote .voteTitle{font-size:14px;}
  279. .index_3_box_vote .inquire .btn{padding-left:22px;}
  280. .index_3_box_vote .inquire .radio .el-radio.el-radio--large{margin-bottom:3px;}
  281. .index_3_box_vote .inquire .radioBox{height:auto;
  282. padding:0px 0px 12px 18px;}
  283. .index_3_box_vote .inquire .radio .el-radio-group{width:100%;}
  284. .index_3_box_vote .inquire .btn button{width:auto;padding:0px 10px;line-height:33px;height:33px;font-size:14px;margin-bottom:14px;}
  285. .newsDetail .inner{width:92%;}
  286. .newsDetail .inner .innerLeft{width:100%;margin:0;float:none; }
  287. .newsDetail .inner .innerLeft .LeftTop{margin-top:9px;border-top:solid 1px #a91b33;}
  288. .newsDetail .inner .innerLeft .LeftTop > h1{font-size:20px;line-height:28px;margin:15px auto 15px;}
  289. .newsDetail .inner .innerLeft .leftBottom{width:100%;margin-top:20px;}
  290. .newsDetail .inner .innerLeft .leftBottom *,
  291. .newsDetail .inner .innerLeft .leftBottom{ font-size:16px!important;line-height:24px!important;}
  292. .newsDetail .inner .innerLeft .leftBottom /deep/img{max-width:100%;height:auto; }
  293. .newsDetail .inner .innerLeft .LeftTop > p{height:auto;}
  294. .breadcrumb_box{
  295. height:22px;width:100%;margin:16px auto 9px;
  296. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  297. font-size:14px;
  298. color:#666;
  299. *{
  300. font-size:14px;
  301. display:inline ;
  302. color:#666;
  303. line-height:22px;height:22px;
  304. margin-right:5px;
  305. }
  306. }
  307. .newsDetail .inner .innerLeft .disclaimer{width:100%; }
  308. .newsDetail .inner .innerLeft .disclaimer *{word-wrap: break-word;width:100%!important;display:block!important;
  309. overflow-wrap: break-word;font-size:16px;
  310. white-space: pre-wrap;
  311. word-break: break-all;
  312. }
  313. // 推荐阅读
  314. .newsDetail .inner .innerLeft .recommendRead .recommendReadList{
  315. height:auto;margin-top:11px; min-height:auto;padding-bottom:8px;
  316. }
  317. .newsDetail .inner .innerLeft .recommendRead .recommendReadList .recommendReadListTitle{
  318. margin-top:0px;overflow:hidden;width:100%;
  319. }
  320. .newsDetail .inner .innerLeft .recommendRead .recommendReadList .recommendReadListTitle a{
  321. line-height:33px;height:33px;font-size:14px;float:left;max-width:90%;font-weight:normal;
  322. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  323. }
  324. .phone_box_1_head{
  325. height:33px;line-height:33px;background:#fff;border-bottom:1px solid #a91b33;
  326. margin-top:15px;width:100%;
  327. a{
  328. float:left;height:33px;line-height:33px;margin:0;position:relative;text-indent:8px;
  329. color:#a91b33;font-size:14px; font-weight:bold;box-sizing:border-box;
  330. }
  331. a::before{
  332. content: '';display: block;
  333. position:absolute;left:0px;top:12px;
  334. background:#a91b33;
  335. width:3px;height:10px;
  336. }
  337. }
  338. .newsDetail .inner .innerLeft .recommendRead{width:100%; margin:25px auto 32px;}
  339. .newsDetail .inner .innerLeft .recommendRead .recommendReadTitle{width:100%;margin:22px 0px;}
  340. .recommend_read_head_box{overflow:hidden;border-bottom:1px solid #D9D9D9;}
  341. .recommend_read_head{
  342. width:auto;font-size:14px;box-sizing:border-box;height:33px;line-height:33px;
  343. color: #A01C0E;
  344. border-bottom:1px solid #A01C0E;float:left;
  345. }
  346. .newsDetail .inner .innerLeft .recommendRead .recommendReadList{
  347. height:auto;margin-top:11px; min-height:auto;padding-bottom:8px;
  348. }
  349. .newsDetail .inner .innerLeft .recommendRead .recommendReadList .recommendReadListTitle{
  350. margin-top:0px;overflow:hidden;width:100%;
  351. }
  352. .newsDetail .inner .innerLeft .recommendRead .recommendReadList .recommendReadListTitle a{
  353. line-height:33px;height:33px;font-size:14px;float:left;max-width:90%;
  354. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  355. }
  356. .newsDetail .inner .innerLeft .LeftTop > p span:nth-last-of-type(1){margin-right:0px;}
  357. .newsDetail .inner .innerLeft .recommendRead .recommendReadList .recommendReadListTitle span{display:none;}
  358. .newsDetail .inner .innerRight{display:none;}
  359. .breadcrumb_phone_none{display:none!important;}
  360. .phone_none{display:none;}
  361. }
  362. </style>