detail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <!-- 资讯详情 -->
  3. <div class="news">
  4. <main class="index_main">
  5. <section class="clearfix">
  6. <div class="info_1_left">
  7. <div class="breadcrumb">
  8. <div class="inner">
  9. <span class="location">当前位置 :</span>
  10. <el-breadcrumb :separator-icon="ArrowRight">
  11. <el-breadcrumb-item>
  12. <NuxtLink to="/">首页</NuxtLink>
  13. </el-breadcrumb-item>
  14. <el-breadcrumb-item v-if="p_parent_name != ''">
  15. <NuxtLink :to="`/${targetSegment}/index.html`"> {{ p_parent_name }}</NuxtLink>
  16. </el-breadcrumb-item>
  17. <el-breadcrumb-item v-if="parent_name != ''">
  18. <NuxtLink :to="`/${targetSegment}/${targetSegment1}/index.html`"> {{ parent_name }}
  19. </NuxtLink>
  20. </el-breadcrumb-item>
  21. <el-breadcrumb-item>{{ navTitle }}</el-breadcrumb-item>
  22. </el-breadcrumb>
  23. </div>
  24. </div>
  25. <h4 class="show_1_h4">{{ newsDetail.title }}</h4>
  26. <div class="show_1_title_box clearfix">
  27. <span class="show_1_title">来源:{{ newsDetail.copyfrom }}</span>
  28. <span class="show_1_title">作者:{{ newsDetail.author }}</span>
  29. <span class="show_1_title">时间:{{ getTime(newsDetail.updated_at, 'year', 1) }}</span>
  30. </div>
  31. <article class="show_1_article" v-html="newsDetail.content">
  32. </article>
  33. <footer class="show_foot" v-if="newsDetail.copyfrom != '本网'">
  34. 原文链接:{{ newsDetail.fromurl }}
  35. <br>
  36. [免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。
  37. </footer>
  38. </div>
  39. <aside class="info_1_aside">
  40. <DetailHotNews></DetailHotNews>
  41. <DetailHotNews2></DetailHotNews2>
  42. <!-- <div class="shop_head_1 clearfix">
  43. <div class="shop_head_1_name">供求信息</div>
  44. </div>
  45. <div class="shop_img_ul_1 clearfix">
  46. <div class="shop_img_li_1 clearfix" v-for="(per_obj, per_index) in 2" :key="per_obj">
  47. <a class="shop_img_li_1_a" href="" title="">
  48. <img class="shop_img_li_1_img" src="@/public/img/7.png" title="" alt="">
  49. <div class="shop_img_li_1_right clearfix">
  50. <div class="shop_img_li_1_dot3 dot3 clearfix">
  51. 供求信息供求信息供求信息供求信息供求信息供求信息供求信息供求信息供求信息供求信息供求信息
  52. </div>
  53. <div class="shop_img_li_1_btn">供应</div>
  54. </div>
  55. </a>
  56. </div>
  57. </div>
  58. <div class="shop_ul_1 clearfix">
  59. <a class="shop_li_1 clearfix dot1" href="" title="" v-for="(per_obj, per_index) in 4"
  60. :key="per_obj">农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态</a>
  61. </div>
  62. <div class="shop_head_2 clearfix">
  63. <div class="shop_head_2_name">名品之窗</div>
  64. </div>
  65. <div class="shop_img_ul_2 clearfix">
  66. <div class="shop_img_li_2 clearfix" v-for="(per_obj, per_index) in 2" :key="per_obj">
  67. <a class="shop_img_li_2_a" href="" title="">
  68. <img class="shop_img_li_2_img" src="@/public/img/7.png" title="" alt="">
  69. <div class="shop_img_li_2_right clearfix">
  70. <div class="shop_img_li_2_dot3 dot3 clearfix">
  71. 供求信息供求信息供求信息供求信息供求信息供求信息供求信息供求信息供求信息供求信息供求信息
  72. </div>
  73. <div class="shop_img_li_2_btn">供应</div>
  74. </div>
  75. </a>
  76. </div>
  77. </div>
  78. <div class="shop_ul_2 clearfix">
  79. <a class="shop_li_2 clearfix dot1" href="" title="" v-for="(per_obj, per_index) in 4"
  80. :key="per_obj">农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态农产动态</a>
  81. </div> -->
  82. </aside>
  83. </section>
  84. </main>
  85. </div>
  86. </template>
  87. <script setup>
  88. //0.页面依赖 start ---------------------------------------->
  89. import { onMounted } from 'vue'
  90. import { ElBreadcrumb, ElBreadcrumbItem, ElRadio, ElRadioGroup, ElCheckbox, ElCheckboxGroup, ElMessage, ElInput } from 'element-plus'
  91. import { ArrowRight } from '@element-plus/icons-vue'
  92. //0.页面依赖 end ---------------------------------------->
  93. //1.获得路由id start ---------------------------------------->
  94. const route = useRoute();
  95. const articleId = parseInt(route.params.id);
  96. const targetSegment = getRoutePath(1);
  97. const targetSegment1 = getRoutePath(2);
  98. const targetSegment2 = getRoutePath(3);
  99. //1.1 获得当前的路由id
  100. let routeId;
  101. let routeType;
  102. let navTitle = ref('')//二级导航标题
  103. let navCid = ref('')//二级导航id
  104. //通过导航路径反向查询导航id
  105. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  106. method: 'GET',
  107. query: {
  108. 'pinyin': targetSegment2,
  109. },
  110. });
  111. console.log("getRouteId", getRouteId);
  112. if (getRouteId.code == 200) {
  113. navTitle.value = getRouteId.data.alias
  114. navCid.value = getRouteId.data.category_id
  115. } else {
  116. console.log("获得路由id出错!", getRouteId.message)
  117. }
  118. //1.2 获取二级栏目
  119. let parent_name = ref('');//父级名称
  120. let parent_id = ref('');//父级id
  121. let parent_pinyin = ref('');//父级拼音
  122. const getRoutePName = await requestDataPromise('/web/getWebsiteRoute', {
  123. method: 'GET',
  124. query: {
  125. 'pinyin': targetSegment1,
  126. },
  127. });
  128. console.log("getRoutePName", getRoutePName);
  129. if (getRoutePName.code == 200) {
  130. routeId = getRoutePName.data.category_id
  131. parent_id.value = getRoutePName.data.category_id
  132. parent_name.value = getRoutePName.data.alias
  133. routeType = getRoutePName.data.type
  134. } else {
  135. console.log("获得路由id出错!", getRoutePName.message)
  136. }
  137. //1.3 获取一级栏目
  138. let p_parent_name = ref('');//父级名称
  139. let p_parent_id = ref('');//父级id
  140. let p_parent_pinyin = ref('');//父级拼音
  141. const getRoutePName_parent = await requestDataPromise('/web/getWebsiteRoute', {
  142. method: 'GET',
  143. query: {
  144. 'pinyin': targetSegment,
  145. },
  146. });
  147. console.log("getRoutePName_parent", getRoutePName_parent);
  148. if (getRoutePName_parent.code == 200) {
  149. p_parent_id.value = getRoutePName_parent.data.category_id
  150. p_parent_name.value = getRoutePName_parent.data.alias
  151. // p_parent_pinyin.value = getRoutePName_parent.data.aLIas_pinyin
  152. } else {
  153. console.log("获得路由id出错!", getRoutePName_parent.message)
  154. }
  155. //1.4 获取某个栏目
  156. const getParentId = await requestDataPromise('/web/getOneWebsiteCategory', {
  157. method: 'GET',
  158. query: {
  159. 'catid': parent_id.value,
  160. },
  161. });
  162. console.log("getParentId", getParentId);
  163. if (getParentId.code == 200) {
  164. parent_pinyin.value = getParentId.data.aLIas_pinyin
  165. } else {
  166. console.log("获得路由id出错!", getParentId.message)
  167. }
  168. //1.获得路由id end ---------------------------------------->
  169. //4.新闻详情 start ---------------------------------------->
  170. //4.1 资讯详情
  171. const newsDetail = ref({})
  172. const routeNewsTtitle = ref("");
  173. //4.2 发布日期
  174. const time = ref("");
  175. //4.3 路径
  176. const routLevelTitle = ref("");
  177. const routLevelId = ref("");
  178. //4.4 是否展示投票
  179. const articleChoice = ref(false);
  180. //4.5 获取详情
  181. async function getPageData() {
  182. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  183. method: 'GET',
  184. query: {
  185. 'articleid': articleId
  186. },
  187. });
  188. console.log('111111111111111', mkdata.data);
  189. if (mkdata.code == 200) {
  190. //判断是否显示投票
  191. if (mkdata.data.is_survey == 1) {
  192. console.log("本篇文章含有投票!")
  193. articleChoice.value = true;
  194. }
  195. //获取内容
  196. newsDetail.value = mkdata.data;
  197. //获取路径
  198. routLevelTitle.value = newsDetail.value.cat_name;
  199. routLevelId.value = newsDetail.value.category_id;
  200. //获取发布时间
  201. time.value = newsDetail.value.updated_at.split(' ')[0];
  202. //修正标题长度
  203. if (newsDetail.value.title.length >= 20) {
  204. routeNewsTtitle.value = newsDetail.value.title.substr(0, 20) + "...";
  205. } else {
  206. routeNewsTtitle.value = newsDetail.value.title
  207. }
  208. } else {
  209. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  210. console.log("错误位置:获取详情内容")
  211. console.log("后端错误反馈:", mkdata.message)
  212. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  213. }
  214. }
  215. getPageData();
  216. //4.新闻详情 end ---------------------------------------->
  217. //5.广告 start ---------------------------------------->
  218. let adImg1 = ref([]);
  219. let adImg2 = ref([]);
  220. onMounted(async () => {
  221. const { $webUrl, $CwebUrl } = useNuxtApp();
  222. //广告1
  223. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_detail_0001`
  224. const responseAd1 = await fetch(url, {
  225. headers: {
  226. 'Content-Type': 'application/json',
  227. 'Userurl': $CwebUrl,
  228. 'Origin': $CwebUrl
  229. }
  230. });
  231. const resultAd1 = await responseAd1.json();
  232. adImg1.value = resultAd1.data[0];
  233. //广告2
  234. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_detail_0002`
  235. const responseAd2 = await fetch(url2, {
  236. headers: {
  237. 'Content-Type': 'application/json',
  238. 'Userurl': $CwebUrl,
  239. 'Origin': $CwebUrl
  240. }
  241. });
  242. const resultAd2 = await responseAd2.json();
  243. adImg2.value = resultAd2.data[0];
  244. })
  245. //5.广告 end ---------------------------------------->
  246. //6.设置seo信息 start---------------------------------------->
  247. // const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  248. // method: 'GET',
  249. // query: {
  250. // 'articleid': articleId
  251. // },
  252. // });
  253. // if (setData.code == 200) {
  254. // let seoTitle = setData.data.title;
  255. // let seoDescription = setData.data.introduce;
  256. // let seoKeywords = setData.data.keyword;
  257. // let seoSuffix = setData.data.suffix;
  258. // let seoName = setData.data.website_name;
  259. // useSeoMeta({
  260. // title: seoTitle + "_" + seoName + "_" + seoSuffix,
  261. // meta: [
  262. // { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  263. // { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  264. // ]
  265. // });
  266. // } else {
  267. // console.log("获取广告数据失败!", setData.message)
  268. // }
  269. //6.设置seo信息 end---------------------------------------->
  270. //8.页面图片放大 start---------------------------------------->
  271. const previewVisible = ref(false)
  272. const selectedImage = ref(' ')
  273. const openPreview = (event) => {
  274. if (event.target.tagName === 'IMG') {
  275. selectedImage.value = event.target.src;
  276. previewVisible.value = true;
  277. }
  278. }
  279. const closePreview = () => {
  280. previewVisible.value = false;
  281. }
  282. //8.页面图片放大 end---------------------------------------->
  283. </script>
  284. <style lang="less" scoped>
  285. @import url('@/assets/css/shop/newsDetail.less');
  286. </style>