news.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation1 :type="type"></HomePageNavigation1>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 搜索框 -->
  10. <div class="search">
  11. <div class="inner">
  12. <input v-model="keywordInput" type="text" placeholder="请输入搜索内容">
  13. <button @click="goSearch">搜索</button>
  14. </div>
  15. </div>
  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>搜索</el-breadcrumb-item>
  24. <el-breadcrumb-item>资讯</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. <span class=" ">搜索</span>
  33. </div>
  34. <div class="newsList">
  35. <div class="inner">
  36. <div class="innerLeft">
  37. <ul class="list" v-if="newsList.length >= 0">
  38. <li v-for="(item, index) in newsList" :key="index">
  39. <NuxtLink :href="getLinkPathDetail(item)" :title="item.title"
  40. :target="item.islink == 1 ? '_blank' : '_self'">
  41. {{ item.title }}
  42. </NuxtLink>
  43. <span class="time right phone_none">{{ getTime(item.updated_at, 'month', 1) }}</span>
  44. </li>
  45. </ul>
  46. <div v-if="newsList.length == 0" class="empty">
  47. <div>
  48. <img src="../../public/search/empty.png" alt="暂无内容">
  49. <p>暂无搜索数据</p>
  50. </div>
  51. </div>
  52. <!-- 分页器 -->
  53. <div class="pagination pagination_phone_none" v-if="total > 0">
  54. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  55. :page-size="pageSize" prev-text="上一页" next-text="下一页" @change="changePage" />
  56. </div>
  57. <div class="pagination pagination_pc_none" v-if="total > 0">
  58. <el-pagination
  59. pager-count="5"
  60. class="mt-4"
  61. size="small"
  62. background
  63. layout=" pager "
  64. :total="total"
  65. page-size="pageSize"
  66. @change="changePage"
  67. />
  68. </div>
  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.获取url中的参数 start ---------------------------------------->
  85. const route = useRoute();
  86. let keywordInput = ref(route.query.keyword);
  87. let type = ref(route.query.type);
  88. //2.获取url中的参数 end ---------------------------------------->
  89. //3.在该页进行搜索 start ---------------------------------------->
  90. //3.1 分页
  91. let total = useState("total", () => 0)
  92. let page = useState("page", () => 1)
  93. let pageSize = useState("pageSize", () => 20)
  94. //3.2 获得新闻列表
  95. const newsList = ref([]);
  96. //3.3 在本页进行搜索的方法
  97. let goSearch = async () => {
  98. console.log(page.value)
  99. console.log(pageSize.value)
  100. console.log(keywordInput.value)
  101. const listData = await requestDataPromise('/web/selectWebsiteCategory', {
  102. method: 'GET',
  103. query: {
  104. 'page': page.value,
  105. 'pageSize': pageSize.value,
  106. 'keyword': keywordInput.value,
  107. },
  108. });
  109. if (listData.data.rows) {
  110. console.log(listData)
  111. newsList.value = listData.data.rows;
  112. total.value = listData.data.count;
  113. } else {
  114. newsList.value = [];
  115. total.value = 0;
  116. }
  117. }
  118. goSearch();
  119. //3.4 分页事件
  120. let changePage = (value) => {
  121. console.log("当前页码", value);
  122. page.value = value
  123. console.log(page.value);
  124. goSearch()
  125. }
  126. //3.在该页进行搜索 end ---------------------------------------->
  127. //4.广告 start ---------------------------------------->
  128. let adImg1 = ref([]);
  129. let adImg2 = ref([]);
  130. onMounted(async () => {
  131. //从客户端获取行政职能部门 加快打开速度
  132. const { $webUrl, $CwebUrl } = useNuxtApp();
  133. //广告1
  134. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_search_0001`
  135. const responseAd1 = await fetch(url, {
  136. headers: {
  137. 'Content-Type': 'application/json',
  138. 'Userurl': $CwebUrl,
  139. 'Origin': $CwebUrl
  140. }
  141. });
  142. const resultAd1 = await responseAd1.json();
  143. adImg1.value = resultAd1.data[0];
  144. //广告2
  145. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nzgxw_search_0002`
  146. const responseAd2 = await fetch(url2, {
  147. headers: {
  148. 'Content-Type': 'application/json',
  149. 'Userurl': $CwebUrl,
  150. 'Origin': $CwebUrl
  151. }
  152. });
  153. const resultAd2 = await responseAd2.json();
  154. adImg2.value = resultAd2.data[0];
  155. })
  156. //4.页面数据 end ---------------------------------------->
  157. //5.设置seo信息 start---------------------------------------->
  158. const setData = await requestDataPromise('/web/getWebsiteFootInfo', {
  159. method: 'GET',
  160. query: {},
  161. });
  162. let seoTitle = setData.data.website_head.title;
  163. let seoDescription = setData.data.website_head.description;
  164. let seoKeywords = setData.data.website_head.keywords;
  165. let seoSuffix = setData.data.website_head.suffix;
  166. let seoName = setData.data.website_head.website_name;
  167. useSeoMeta({
  168. title: seoTitle + "_" + seoSuffix,
  169. meta: [
  170. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  171. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  172. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  173. ]
  174. });
  175. //5.设置seo信息 end---------------------------------------->
  176. </script>
  177. <style lang="less" scoped>
  178. @import url('@/assets/css/search.less');
  179. </style>
  180. <style lang="less" scoped>
  181. @media screen and (min-width:801px){/*pc*/
  182. .pagination_pc_none{display:none!important;}
  183. .pc_none{display:none;}
  184. }
  185. @media screen and (max-width:800px){/*ipad_phone*/
  186. .breadcrumb{margin-bottom:10px; }
  187. .breadcrumb .location{ font-size: 14px; }
  188. .breadcrumb span { font-size: 14px; }
  189. .newsList{width:100%;margin-bottom:22px;}
  190. .newsList .inner{width:92%!important;}
  191. .newsList .inner .innerLeft > .list > li{width:96%;margin:0px auto;}
  192. .newsList .inner .innerLeft{width:100%;border-top:solid 1px #a91b33;}
  193. .newsList .inner .innerLeft > .list > li{line-height:50px;}
  194. .newsList .inner .innerLeft > .list > li > a{
  195. width:100%;display:block; height:50px;line-height:50px;font-size:16px;
  196. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  197. }
  198. .newsList .inner .innerLeft > .list > li a{float:left;width:92%; }
  199. .newsList .inner .innerLeft > .list > li:nth-of-type(-n+2)::after{display: block;height:18px;margin:10px 0px 0px 0px;
  200. font-size:12px;line-height:18px;float:right;}
  201. .newsList .inner .innerLeft > .pagination{width:100%;}
  202. .newsList .inner .innerLeft > .list{margin:10px auto 10px;}
  203. .newsList .inner .innerLeft > .pagination{margin-bottom:11px;}
  204. .newsList .inner .innerRight {width:100%;display:none;}
  205. .index_foot{margin-top:11px;}
  206. .search{ overflow:hidden;height:auto;
  207. width:92%;margin:10px auto;
  208. .inner{width:100%;display:flex;height:auto;padding:0;}
  209. .inner > input{ flex:1;width:auto;line-height:33px;height:33px;box-sizing:border-box;font-size:14px;}
  210. .inner > button{width:auto;padding:0px 8px;line-height:33px;height:33px;font-size:14px;}
  211. }
  212. ::v-deep .el-pager li{
  213. margin:0px 4px!important;
  214. }
  215. .advert_box{width:92%;margin:0px auto;}
  216. .pagination_phone_none{display:none!important;}
  217. .newsList .inner .innerLeft > .list > li{line-height:40px;height:40px;padding:0!important;}
  218. .newsList .inner .innerLeft > .list > li a{line-height:40px;height:40px;}
  219. .newsList .inner .innerLeft > .list > li:nth-child(5n){
  220. height:auto;
  221. padding-bottom:11px!important;
  222. margin-bottom:11px;
  223. }
  224. .breadcrumb_box{
  225. height:22px;width:100%;margin:10px auto;
  226. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  227. width:92%;
  228. font-size:14px;
  229. color:#666;
  230. *{
  231. font-size:14px;
  232. display:inline ;
  233. color:#666;
  234. line-height:22px;height:22px;
  235. margin-right:5px;
  236. }
  237. }
  238. .phone_none{display:none;}
  239. }
  240. </style>