news.vue 11 KB

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