Slider.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <template>
  2. <!-- 滑块 -->
  3. <!-- v-if="navigation1[2]" -->
  4. <div class="slider" v-if="navigation1[2]">
  5. <!-- 标题部分 -->
  6. <div class="scienceTitle" v-if="navigation1[2]">
  7. <h5 v-if="navigation1[2].category_id">
  8. <NuxtLink
  9. :to="{ path: `/newsList/${navigation1[2].category_id}`}"
  10. target="_blank" v-if="navigation1[2].category_id&&message.children_count!=0" class="active">
  11. {{navigation1[2].alias}}
  12. </NuxtLink>
  13. <NuxtLink
  14. :to="{ path: `/primaryNavigation/${navigation1[2].category_id}`}"
  15. target="_blank" v-else-if="navigation1[2].category_id&&message.children_count==0" class="active">
  16. {{navigation1[2].alias}}
  17. </NuxtLink>
  18. </h5>
  19. <NuxtLink :to="`/newsList/${navigation1[2].category_id}`" target="_blank">
  20. 查看更多
  21. </NuxtLink>
  22. <!-- <span>查看更多</span> -->
  23. <!-- <p class="title">
  24. <span v-for="(item, index) in scienceTitleList" :key="index" @mousemove="changeUl(index)">
  25. <a href="#">{{ item.title }}</a>
  26. </span>
  27. </p> -->
  28. </div>
  29. <!-- 标题下内容列表 -->
  30. <div class="box">
  31. <div class="boxcontent">
  32. <div class="boxleft" v-if="boxData1[0]">
  33. <div class="boxBigImg">
  34. <NuxtLink :to="`/newsDetail/${boxData1[0].id}`" target="_blank" class="imgbg">
  35. <img :src="boxData1[0].imgurl">
  36. <div>
  37. <p><span>专题</span>{{ boxData1[0].title }}</p>
  38. <span>{{ getDays(boxData1[0].created_at) }}</span>
  39. </div>
  40. </NuxtLink>
  41. </div>
  42. <div class="boxMainImg">
  43. <NuxtLink :to="`/newsDetail/${boxData1[1].id}`" target="_blank" class="imgbg">
  44. <img :src="boxData1[1].imgurl">
  45. <div>
  46. <p>{{ boxData1[1].title }}</p>
  47. <span>{{ getDays(boxData1[1].created_at) }}</span>
  48. </div>
  49. </NuxtLink>
  50. <NuxtLink :to="`/newsDetail/${boxData1[2].id}`" target="_blank" class="imgbg">
  51. <img :src="boxData1[2].imgurl">
  52. <div>
  53. <p>{{ boxData1[2].title }}</p>
  54. <span>{{ getDays(boxData1[2].created_at) }}</span>
  55. </div>
  56. </NuxtLink>
  57. </div>
  58. <div class="boxBigImg">
  59. <NuxtLink :to="`/newsDetail/${boxData1[3].id}`" target="_blank" class="imgbg">
  60. <img :src="boxData1[3].imgurl">
  61. <div>
  62. <p>{{ boxData1[3].title }}</p>
  63. <span>{{ getDays(boxData1[3].created_at) }}</span>
  64. </div>
  65. </NuxtLink>
  66. </div>
  67. </div>
  68. <div class="boxright">
  69. <ul>
  70. <li v-for="item in boxData2">
  71. <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank">
  72. <p class="title">{{ item.title }}</p>
  73. <p class="time">{{ getDays(item.created_at) }}</p>
  74. </NuxtLink>
  75. </li>
  76. </ul>
  77. </div>
  78. </div>
  79. <!-- <ul class="scienceList">
  80. <li v-for="item in boxData2">
  81. <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank">
  82. <img :src="item.imgurl">
  83. <p>{{ item.title }}</p>
  84. </NuxtLink>
  85. </li>
  86. </ul> -->
  87. <!-- <transition name="fade">
  88. <div class="scienceListBox">
  89. <ul class="scienceList">
  90. <li v-for="item in boxData1">
  91. <NuxtLink
  92. :to="{ path: `/newsDetail/${item.id}`, query: { listId: routeId, listName: routeName } }"
  93. target="_blank">
  94. <img :src="item.imgurl">
  95. <p>{{ item.title }}</p>
  96. </NuxtLink>
  97. </li>
  98. </ul>
  99. <ul class="scienceList">
  100. <li v-for="item in 6">
  101. <img src="../../static/images/sgbhsihfgisdfaasda45632113_A_Chinese_farmer_carrying_a_hoe_is_h_1ba32eee-c498-4dd7-9cd9-013568c09db7.png"
  102. alt="">
  103. <p>市农业农村局关于印发连云港市市级…</p>
  104. </li>
  105. </ul>
  106. <ul class="scienceList">
  107. <li v-for="item in 6">
  108. <img src="../../static/images/rgmezdvz_19982_On_a_vast_and_boundless_wheat_field_many_harvest_5b5cfeda-ef17-4551-a935-5f8e3f799b69.png"
  109. alt="">
  110. <p>市农业农村局关于印发连云港市市级…</p>
  111. </li>
  112. </ul>
  113. <ul class="scienceList">
  114. <li v-for="item in 6">
  115. <img src="../../static/images/rgmezdvz_19982_A_Chinese_farmer_carrying_a_hoe_is_hoeing_the_fi_a036c7b3-b05e-4d3d-a371-0bed91ec1ff8(1).png"
  116. alt="">
  117. <p>市农业农村局关于印发连云港市市级…</p>
  118. </li>
  119. </ul>
  120. </div>
  121. </transition> -->
  122. </div>
  123. </div>
  124. </template>
  125. <script setup>
  126. const nuxtApp = useNuxtApp();
  127. const axios = nuxtApp.$axios;
  128. const radio1 = ref('1')
  129. const props = defineProps({
  130. message: Array,
  131. });
  132. //获取导航一的栏目
  133. const navigation1 = ref("");
  134. const navigateList = async () => {
  135. try {
  136. const response = await axios.get(`/web/getWebsiteModelCategory?placeid=${1}&pid=${0}&num=${24}`);
  137. console.log('一级导航', response.data);
  138. navigation1.value = response.data;
  139. getWebsiteModelArticles()
  140. getWebsiteModelArticles2()
  141. } catch (error) {
  142. console.error(error);
  143. }
  144. }
  145. const boxData1 = ref("");
  146. const getWebsiteModelArticles = async () => {
  147. try {
  148. // console.log(99999999);
  149. // console.log(navigation1.value[2].category_id)
  150. let cid = navigation1.value[2].category_id
  151. const response = await axios.get(`/web/getWebsiteModelArticles?catid=${cid}&level=${1}&pagesize=${4}`);
  152. boxData1.value = response.data;
  153. } catch (error) {
  154. console.error(error);
  155. }
  156. }
  157. const boxData2 = ref("");
  158. const getWebsiteModelArticles2 = async () => {
  159. try {
  160. // console.log(99999999);
  161. // console.log(navigation1.value[2].category_id)
  162. let cid = navigation1.value[2].category_id
  163. const response = await axios.get(`/web/getWebsiteModelArticles?catid=${cid}&level=${3}&pagesize=${6}`);
  164. boxData2.value = response.data;
  165. } catch (error) {
  166. console.error(error);
  167. }
  168. }
  169. function getTime(time) {
  170. const date = new Date(time);
  171. const year = date.getFullYear();
  172. const month = date.getMonth() + 1;
  173. const day = date.getDate();
  174. return `${year}-${month}-${day}`;
  175. }
  176. onMounted(() => {
  177. // 一级导航
  178. navigateList()
  179. })
  180. let scienceTitleList = [
  181. {
  182. id: 1,
  183. title: "农产畅销"
  184. },
  185. {
  186. id: 2,
  187. title: "农业在线"
  188. },
  189. {
  190. id: 3,
  191. title: "农产行情"
  192. },
  193. {
  194. id: 4,
  195. title: "名优特产"
  196. }
  197. ]
  198. //鼠标移入标题时,下方内容会发生变化
  199. // let changeUl = (index) => {
  200. // // console.log(index);
  201. // if (process.browser) {
  202. // let scienceListBox = document.querySelector('.scienceListBox');
  203. // let titleList = document.querySelectorAll('.title>span>a')
  204. // for (let i = 0; i < titleList.length; i++) {
  205. // titleList[i].className = ''
  206. // }
  207. // titleList[index].setAttribute('class', 'current')
  208. // if (index == 0) {
  209. // scienceListBox.style.left = 0
  210. // } else if (index == 1) {
  211. // scienceListBox.style.left = "-790px"
  212. // } else if (index == 2) {
  213. // scienceListBox.style.left = "-1580px"
  214. // } else if (index == 3) {
  215. // scienceListBox.style.left = "-2370px"
  216. // }
  217. // }
  218. // }
  219. function getDays(time) {
  220. const date = new Date(time);
  221. const year = date.getFullYear();
  222. const month = date.getMonth() + 1;
  223. const day = date.getDate();
  224. return `${month}-${day}`;
  225. }
  226. </script>
  227. <style lang="less" scoped>
  228. .slider {
  229. width: 720px;
  230. }
  231. // 标题
  232. .scienceTitle {
  233. height: 50px;
  234. line-height: 50px;
  235. border-bottom: 1px solid #D9D9D9;
  236. display: flex;
  237. justify-content: space-between;
  238. h5 {
  239. float: left;
  240. width: 96px;
  241. height: 34px;
  242. font-family: PingFang SC, PingFang SC;
  243. font-weight: 600;
  244. font-size: 24px;
  245. color: #000000;
  246. line-height: 28px;
  247. text-align: left;
  248. font-style: normal;
  249. text-transform: none;
  250. margin-right: 20px;
  251. // border-bottom: 2px solid #139602;
  252. height: 50px;
  253. line-height: 50px;
  254. a {
  255. font-size: 22px;
  256. color: #139602;
  257. border-bottom: 3px solid #139602;
  258. height: 50px;
  259. line-height: 50px;
  260. display: inline-block;
  261. box-sizing: border-box;
  262. width: auto;
  263. font-weight: bold;
  264. }
  265. }
  266. a {
  267. width: 65px;
  268. height: 50px;
  269. line-height: 50px;
  270. font-weight: 400;
  271. font-size: 16px;
  272. color: #333333;
  273. font-style: normal;
  274. text-transform: none;
  275. display: inline-block;
  276. }
  277. >p {
  278. float: left;
  279. height: 37px;
  280. line-height: 30px;
  281. >span {
  282. display: inline-block;
  283. height: 20px;
  284. line-height: 20px;
  285. text-align: center;
  286. margin: 4px 0px 3px;
  287. padding: 0 20px;
  288. border-right: 1px solid #ccc;
  289. >a {
  290. display: inline-block;
  291. padding-bottom: 11px;
  292. font-family: PingFang SC, PingFang SC;
  293. font-weight: 500;
  294. font-size: 20px;
  295. color: #666666;
  296. line-height: 20px;
  297. font-style: normal;
  298. text-transform: none;
  299. box-sizing: border-box;
  300. }
  301. .current {
  302. color: #139602;
  303. border-bottom: 1px solid #139602;
  304. }
  305. }
  306. >span:nth-child(4) {
  307. border-right: none;
  308. }
  309. >span:hover>a {
  310. color: #139602;
  311. border-bottom: 1px solid #139602;
  312. }
  313. }
  314. }
  315. .box {
  316. width: 720px;
  317. height: 700px;
  318. position: relative;
  319. overflow: hidden;
  320. .boxcontent {
  321. display: flex;
  322. justify-content: space-between;
  323. padding-top: 30px;
  324. .boxleft {
  325. width: 349px;
  326. height: 700px;
  327. padding-bottom: 30px;
  328. }
  329. }
  330. .boxMainImg {
  331. display: flex;
  332. justify-content: space-between;
  333. margin-bottom: 15px;
  334. a {
  335. position: relative;
  336. img {
  337. width: 170px;
  338. height: 115px;
  339. border-radius: 4px;
  340. border-radius: 6px;
  341. }
  342. div {
  343. position: absolute;
  344. bottom: 4px;
  345. left: 7px;
  346. p {
  347. display: -webkit-box;
  348. -webkit-box-orient: vertical;
  349. -webkit-line-clamp: 2;
  350. overflow: hidden;
  351. text-overflow: ellipsis;
  352. word-break: break-all;
  353. width: 158px;
  354. height: 42px;
  355. color: #fff;
  356. }
  357. span {
  358. display:block;
  359. height: 20px;
  360. line-height: 20px;
  361. text-align: left;
  362. color: #fff;
  363. }
  364. }
  365. }
  366. }
  367. .boxBigImg {
  368. margin-bottom: 15px;
  369. a {
  370. position: relative;
  371. img {
  372. width: 349px;
  373. height: 236px;
  374. border-radius: 6px;
  375. }
  376. div {
  377. position: absolute;
  378. bottom: 7px;
  379. left: 20px;
  380. z-index: 99;
  381. p{
  382. display: -webkit-box;
  383. -webkit-box-orient: vertical;
  384. -webkit-line-clamp: 2;
  385. overflow: hidden;
  386. text-overflow: ellipsis;
  387. word-break: break-all;
  388. width: 320px;
  389. height: 42px;
  390. color: #fff;
  391. font-size: 16px;
  392. margin-bottom: 5px;
  393. span {
  394. display: inline-block;
  395. background: #9CD26B;
  396. font-size: 14px;
  397. color: #fff;
  398. padding: 0 6px;
  399. border-radius: 4px;
  400. margin-right: 5px;
  401. }
  402. }
  403. span {
  404. display:block;
  405. height: 20px;
  406. line-height: 20px;
  407. text-align: left;
  408. color: #fff;
  409. }
  410. }
  411. }
  412. }
  413. }
  414. .fade-in {
  415. animation: fadeIn 1s ease-in-out;
  416. }
  417. .fade-enter-from,
  418. .fade-leave-to {
  419. opacity: 0;
  420. }
  421. .fade-enter-to,
  422. .fade-leave-from {
  423. opacity: 1;
  424. }
  425. .fade-enter-active,
  426. .fade-leave-active {
  427. transition: opacity 1s ease;
  428. }
  429. .scienceListBox {
  430. width: 3160px;
  431. height: 570px;
  432. position: absolute;
  433. top: 0;
  434. left: 0;
  435. transition: all 3s linear 0;
  436. z-index: 99;
  437. }
  438. // 标题下列表
  439. .scienceList {
  440. width: 790px;
  441. height: 570px;
  442. float: left;
  443. margin-top: 17px;
  444. >li {
  445. width: 250px;
  446. height: 276px;
  447. float: left;
  448. margin-right: 20px;
  449. position: relative;
  450. img {
  451. width: 250px;
  452. height: 220px;
  453. border-radius: 40px 4px 40px 4px;
  454. }
  455. p {
  456. width: 254px;
  457. display: -webkit-box;
  458. -webkit-box-orient: vertical;
  459. -webkit-line-clamp: 2;
  460. overflow: hidden;
  461. text-overflow: ellipsis;
  462. word-break: break-all;
  463. height: 48px;
  464. overflow: hidden;
  465. font-family: PingFang SC, PingFang SC;
  466. font-weight: 600;
  467. font-size: 18px;
  468. color: #333333;
  469. line-height: 24px;
  470. text-align: left;
  471. font-style: normal;
  472. text-transform: none;
  473. }
  474. p:hover {
  475. color: #139602;
  476. }
  477. }
  478. >li:nth-child(3),
  479. >li:nth-child(6) {
  480. margin-right: 0;
  481. }
  482. >li::before {
  483. content: "";
  484. display: inline-block;
  485. width: 40px;
  486. height: 20px;
  487. position: absolute;
  488. z-index: 99;
  489. top: 0;
  490. right: 0;
  491. background-image: url("../../static/images/Component 209.png");
  492. }
  493. }
  494. .boxright {
  495. ul {
  496. li {
  497. width: 349px;
  498. box-sizing: border-box;
  499. border-bottom: 1px solid #E6E6E6;
  500. margin-bottom: 20px;
  501. padding-bottom: 10px;
  502. .title {
  503. height: 42px;
  504. display: -webkit-box;
  505. -webkit-box-orient: vertical;
  506. -webkit-line-clamp: 2;
  507. overflow: hidden;
  508. text-overflow: ellipsis;
  509. word-break: break-all;
  510. height: 42px;
  511. width: 100%;
  512. font-size: 16px;
  513. color: #333333;
  514. margin-bottom: 5px;
  515. }
  516. .title:hover {
  517. color: #49A769;
  518. }
  519. .time {
  520. font-size: 14px;
  521. color: #999999;
  522. margin-bottom: 10px;
  523. }
  524. }
  525. }
  526. }
  527. .imgbg::after{
  528. content: '';
  529. display: block;
  530. width:100%;
  531. height:68px;
  532. z-index:44;
  533. left:0px;
  534. bottom:4px;
  535. position:absolute;
  536. background:linear-gradient(to bottom,rgba(0,0,0,0),black);
  537. opacity:.3;
  538. border-radius: 6px;
  539. }
  540. </style>