list_sec.vue 12 KB

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