search.vue 23 KB

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