search.vue 21 KB

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