search.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. const catids = ref([]);
  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. // 从地区跳转
  222. if (route.query.catids && route.query.catids.length > 0) {
  223. // 将字符串转换回数组,并过滤掉可能的空值
  224. catids.value = route.query.catids.split(',').filter(id => id);
  225. if (catids.value.length > 0) {
  226. // 有效的 catids 数组,可以进行后续操作
  227. console.log('接收到的分类ID数组:', catids.value);
  228. let font = catids.value.join(",")
  229. font = "[" + font + "]"
  230. //console.log(font);
  231. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${font}`);
  232. console.log(response.data.rows);
  233. newsList.value = response.data.rows;
  234. total.value = response.data.count;
  235. } else {
  236. // 处理空数组情况
  237. console.log('未接收到有效的分类ID');
  238. }
  239. } else {
  240. if (category_id == undefined) {
  241. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&keyword=${searchKey}`);
  242. // console.log(response.data.rows);
  243. newsList.value = response.data.rows;
  244. total.value = response.data.count;
  245. } else {
  246. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${category_id}&keyword=${searchKey}`);
  247. // console.log(response.data.rows);
  248. newsList.value = response.data.rows;
  249. total.value = response.data.count;
  250. }
  251. }
  252. } catch (error) {
  253. console.error(error);
  254. }
  255. }
  256. //热点资讯
  257. const hotlistall = useState("hotlistall", () => "");
  258. const hotlist = async () => {
  259. try {
  260. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${2}&level=${4}&placeid=${1}`);
  261. console.log('热点资讯', response.data);
  262. for (let item of response.data) {
  263. console.log(item);
  264. item.count = 1;
  265. }
  266. hotlistall.value = response.data;
  267. } catch (error) {
  268. console.error(error);
  269. }
  270. }
  271. //资讯推荐1
  272. const news1 = useState("news1", () => "");
  273. const newslist1 = async () => {
  274. try {
  275. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  276. console.log('热点资讯', response.data);
  277. news1.value = response.data;
  278. } catch (error) {
  279. console.error(error);
  280. }
  281. }
  282. const news11 = useState("news11", () => "");
  283. const newslist11 = async () => {
  284. try {
  285. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  286. console.log('热点资讯', response.data);
  287. news11.value = response.data;
  288. } catch (error) {
  289. console.error(error);
  290. }
  291. }
  292. //资讯推荐2
  293. const news2 = useState("news2", () => "");
  294. const newslist2 = async () => {
  295. try {
  296. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  297. console.log('热点资讯', response.data);
  298. news2.value = response.data;
  299. } catch (error) {
  300. console.error(error);
  301. }
  302. }
  303. const news22 = useState("news22", () => "");
  304. const newslist22 = async () => {
  305. try {
  306. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  307. console.log('热点资讯', response.data);
  308. news22.value = response.data;
  309. } catch (error) {
  310. console.error(error);
  311. }
  312. }
  313. //挂载成功钩子函数
  314. onMounted(() => {
  315. // 资讯推荐
  316. newslists()
  317. // 热点资讯
  318. hotlist()
  319. // 资讯推荐
  320. newslist1()
  321. newslist2()
  322. // 热点资讯
  323. newslist11()
  324. newslist22()
  325. })
  326. //路由中间件
  327. definePageMeta({
  328. middleware: 'auth'
  329. })
  330. </script>
  331. <style lang="less" scoped>
  332. //导航条
  333. .breadcrumb {
  334. width: 100%;
  335. height: 22px;
  336. margin-bottom: 30px;
  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. :deep(.el-breadcrumb) {
  346. display: inline-block;
  347. vertical-align: -4px;
  348. }
  349. :deep(.el-breadcrumb__inner a),
  350. :deep(.el-breadcrumb__inner.is-link) {
  351. color: #666666;
  352. font-weight: 400;
  353. text-decoration: none;
  354. transition: var(--el-transition-color);
  355. }
  356. span {
  357. font-family: Microsoft YaHei, Microsoft YaHei;
  358. font-weight: 400;
  359. font-size: 20px;
  360. color: #666666;
  361. line-height: 23px;
  362. text-align: left;
  363. font-style: normal;
  364. text-transform: none;
  365. }
  366. span:hover {
  367. color: #666666;
  368. }
  369. .location {
  370. margin-right: 20px;
  371. width: 100px;
  372. height: 22px;
  373. font-family: Microsoft YaHei, Microsoft YaHei;
  374. font-weight: 400;
  375. font-size: 20px;
  376. color: #666666;
  377. line-height: 23px;
  378. text-align: left;
  379. font-style: normal;
  380. text-transform: none;
  381. }
  382. }
  383. // 资讯列表
  384. .newsList {
  385. width: 1200px;
  386. margin: 0 auto;
  387. //height: 675px;
  388. margin-bottom: 70px;
  389. .inner {
  390. width: 1200px;
  391. .innerLeft {
  392. width: 100%;
  393. }
  394. .innerLeft,
  395. .innerRight {
  396. border-top: 1px solid #139602;
  397. clear: both;
  398. float: none;
  399. }
  400. .innerLeft {
  401. //height: 675px;
  402. >.list {
  403. //height: 570px;
  404. margin-bottom: 70px;
  405. >li {
  406. width: 100%;
  407. height: 56px;
  408. white-space: nowrap;
  409. overflow: hidden;
  410. text-overflow: ellipsis;
  411. line-height: 56px;
  412. >a {
  413. width: 360px;
  414. height: 26px;
  415. font-family: Microsoft YaHei, Microsoft YaHei;
  416. font-weight: 400;
  417. font-size: 20px;
  418. color: #333333;
  419. line-height: 26px;
  420. text-align: left;
  421. font-style: normal;
  422. text-transform: none;
  423. }
  424. }
  425. >li:hover>a {
  426. color: #139602;
  427. }
  428. >li:nth-child(1)::after,
  429. >li:nth-child(2)::after {
  430. content: "热";
  431. margin-left: 13px;
  432. background: #FF8A37;
  433. color: #fff;
  434. font-size: 14px;
  435. padding: 0px 2px;
  436. }
  437. >li:nth-child(5n) {
  438. border-bottom: 1px solid #D9D9D9;
  439. }
  440. }
  441. >.pagination {
  442. width: 100%;
  443. height: 34px;
  444. margin-left: 141px;
  445. display: flex;
  446. justify-content: center;
  447. margin: 0;
  448. // 鼠标移入后字体颜色
  449. .el-pagination::v-deep :hover {
  450. color: #139609;
  451. }
  452. .el-pagination.is-background::v-deep .btn-next,
  453. .el-pagination.is-background::v-deep .btn-prev {
  454. width: 70px;
  455. height: 34px;
  456. margin: 0px 10px;
  457. border-radius: 4px;
  458. }
  459. .el-pagination.is-background::v-deep .el-pager li {
  460. margin: 0px 10px;
  461. width: 38px;
  462. height: 34px;
  463. border-radius: 4px;
  464. }
  465. .el-pagination.is-background::v-deep .btn-next.is-active,
  466. .el-pagination.is-background::v-deep .btn-prev.is-active,
  467. .el-pagination.is-background::v-deep .el-pager li.is-active {
  468. background-color: #028e21;
  469. color: #fff;
  470. }
  471. }
  472. }
  473. .innerRight {
  474. width: 381px;
  475. height: 605px;
  476. clear: both;
  477. overflow: hidden;
  478. }
  479. }
  480. }
  481. //资讯推荐
  482. .zixuntuijian {
  483. width: 100%;
  484. height: 290px;
  485. margin-bottom: 70px;
  486. .innerLeft {
  487. // 左侧
  488. .zixunLeft {
  489. margin-right: 30px;
  490. }
  491. .zixunRight,
  492. .zixunLeft {
  493. float: left;
  494. width: 380px;
  495. height: 290px;
  496. // 标题部分
  497. >.title {
  498. width: 380px;
  499. }
  500. >.title>h3 {
  501. height: 36px;
  502. font-family: Source Han Sans, Source Han Sans;
  503. font-weight: bold;
  504. font-size: 24px;
  505. color: #000000;
  506. line-height: 28px;
  507. text-align: left;
  508. font-style: normal;
  509. text-transform: none;
  510. border-bottom: 1px solid #139602;
  511. }
  512. >.title>h3>span {
  513. float: right;
  514. width: 56px;
  515. height: 20px;
  516. line-height: 24px;
  517. font-weight: 400;
  518. font-size: 14px;
  519. color: #999999;
  520. font-style: normal;
  521. text-transform: none;
  522. }
  523. .photo_text {
  524. >li:first-child {
  525. width: 380px;
  526. height: 120px;
  527. margin-top: 20px;
  528. margin-bottom: 15px;
  529. position: relative;
  530. >img {
  531. float: left;
  532. width: 160px;
  533. height: 120px;
  534. }
  535. >div {
  536. float: left;
  537. width: 220px;
  538. height: 120px;
  539. padding-left: 15px;
  540. padding-top: 6px;
  541. box-sizing: border-box;
  542. background-color: #f6f6f6;
  543. >h5 {
  544. width: 200px;
  545. height: 54px;
  546. display: -webkit-box;
  547. -webkit-box-orient: vertical;
  548. -webkit-line-clamp: 2;
  549. overflow: hidden;
  550. text-overflow: ellipsis;
  551. word-break: break-all;
  552. font-family: Source Han Sans, Source Han Sans;
  553. font-weight: 500;
  554. font-size: 18px;
  555. color: #333333;
  556. line-height: 26px;
  557. text-align: left;
  558. font-style: normal;
  559. text-transform: none;
  560. }
  561. >p {
  562. width: 200px;
  563. height: 22px;
  564. line-height: 20px;
  565. position: absolute;
  566. bottom: 5px;
  567. right: 0;
  568. >span {
  569. display: inline-block;
  570. // width: 100px;
  571. height: 18px;
  572. font-family: Source Han Sans, Source Han Sans;
  573. font-weight: 400;
  574. font-size: 12px;
  575. color: #999999;
  576. text-align: left;
  577. line-height: 14px;
  578. font-style: normal;
  579. text-transform: none;
  580. }
  581. >span:last-child {
  582. // width: 90px;
  583. text-align: right;
  584. margin-left: 20px;
  585. }
  586. }
  587. }
  588. }
  589. >li {
  590. width: 380px;
  591. height: 25px;
  592. white-space: nowrap;
  593. overflow: hidden;
  594. text-overflow: ellipsis;
  595. font-family: PingFang SC, PingFang SC;
  596. font-weight: 500;
  597. font-size: 18px;
  598. color: #333333;
  599. line-height: 21px;
  600. text-align: left;
  601. font-style: normal;
  602. text-transform: none;
  603. margin-bottom: 10px;
  604. em {
  605. display: inline-block;
  606. width: 8px;
  607. height: 8px;
  608. border-radius: 8px;
  609. margin-right: 10px;
  610. background-color: #d9d9d9;
  611. }
  612. }
  613. >li:hover {
  614. color: #139602;
  615. }
  616. >li:hover em {
  617. background-color: #139602;
  618. }
  619. }
  620. }
  621. }
  622. .innerRight {
  623. width: 381px;
  624. height: 290px;
  625. background-color: #fbfbfb;
  626. >.title {
  627. width: 380px;
  628. height: 40px;
  629. line-height: 40px;
  630. border-top: 1px solid #139602;
  631. border-bottom: 1px solid #e7e7e7;
  632. >h4 {
  633. font-family: Microsoft YaHei, Microsoft YaHei;
  634. font-weight: 400;
  635. margin-left: 20px;
  636. font-size: 20px;
  637. color: #000000;
  638. text-align: left;
  639. font-style: normal;
  640. text-transform: none;
  641. >span {
  642. float: right;
  643. font-family: Microsoft YaHei, Microsoft YaHei;
  644. font-weight: 400;
  645. font-size: 14px;
  646. margin-right: 10px;
  647. color: #999999;
  648. text-align: left;
  649. font-style: normal;
  650. text-transform: none;
  651. }
  652. }
  653. }
  654. .rightList {
  655. height: 540px;
  656. margin-top: 20px;
  657. >li {
  658. height: 100px;
  659. margin-bottom: 10px;
  660. >img {
  661. width: 150px;
  662. height: 100px;
  663. }
  664. >p {
  665. width: 219px;
  666. height: 100px;
  667. padding-left: 12px;
  668. font-family: PingFang SC, PingFang SC;
  669. font-weight: 400;
  670. font-size: 16px;
  671. color: #333333;
  672. line-height: 22px;
  673. text-align: left;
  674. font-style: normal;
  675. text-transform: none;
  676. }
  677. >p:hover {
  678. box-shadow: 0 0 16px 1px rgba(0, 0, 0, 0.1);
  679. }
  680. }
  681. }
  682. }
  683. }
  684. .searchBox {
  685. text-align: center;
  686. padding-bottom: 40px;
  687. }
  688. </style>