news.vue 11 KB

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