search.vue 24 KB

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