list.vue 12 KB

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