search.vue 11 KB

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