list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation></HomePageNavigation>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 资讯列表 -->
  10. <div class="newsList">
  11. <div class="inner">
  12. <div class="innerLeft">
  13. <!-- 面包屑导航 -->
  14. <div class="breadcrumb phone_none">
  15. <div class="inner">
  16. <span class="location">当前位置:</span>
  17. <el-breadcrumb :separator-icon="ArrowRight">
  18. <el-breadcrumb-item>
  19. <NuxtLink to="/">首页</NuxtLink>
  20. </el-breadcrumb-item>
  21. <el-breadcrumb-item v-if="parent_name !=''">
  22. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  23. </el-breadcrumb-item>
  24. <el-breadcrumb-item class="nameBox">{{ name }}</el-breadcrumb-item>
  25. </el-breadcrumb>
  26. </div>
  27. </div>
  28. <div class="breadcrumb_box pc_none">
  29. <span class=" ">当前位置:</span>
  30. <NuxtLink to="/">首页</NuxtLink>
  31. <span class=" ">&gt;</span>
  32. <NuxtLink :to="`/${parent_pinyin}/index.html`" v-if="parent_name != ''"> {{ parent_name }}</NuxtLink>
  33. <span class=" " v-if="parent_name != ''">&gt;</span>
  34. {{ name }}
  35. </div>
  36. <ul class="list">
  37. <li v-for="(item, index) in newsList" :key="index">
  38. <NuxtLink :href="getLinkPathDetail(item)" :title="item.alias">
  39. <span class="listTitle">{{ item.title }}</span>
  40. <span class="time phone_none">{{ getTime(item.updated_at, 'month', 1) }}</span>
  41. </NuxtLink>
  42. </li>
  43. </ul>
  44. <!-- 分页器 -->
  45. <div class="pagination page_phone_none" v-if="total > 0">
  46. <el-pagination
  47. size="small"
  48. background
  49. layout="prev, pager, next"
  50. :total="total"
  51. class="mt-4"
  52. :page-size="pageSize"
  53. :current-page="pageNum"
  54. prev-text="上一页"
  55. next-text="下一页"
  56. @current-change="changePage"
  57. />
  58. </div>
  59. <div class="pagination page_pc_none" v-if="total > 0">
  60. <el-pagination
  61. pager-count="5"
  62. size="small"
  63. background
  64. layout=" pager "
  65. :total="total"
  66. class="mt-4"
  67. v-model:page-size="pageSize"
  68. :current-page="pageNum"
  69. @current-change="changePage" />
  70. </div>
  71. </div>
  72. <div class="innerRight">
  73. <DetailHotNews></DetailHotNews>
  74. <DetailHotNews2></DetailHotNews2>
  75. </div>
  76. </div>
  77. </div>
  78. <!-- 列表页广告二 -->
  79. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  80. <!-- 页面底部 -->
  81. <HomeFoot1></HomeFoot1>
  82. </div>
  83. </template>
  84. <script setup>
  85. //1.页面必备依赖 start ---------------------------------------->
  86. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus';
  87. import { ArrowRight } from '@element-plus/icons-vue';
  88. import { ref, onMounted } from 'vue';
  89. //1.页面必备依赖 end ---------------------------------------->
  90. //2.页面路径 start ---------------------------------------->
  91. const route = useRoute();
  92. let articleId = 0; //获取哪个导航下的列表
  93. //2.1 获得当前的完整路径
  94. const targetSegment = getRoutePath(1);
  95. //通过导航路径反向查询导航id
  96. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  97. method: 'GET',
  98. query: {
  99. 'pinyin': targetSegment,
  100. },
  101. });
  102. if(getRouteId.code == 200){
  103. articleId = getRouteId.data.category_id
  104. }else{
  105. console.log("错误位置:获得页面路径")
  106. }
  107. //2.页面路径 end ---------------------------------------->
  108. //3.页面数据 start ---------------------------------------->
  109. let pageNum = ref(2); //当前页码
  110. pageNum.value = parseInt(route.params.id);//路由中传递的分页页码
  111. let total = ref(1); //总条数
  112. let pageSize = ref(20); //每页条数
  113. //3.1 新闻列表
  114. const newsList = ref([]);
  115. let newslists = async () => {
  116. const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  117. method: 'GET',
  118. query: {
  119. 'page': pageNum.value,
  120. 'pageSize': pageSize.value,
  121. 'catid': articleId
  122. },
  123. });
  124. if (listData.code == 200) {
  125. newsList.value = listData.data.rows;
  126. total.value = listData.data.count;
  127. } else {
  128. console.log("错误位置:获取新闻列表")
  129. }
  130. }
  131. //获得列表
  132. newslists();
  133. //3.2 分页事件
  134. let changePage = (value) => {
  135. console.log("当前页码", value);
  136. navigateTo(`/${targetSegment}/list-${value}.html`)
  137. }
  138. //3.页面数据 end ---------------------------------------->
  139. //4.面包屑 start ---------------------------------------->
  140. const name = ref('')
  141. //4.1 当前频道名称
  142. let getPageName = async () => {
  143. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  144. method: 'GET',
  145. query: {
  146. 'catid': articleId
  147. },
  148. });
  149. if (pageName.code == 200) {
  150. name.value = pageName.data.alias
  151. } else {
  152. console.log("错误位置:获取当前频道名称", pageName.message)
  153. }
  154. }
  155. getPageName();
  156. //4.2 查询是否含有父级导航
  157. const parent_name = ref([]);
  158. const parent_id = ref([]);
  159. const parent_pinyin = ref("");
  160. let getParentNav = async () => {
  161. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  162. method: 'GET',
  163. query: {
  164. 'catid': articleId
  165. },
  166. });
  167. if (listData.code == 200) {
  168. parent_name.value = listData.data.parent_name;
  169. parent_id.value = listData.data.parent_id;
  170. parent_pinyin.value = listData.data.parent_pinyin;
  171. } else {
  172. console.log("错误位置:查询父级导航信息")
  173. }
  174. getSecondNav();
  175. }
  176. getParentNav();
  177. //4.3 获取二级栏目列表
  178. const secondNav = ref([]);
  179. let getSecondNav = async () => {
  180. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  181. method: 'GET',
  182. query: {
  183. 'placeid': 1,
  184. 'pid': parent_id.value,
  185. 'num': 8,
  186. },
  187. });
  188. console.log('listData', listData);
  189. if (listData.code == 200) {
  190. secondNav.value = listData.data
  191. } else {
  192. console.log("错误位置:获得二级栏目列表")
  193. }
  194. }
  195. //4.面包屑 end ---------------------------------------->
  196. //5.设置seo信息 start---------------------------------------->
  197. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  198. method: 'GET',
  199. query: {
  200. 'catid': articleId
  201. },
  202. });
  203. if (setData.code == 200) {
  204. let seoTitle = setData.data.seo_title;
  205. let seoDescription = setData.data.seo_description;
  206. let seoKeywords = setData.data.seo_keywords;
  207. let seoSuffix = setData.data.suffix;
  208. let seoName = setData.data.website_name;
  209. useSeoMeta({
  210. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  211. meta: [
  212. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  213. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  214. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  215. ]
  216. });
  217. } else {
  218. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  219. // console.log("错误位置:设置列表页面SEO数据")
  220. // console.log("后端错误反馈:", setData.message)
  221. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  222. }
  223. //5.设置seo信息 end---------------------------------------->
  224. //6.广告 start---------------------------------------->
  225. let adImg1 = ref({});
  226. let adImg2 = ref({});
  227. onMounted(async () => {
  228. //从客户端获取行政职能部门 加快打开速度
  229. const { $webUrl, $CwebUrl } = useNuxtApp();
  230. //广告1
  231. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_list_0001`
  232. const responseAd1 = await fetch(url, {
  233. headers: {
  234. 'Content-Type': 'application/json',
  235. 'Userurl': $CwebUrl,
  236. 'Origin': $CwebUrl
  237. }
  238. });
  239. const resultAd1 = await responseAd1.json();
  240. adImg1.value = resultAd1.data[0];
  241. //广告2
  242. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_list_0002`
  243. const responseAd2 = await fetch(url2, {
  244. headers: {
  245. 'Content-Type': 'application/json',
  246. 'Userurl': $CwebUrl,
  247. 'Origin': $CwebUrl
  248. }
  249. });
  250. const resultAd2 = await responseAd2.json();
  251. adImg2.value = resultAd2.data[0];
  252. })
  253. //6.广告 end---------------------------------------->
  254. </script>
  255. <style lang="less" scoped>
  256. @import url('@/assets/css/list.less');
  257. </style>
  258. <style lang="less" scoped>
  259. @media screen and (min-width:801px){/*pc*/
  260. .page_pc_none{display:none!important;}
  261. .pc_none{display:none;}
  262. }
  263. @media screen and (max-width:800px){/*ipad_phone*/
  264. .newsList{margin-bottom:22px;}
  265. .newsList .inner{width:92%;margin:0px auto 0px;}
  266. .newsList .inner .innerLeft{width:100%;float:none;}
  267. .newsList .inner .innerLeft{width:100%;float:none;margin:0px auto;}
  268. .newsList .inner .innerLeft .list{margin-bottom:10px;border-top:solid 1px #a91b33;padding-top:11px;}
  269. .newsList .inner .innerLeft .list li{display:block;width:100%;padding:0!important; height:auto;}
  270. .newsList .inner .innerLeft .list li:nth-of-type(5n){
  271. border-bottom: 1px solid #D9D9D9;
  272. padding-bottom: 10px!important;
  273. margin-bottom:11px;
  274. }
  275. .newsList .inner .innerLeft .list li a{
  276. width:100%;display:block; height:40px;line-height:40px;font-size:16px;
  277. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  278. }
  279. .newsList .inner .innerLeft .list li .listTitle{font-size:16px;font-weight:normal!important;width:100%;}
  280. .newsList .inner .innerLeft > .pagination{width:100%;}
  281. .newsList .inner .innerLeft > .pagination .el-pagination.is-background .el-pager li{margin:0px 4px;}
  282. .breadcrumb_box{
  283. height:22px;width:100%;margin:15px auto 10px;
  284. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  285. font-size:14px;
  286. color:#666;
  287. *{
  288. font-size:14px;
  289. display:inline ;
  290. color:#666;
  291. line-height:22px;height:22px;
  292. margin-right:5px;
  293. }
  294. }
  295. .page_phone_none{display:none!important;}
  296. .innerRight{display:none;}
  297. .phone_none{display:none;}
  298. }
  299. </style>