list.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation1></HomePageNavigation1>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 二级标题-->
  10. <div class="sannongzhichuang" v-if="parent_name != ''">
  11. <div class="inner">
  12. <h2>
  13. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  14. <em class="iconfont icon-xingzhuang-zhijiaosanjiaoxing-copy"></em>
  15. </h2>
  16. <p class="introduction">
  17. <strong>频道介绍</strong>
  18. <div v-for="(item, index) in secondNav" :key="index">
  19. <span v-if="index <= 7">
  20. <NuxtLink :to="{ path: `/${targetRoute}/${item.aLIas_pinyin}/list-1.html`}">{{ item.alias }}</NuxtLink>
  21. </span>
  22. <b v-else></b>
  23. </div>
  24. </p>
  25. </div>
  26. </div>
  27. <!-- 面包屑导航 -->
  28. <div class="breadcrumb">
  29. <div class="inner">
  30. <span class="location">当前位置:</span>
  31. <el-breadcrumb :separator-icon="ArrowRight">
  32. <el-breadcrumb-item>
  33. <NuxtLink to="/">首页</NuxtLink>
  34. </el-breadcrumb-item>
  35. <el-breadcrumb-item v-if="parent_name !=''">
  36. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  37. </el-breadcrumb-item>
  38. <el-breadcrumb-item class="phone_breadcrumb_text">{{ name }}</el-breadcrumb-item>
  39. </el-breadcrumb>
  40. </div>
  41. </div>
  42. <!-- 资讯列表 -->
  43. <div class="newsList">
  44. <div class="inner">
  45. <div class="innerLeft">
  46. <ul class="list">
  47. <li v-for="(item, index) in newsList" :key="index">
  48. <NuxtLink :href="getLinkPathDetail(item)" :title="item.alias">
  49. {{ item.title }}
  50. </NuxtLink>
  51. </li>
  52. </ul>
  53. <!-- 分页器 -->
  54. <div class="pagination pagination_phone_none" v-if="total > 0">
  55. <el-pagination
  56. size="small"
  57. background
  58. layout="prev, pager, next"
  59. :total="total"
  60. class="mt-4"
  61. :page-size="pageSize"
  62. :current-page="pageNum"
  63. prev-text="上一页"
  64. next-text="下一页"
  65. @current-change="changePage"
  66. />
  67. </div>
  68. <div class="pagination pagination_pc_none" v-if="total > 0">
  69. <el-pagination
  70. pager-count="5"
  71. size="small"
  72. background
  73. layout="pager "
  74. :total="total"
  75. class="mt-4"
  76. :page-size="pageSize"
  77. :current-page="pageNum"
  78. @current-change="changePage"
  79. />
  80. </div>
  81. </div>
  82. <div class="innerRight">
  83. <DetailHotNews></DetailHotNews>
  84. <DetailHotNews2></DetailHotNews2>
  85. </div>
  86. </div>
  87. </div>
  88. <!-- 列表页广告二 -->
  89. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  90. <!-- 页面底部 -->
  91. <HomeFoot1></HomeFoot1>
  92. </div>
  93. </template>
  94. <script setup>
  95. //1.页面必备依赖 start ---------------------------------------->
  96. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  97. import { ArrowRight } from '@element-plus/icons-vue'
  98. import { ref, onMounted } from 'vue';
  99. //当前列表名称
  100. const name = ref('')
  101. const { $webUrl, $CwebUrl, $BwebUrl } = useNuxtApp()
  102. //格式化跳转路径
  103. const getLinkPathDetail = (item) => {
  104. if (item.islink == 1) {
  105. return `${item.linkurl}`;
  106. } else {
  107. //return `/${item.aLIas_pinyin}/${item.id}`;
  108. //return `/newsDetail/${item.id}`
  109. return `/${item.pinyin}/${item.id}.html`;
  110. }
  111. }
  112. //1.页面必备依赖 end ---------------------------------------->
  113. //1.获得路由id start ---------------------------------------->
  114. const route = useRoute();
  115. let articleId = 0;//路由id
  116. let pageNum = ref(2);
  117. let total = ref(1);
  118. let pageSize = ref(20);
  119. //获得当前的完整路径
  120. const fullPath = route.path;
  121. //拆分,取出来中间这一段,然后提取数字部分
  122. const segments = fullPath.split('/');
  123. const targetSegment = segments[2];
  124. const targetRoute = segments[1];
  125. //const numberPart = targetSegment.match(/\d+$/)?.[0];
  126. //let routeId = 20 //排除路径错误可以打开这个
  127. //articleId = numberPart;
  128. //通过导航路径反向查询导航id
  129. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  130. method: 'GET',
  131. query: {
  132. 'pinyin': targetRoute+'/'+targetSegment,
  133. },
  134. });
  135. if(getRouteId.code == 200){
  136. articleId = getRouteId.data.category_id
  137. }else{
  138. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  139. console.log("错误位置:通过url路径查询导航池id")
  140. console.log("后端错误反馈:",getRouteId.message)
  141. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  142. }
  143. //获得html前的数字
  144. // const pageUrl = segments[3];
  145. // const pageNumber = pageUrl.split('.')[0];
  146. // console.log("当前URL中的页码:")
  147. // console.log(pageNumber)//2
  148. // pageNum.value = parseInt(pageNumber);
  149. pageNum.value = parseInt(route.params.id);
  150. //1.获得路由id end ---------------------------------------->
  151. //2.页面数据 start ---------------------------------------->
  152. //2.2新闻列表
  153. const newsList = ref([]);
  154. let newslists = async () => {
  155. const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  156. method: 'GET',
  157. query: {
  158. 'page': pageNum.value,
  159. 'pageSize': pageSize.value,
  160. 'catid': articleId
  161. },
  162. });
  163. if (listData.code == 200) {
  164. newsList.value = listData.data.rows;
  165. total.value = listData.data.count;
  166. } else {
  167. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  168. console.log("错误位置:获取新闻列表")
  169. console.log("后端错误反馈:", listData.message)
  170. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  171. }
  172. }
  173. //获得列表
  174. newslists();
  175. //分页事件
  176. let changePage = (value) => {
  177. console.log("当前页码", value);
  178. navigateTo(`/${targetSegment}/${value}.html`)
  179. }
  180. //2.3获得页面名称
  181. let getPageName = async () => {
  182. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  183. method: 'GET',
  184. query: {
  185. 'catid': articleId
  186. },
  187. });
  188. if (pageName.code == 200) {
  189. name.value = pageName.data.alias
  190. } else {
  191. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  192. console.log("错误位置:设置页面标题")
  193. console.log("后端错误反馈:", pageName.message)
  194. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  195. }
  196. }
  197. //获得列表
  198. getPageName();
  199. //2.页面数据 end ---------------------------------------->
  200. //3.二级栏目 start ---------------------------------------->
  201. //3.1通过id获取父栏目
  202. const parent_name = ref([]);
  203. const parent_id = ref([]);
  204. const parent_pinyin = ref("");
  205. let getParentNav = async () => {
  206. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  207. method: 'GET',
  208. query: {
  209. 'catid': articleId
  210. },
  211. });
  212. if (listData.code == 200) {
  213. console.log(111999)
  214. console.log(listData.data);
  215. parent_name.value = listData.data.parent_name;
  216. parent_id.value = listData.data.parent_id;
  217. parent_pinyin.value = listData.data.parent_pinyin;
  218. } else {
  219. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  220. console.log("错误位置:获取新闻列表")
  221. console.log("后端错误反馈:", listData.message)
  222. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  223. }
  224. getSecondNav();
  225. }
  226. //获得父级栏目详情
  227. getParentNav();
  228. // 3.2获取二级栏目
  229. const secondNav = ref([]);
  230. let getSecondNav = async () => {
  231. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  232. method: 'GET',
  233. query: {
  234. 'placeid': 1,
  235. 'pid': parent_id.value,
  236. 'num': 8,
  237. },
  238. });
  239. console.log('listData', listData);
  240. if (listData.code == 200) {
  241. secondNav.value = listData.data;
  242. } else {
  243. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  244. console.log("错误位置:获取新闻列表")
  245. console.log("后端错误反馈:", listData.message)
  246. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  247. }
  248. }
  249. //3.二级栏目 end ---------------------------------------->
  250. //4.设置seo信息 start---------------------------------------->
  251. //4.1 设置seo信息
  252. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  253. method: 'GET',
  254. query: {
  255. 'catid': articleId
  256. },
  257. });
  258. if (setData.code == 200) {
  259. let seoTitle = setData.data.seo_title;
  260. let seoDescription = setData.data.seo_description;
  261. let seoKeywords = setData.data.seo_keywords;
  262. let seoSuffix = setData.data.suffix;
  263. let seoName = setData.data.website_name;
  264. useSeoMeta({
  265. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  266. meta: [
  267. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  268. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  269. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  270. ]
  271. });
  272. } else {
  273. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  274. console.log("错误位置:设置列表页面SEO数据")
  275. console.log("后端错误反馈:", setData.message)
  276. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  277. }
  278. //4.设置seo信息 end---------------------------------------->
  279. //5.广告 start---------------------------------------->
  280. let adImg1 = ref({});
  281. let adImg2 = ref({});
  282. onMounted(async () => {
  283. //从客户端获取行政职能部门 加快打开速度
  284. const { $webUrl, $CwebUrl } = useNuxtApp();
  285. //广告1
  286. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_list_0001`
  287. const responseAd1 = await fetch(url, {
  288. headers: {
  289. 'Content-Type': 'application/json',
  290. 'Userurl': $CwebUrl,
  291. 'Origin': $CwebUrl
  292. }
  293. });
  294. const resultAd1 = await responseAd1.json();
  295. adImg1.value = resultAd1.data[0];
  296. //广告2
  297. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_list_0002`
  298. const responseAd2 = await fetch(url2, {
  299. headers: {
  300. 'Content-Type': 'application/json',
  301. 'Userurl': $CwebUrl,
  302. 'Origin': $CwebUrl
  303. }
  304. });
  305. const resultAd2 = await responseAd2.json();
  306. adImg2.value = resultAd2.data[0];
  307. })
  308. //5.广告 end---------------------------------------->
  309. </script>
  310. <style lang="less" scoped>
  311. @import url('@/assets/css/list/pc.less');
  312. </style>
  313. <style lang="less" scoped>
  314. @media screen and (min-width:801px){/*pc*/
  315. .pagination_pc_none{display:none!important;}
  316. .pc_none{display:none;}
  317. }
  318. @media screen and (max-width:800px){/*ipad_phone*/
  319. .sannongzhichuang .inner{width:100%;height:33px;background:#fafafa;}
  320. .sannongzhichuang h2{display:none;}
  321. .sannongzhichuang p.introduction{background:#fafafa;
  322. height:33px;line-height:33px;right:4%;box-sizing:border-box;
  323. width:92%;display:block;word-break: keep-all; white-space: nowrap;
  324. overflow-x:auto;
  325. overflow-y:hidden;
  326. &::-webkit-scrollbar {
  327. height:0px;
  328. }
  329. }
  330. .sannongzhichuang p.introduction > strong{display:none!important;}
  331. .sannongzhichuang p.introduction div{display:inline-block;height:33px;line-height:33px;}
  332. .sannongzhichuang p.introduction div span{display: block;height:33px;line-height:33px;margin-top:0px;width:auto;}
  333. .sannongzhichuang p.introduction div:nth-of-type(1) span{padding-left:0px;}
  334. .sannongzhichuang p.introduction div span{display:block;height:33px;line-height:33px;font-size:14px;padding:0px 10px;}
  335. .sannongzhichuang p.introduction div a{display:block;height:33px;line-height:33px;font-size:14px;}
  336. .introduction .router-link-exact-active{color:#139602!important;}
  337. .location{float:left;width:auto!important;}
  338. .breadcrumb .el-breadcrumb{width:100%;display:block;}
  339. .breadcrumb{margin:15px auto 10px;}
  340. // .breadcrumb .inner{ height:24px; }
  341. .breadcrumb .phone_breadcrumb_text{
  342. display:block;float:none;
  343. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  344. }
  345. .breadcrumb .location{ font-size: 14px; margin-right:5px;}
  346. .breadcrumb span { font-size: 14px; }
  347. .newsList .inner{width:92%!important;}
  348. .newsList .inner .innerLeft > .list > li{width:96%;margin:0px auto;}
  349. .newsList .inner .innerLeft{width:100%;}
  350. .newsList .inner .innerLeft > .list > li{line-height:50px;}
  351. .newsList .inner .innerLeft > .list > li > a{
  352. width:100%;display:block; height:50px;line-height:50px;font-size:16px;
  353. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  354. }
  355. .newsList .inner .innerLeft > .list > li a{float:left;width:92%; }
  356. .newsList .inner .innerLeft > .list > li:nth-of-type(-n+2)::after{display: block;height:22px;margin:16px 0px 0px 0px;line-height:22px;float:right;}
  357. .newsList .inner .innerLeft > .pagination{width:100%;}
  358. .newsList .inner .innerLeft > .list{margin-bottom:11px;}
  359. .newsList .inner .innerLeft > .pagination{margin-bottom:11px;}
  360. .newsList .inner .innerRight {width:100%;display:none;}
  361. .index_foot{margin-top:11px;}
  362. ::v-deep .el-pager li{
  363. margin:0px 4px!important;
  364. }
  365. .sannongzhichuang{margin:10px auto 10px;}
  366. .pagination_phone_none{display:none!important;}
  367. }
  368. </style>