search.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- Banner1 -->
  6. <HomeBanner1></HomeBanner1>
  7. <!-- 面包屑导航 -->
  8. <div class="breadcrumb">
  9. <div class="inner">
  10. <span class="location">当前位置:</span>
  11. <el-breadcrumb :separator-icon="ArrowRight">
  12. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  13. <el-breadcrumb-item :to="{ path: '/search/search' }">搜索</el-breadcrumb-item>
  14. </el-breadcrumb>
  15. </div>
  16. </div>
  17. <!-- <div class="searchBox">
  18. <input type="text" placeholder="输入关键词" v-model="keywordInput">
  19. <button @click="goSearch">搜索</button>
  20. </div> -->
  21. <!-- 资讯列表 -->
  22. <div class="newsList">
  23. <div class="inner">
  24. <div class="innerLeft">
  25. <ul class="list">
  26. <li v-for="(item, index) in newsList" :key="index">
  27. <NuxtLink :to="{ path: `/newsDetail/${item.id}`, query: { listId: routeId, listName: routeName } }" target="_blank">{{ item.title }}</NuxtLink>
  28. </li>
  29. </ul>
  30. <!-- 分页器 -->
  31. <div class="pagination">
  32. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  33. prev-text="上一页" next-text="下一页" @change="changePage" />
  34. <!-- <HomePagination @sendData="handleData"></HomePagination> -->
  35. </div>
  36. </div>
  37. <!-- <div class="innerRight">
  38. <DetailHotNews></DetailHotNews>
  39. </div> -->
  40. </div>
  41. </div>
  42. <!-- 三农资讯logo -->
  43. <HomeSannongzixun></HomeSannongzixun>
  44. <!--
  45. <div class="zixuntuijian">
  46. <div class="inner">
  47. <div class="innerLeft">
  48. <div class="zixunLeft">
  49. <div class="title">
  50. <h3>
  51. 资讯推荐
  52. </h3>
  53. </div>
  54. <ul class="photo_text">
  55. <li v-for="item in news1">
  56. <img :src="item.imgurl" alt="">
  57. <div>
  58. <h5>{{ item.title }}</h5>
  59. <p>
  60. <span>{{ item.author }}</span>
  61. <span>{{ item.created_at }}</span>
  62. </p>
  63. </div>
  64. </li>
  65. <li v-for="item in news11">
  66. <em></em>
  67. {{ item.title }}
  68. </li>
  69. </ul>
  70. </div>
  71. <div class="zixunRight">
  72. <div class="title">
  73. <h3>
  74. 资讯推荐
  75. </h3>
  76. </div>
  77. <ul class="photo_text">
  78. <li v-for="item in news2">
  79. <img :src="item.imgurl" alt="">
  80. <div>
  81. <h5>{{ item.title }}</h5>
  82. <p>
  83. <span>{{ item.author }}</span>
  84. <span>{{ item.created_at }}</span>
  85. </p>
  86. </div>
  87. </li>
  88. <li v-for="item in news22">
  89. <em></em>
  90. {{ item.title }}
  91. </li>
  92. </ul>
  93. </div>
  94. </div>
  95. <div class="innerRight">
  96. <div class="title">
  97. <h4>
  98. 热点资讯
  99. </h4>
  100. </div>
  101. <ul class="rightList">
  102. <li v-for="item in hotlistall">
  103. <img class="left" :src="item.imgurl">
  104. <p class="left">{{ item.title }}</p>
  105. </li>
  106. </ul>
  107. </div>
  108. </div>
  109. </div>
  110. -->
  111. <!-- 页面底部 -->
  112. <HomeFoot></HomeFoot>
  113. </div>
  114. </template>
  115. <script setup>
  116. import { onMounted } from 'vue';
  117. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  118. import { ArrowRight } from '@element-plus/icons-vue'
  119. const nuxtApp = useNuxtApp();
  120. const axios = nuxtApp.$axios;
  121. //获得跳转过来的id
  122. const route = useRoute();
  123. const articleId = route.params.id; //获得该页面的id
  124. const category_id = route.query.category_id; //获得该页面的id
  125. const name = route.query.name; //获得该页面的id
  126. const searchKey = route.query.keyword
  127. console.log(name);
  128. //关键词
  129. let keyWord = useState("keyWord", () => "")
  130. let id = useState("id", () => "")
  131. let total = useState("total", () => 0)
  132. let page = useState("page", () => 1)
  133. let pageSize = useState("pageSize", () => 10)
  134. let keywordInput = ref("")
  135. //点击搜索按钮
  136. let goSearch = () => {
  137. navigateTo({
  138. path: '/search/search',
  139. query: {
  140. keyword: keywordInput.value
  141. }
  142. })
  143. }
  144. onMounted(() => {
  145. id.value = route.query.id;
  146. console.log('id', id.value);
  147. })
  148. // 页码
  149. // //页面组件传递数据的时间驱动函数
  150. // const handleData = (data) => {
  151. // console.log(data.value)
  152. // page.value = data.value
  153. // //在页码发生变化时去请求响应页面的新闻数据
  154. // axios.get(`/web/getWebsiteArticlesList?page=${page.value}&pageSize=${10}&catid=${14}&keyword=${keyWord.value}`).then(response => {
  155. // // console.log(response.data.rows);
  156. // newsList.value = response.data.rows;
  157. // }).catch(error => {
  158. // console.error(error);
  159. // })
  160. // }
  161. let changePage = (value) => {
  162. console.log("当前页码", value);
  163. page.value = value
  164. console.log(page.value);
  165. newslists()
  166. }
  167. // 新闻列表
  168. const newsList = useState("newsList", () => '');
  169. const newslists = async () => {
  170. try {
  171. if(category_id == undefined){
  172. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&keyword=${searchKey}`);
  173. // console.log(response.data.rows);
  174. newsList.value = response.data.rows;
  175. total.value = response.data.count;
  176. }else{
  177. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${category_id}&keyword=${searchKey}`);
  178. // console.log(response.data.rows);
  179. newsList.value = response.data.rows;
  180. total.value = response.data.count;
  181. }
  182. } catch (error) {
  183. console.error(error);
  184. }
  185. }
  186. //热点资讯
  187. const hotlistall = useState("hotlistall", () => "");
  188. const hotlist = async () => {
  189. try {
  190. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${2}&level=${4}&placeid=${1}`);
  191. console.log('热点资讯', response.data);
  192. for (let item of response.data) {
  193. console.log(item);
  194. item.count = 1;
  195. }
  196. hotlistall.value = response.data;
  197. } catch (error) {
  198. console.error(error);
  199. }
  200. }
  201. //资讯推荐1
  202. const news1 = useState("news1", () => "");
  203. const newslist1 = async () => {
  204. try {
  205. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  206. console.log('热点资讯', response.data);
  207. news1.value = response.data;
  208. } catch (error) {
  209. console.error(error);
  210. }
  211. }
  212. const news11 = useState("news11", () => "");
  213. const newslist11 = async () => {
  214. try {
  215. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  216. console.log('热点资讯', response.data);
  217. news11.value = response.data;
  218. } catch (error) {
  219. console.error(error);
  220. }
  221. }
  222. //资讯推荐2
  223. const news2 = useState("news2", () => "");
  224. const newslist2 = async () => {
  225. try {
  226. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  227. console.log('热点资讯', response.data);
  228. news2.value = response.data;
  229. } catch (error) {
  230. console.error(error);
  231. }
  232. }
  233. const news22 = useState("news22", () => "");
  234. const newslist22 = async () => {
  235. try {
  236. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  237. console.log('热点资讯', response.data);
  238. news22.value = response.data;
  239. } catch (error) {
  240. console.error(error);
  241. }
  242. }
  243. //挂载成功钩子函数
  244. onMounted(() => {
  245. // 资讯推荐
  246. newslists()
  247. // 热点资讯
  248. hotlist()
  249. // 资讯推荐
  250. newslist1()
  251. newslist2()
  252. // 热点资讯
  253. newslist11()
  254. newslist22()
  255. })
  256. //路由中间件
  257. definePageMeta({
  258. middleware: 'auth'
  259. })
  260. </script>
  261. <style lang="less" scoped>
  262. //导航条
  263. .breadcrumb {
  264. width: 100%;
  265. height: 22px;
  266. margin-bottom: 30px;
  267. font-family: Microsoft YaHei, Microsoft YaHei;
  268. font-weight: 400;
  269. font-size: 20px;
  270. color: #666666;
  271. line-height: 23px;
  272. text-align: left;
  273. font-style: normal;
  274. text-transform: none;
  275. :deep(.el-breadcrumb) {
  276. display: inline-block;
  277. vertical-align: -4px;
  278. }
  279. :deep(.el-breadcrumb__inner a),
  280. :deep(.el-breadcrumb__inner.is-link) {
  281. color: #666666;
  282. font-weight: 400;
  283. text-decoration: none;
  284. transition: var(--el-transition-color);
  285. }
  286. span {
  287. font-family: Microsoft YaHei, Microsoft YaHei;
  288. font-weight: 400;
  289. font-size: 20px;
  290. color: #666666;
  291. line-height: 23px;
  292. text-align: left;
  293. font-style: normal;
  294. text-transform: none;
  295. }
  296. span:hover {
  297. color: #666666;
  298. }
  299. .location {
  300. margin-right: 20px;
  301. width: 100px;
  302. height: 22px;
  303. font-family: Microsoft YaHei, Microsoft YaHei;
  304. font-weight: 400;
  305. font-size: 20px;
  306. color: #666666;
  307. line-height: 23px;
  308. text-align: left;
  309. font-style: normal;
  310. text-transform: none;
  311. }
  312. }
  313. // 资讯列表
  314. .newsList {
  315. width: 1200px;
  316. margin: 0 auto;
  317. height: 675px;
  318. margin-bottom: 70px;
  319. .inner {
  320. width: 1200px;
  321. .innerLeft {
  322. width: 100%;
  323. }
  324. .innerLeft,
  325. .innerRight {
  326. border-top: 1px solid #139602;
  327. clear: both;
  328. float: none;
  329. }
  330. .innerLeft {
  331. height: 675px;
  332. >.list {
  333. height: 570px;
  334. margin-bottom: 70px;
  335. >li {
  336. width: 100%;
  337. height: 56px;
  338. white-space: nowrap;
  339. overflow: hidden;
  340. text-overflow: ellipsis;
  341. line-height: 56px;
  342. border-bottom: 1px solid #D9D9D9;
  343. >a {
  344. width: 360px;
  345. height: 26px;
  346. font-family: Microsoft YaHei, Microsoft YaHei;
  347. font-weight: 400;
  348. font-size: 20px;
  349. color: #333333;
  350. line-height: 26px;
  351. text-align: left;
  352. font-style: normal;
  353. text-transform: none;
  354. }
  355. }
  356. >li:hover>a {
  357. color: #139602;
  358. }
  359. >li:nth-child(1)::after,
  360. >li:nth-child(2)::after {
  361. content: "热";
  362. margin-left: 13px;
  363. background: #FF8A37;
  364. color: #fff;
  365. font-size: 14px;
  366. padding: 0px 2px;
  367. }
  368. }
  369. >.pagination {
  370. width: 100%;
  371. height: 34px;
  372. margin-left: 141px;
  373. display: flex;
  374. justify-content: center;
  375. margin: 0;
  376. // 鼠标移入后字体颜色
  377. .el-pagination::v-deep :hover {
  378. color: #139609;
  379. }
  380. .el-pagination.is-background::v-deep .btn-next,
  381. .el-pagination.is-background::v-deep .btn-prev {
  382. width: 70px;
  383. height: 34px;
  384. margin: 0px 10px;
  385. border-radius: 4px;
  386. }
  387. .el-pagination.is-background::v-deep .el-pager li {
  388. margin: 0px 10px;
  389. width: 38px;
  390. height: 34px;
  391. border-radius: 4px;
  392. }
  393. .el-pagination.is-background::v-deep .btn-next.is-active,
  394. .el-pagination.is-background::v-deep .btn-prev.is-active,
  395. .el-pagination.is-background::v-deep .el-pager li.is-active {
  396. background-color: #028e21;
  397. color: #fff;
  398. }
  399. }
  400. }
  401. .innerRight {
  402. width: 381px;
  403. height: 605px;
  404. clear: both;
  405. overflow: hidden;
  406. }
  407. }
  408. }
  409. //资讯推荐
  410. .zixuntuijian {
  411. width: 100%;
  412. height: 290px;
  413. margin-bottom: 70px;
  414. .innerLeft {
  415. // 左侧
  416. .zixunLeft {
  417. margin-right: 30px;
  418. }
  419. .zixunRight,
  420. .zixunLeft {
  421. float: left;
  422. width: 380px;
  423. height: 290px;
  424. // 标题部分
  425. >.title {
  426. width: 380px;
  427. }
  428. >.title>h3 {
  429. height: 36px;
  430. font-family: Source Han Sans, Source Han Sans;
  431. font-weight: bold;
  432. font-size: 24px;
  433. color: #000000;
  434. line-height: 28px;
  435. text-align: left;
  436. font-style: normal;
  437. text-transform: none;
  438. border-bottom: 1px solid #139602;
  439. }
  440. >.title>h3>span {
  441. float: right;
  442. width: 56px;
  443. height: 20px;
  444. line-height: 24px;
  445. font-weight: 400;
  446. font-size: 14px;
  447. color: #999999;
  448. font-style: normal;
  449. text-transform: none;
  450. }
  451. .photo_text {
  452. >li:first-child {
  453. width: 380px;
  454. height: 120px;
  455. margin-top: 20px;
  456. margin-bottom: 15px;
  457. position: relative;
  458. >img {
  459. float: left;
  460. width: 160px;
  461. height: 120px;
  462. }
  463. >div {
  464. float: left;
  465. width: 220px;
  466. height: 120px;
  467. padding-left: 15px;
  468. padding-top: 6px;
  469. box-sizing: border-box;
  470. background-color: #f6f6f6;
  471. >h5 {
  472. width: 200px;
  473. height: 54px;
  474. display: -webkit-box;
  475. -webkit-box-orient: vertical;
  476. -webkit-line-clamp: 2;
  477. overflow: hidden;
  478. text-overflow: ellipsis;
  479. word-break: break-all;
  480. font-family: Source Han Sans, Source Han Sans;
  481. font-weight: 500;
  482. font-size: 18px;
  483. color: #333333;
  484. line-height: 26px;
  485. text-align: left;
  486. font-style: normal;
  487. text-transform: none;
  488. }
  489. >p {
  490. width: 200px;
  491. height: 22px;
  492. line-height: 20px;
  493. position: absolute;
  494. bottom: 5px;
  495. right: 0;
  496. >span {
  497. display: inline-block;
  498. // width: 100px;
  499. height: 18px;
  500. font-family: Source Han Sans, Source Han Sans;
  501. font-weight: 400;
  502. font-size: 12px;
  503. color: #999999;
  504. text-align: left;
  505. line-height: 14px;
  506. font-style: normal;
  507. text-transform: none;
  508. }
  509. >span:last-child {
  510. // width: 90px;
  511. text-align: right;
  512. margin-left: 20px;
  513. }
  514. }
  515. }
  516. }
  517. >li {
  518. width: 380px;
  519. height: 25px;
  520. white-space: nowrap;
  521. overflow: hidden;
  522. text-overflow: ellipsis;
  523. font-family: PingFang SC, PingFang SC;
  524. font-weight: 500;
  525. font-size: 18px;
  526. color: #333333;
  527. line-height: 21px;
  528. text-align: left;
  529. font-style: normal;
  530. text-transform: none;
  531. margin-bottom: 10px;
  532. em {
  533. display: inline-block;
  534. width: 8px;
  535. height: 8px;
  536. border-radius: 8px;
  537. margin-right: 10px;
  538. background-color: #d9d9d9;
  539. }
  540. }
  541. >li:hover {
  542. color: #139602;
  543. }
  544. >li:hover em {
  545. background-color: #139602;
  546. }
  547. }
  548. }
  549. }
  550. .innerRight {
  551. width: 381px;
  552. height: 290px;
  553. background-color: #fbfbfb;
  554. >.title {
  555. width: 380px;
  556. height: 40px;
  557. line-height: 40px;
  558. border-top: 1px solid #139602;
  559. border-bottom: 1px solid #e7e7e7;
  560. >h4 {
  561. font-family: Microsoft YaHei, Microsoft YaHei;
  562. font-weight: 400;
  563. margin-left: 20px;
  564. font-size: 20px;
  565. color: #000000;
  566. text-align: left;
  567. font-style: normal;
  568. text-transform: none;
  569. >span {
  570. float: right;
  571. font-family: Microsoft YaHei, Microsoft YaHei;
  572. font-weight: 400;
  573. font-size: 14px;
  574. margin-right: 10px;
  575. color: #999999;
  576. text-align: left;
  577. font-style: normal;
  578. text-transform: none;
  579. }
  580. }
  581. }
  582. .rightList {
  583. height: 540px;
  584. margin-top: 20px;
  585. >li {
  586. height: 100px;
  587. margin-bottom: 10px;
  588. >img {
  589. width: 150px;
  590. height: 100px;
  591. }
  592. >p {
  593. width: 219px;
  594. height: 100px;
  595. padding-left: 12px;
  596. font-family: PingFang SC, PingFang SC;
  597. font-weight: 400;
  598. font-size: 16px;
  599. color: #333333;
  600. line-height: 22px;
  601. text-align: left;
  602. font-style: normal;
  603. text-transform: none;
  604. }
  605. >p:hover {
  606. box-shadow: 0 0 16px 1px rgba(0, 0, 0, 0.1);
  607. }
  608. }
  609. }
  610. }
  611. }
  612. .searchBox {
  613. text-align: center;
  614. padding-bottom: 40px;
  615. }
  616. </style>