index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view class="page-container">
  3. <!-- 顶部标签导航 -->
  4. <view class="header-tabs">
  5. <view
  6. class="tab-item"
  7. :class="{ active: currentTab === 0 }"
  8. @click="handleTabChange(0)"
  9. >
  10. <text>农技知识</text>
  11. <view class="tab-line" :class="{ active: currentTab === 0 }"></view>
  12. </view>
  13. <view
  14. class="tab-item"
  15. :class="{ active: currentTab === 1 }"
  16. @click="handleTabChange(1)"
  17. >
  18. <text>政策解读</text>
  19. <view class="tab-line" :class="{ active: currentTab === 1 }"></view>
  20. </view>
  21. </view>
  22. <!-- 内容区域 -->
  23. <scroll-view
  24. scroll-y
  25. class="content-container"
  26. @scrolltolower="loadMore"
  27. @refresherrefresh="onRefresh"
  28. refresher-enabled
  29. :refresher-triggered="isRefreshing"
  30. >
  31. <!-- 主内容区域 -->
  32. <view class="cards-section">
  33. <!-- 农技知识内容 -->
  34. <block v-if="currentTab === 0">
  35. <navigator
  36. class="content-card"
  37. v-for="(item, index) in techList"
  38. :key="index"
  39. :url="`/pages/knowledge/detail?id=${item.id}&type=tech`"
  40. hover-class="card-hover"
  41. >
  42. <view class="content-thumbnail">
  43. <image
  44. :src="item.image"
  45. mode="aspectFill"
  46. class="thumbnail-image"
  47. lazy-load
  48. />
  49. <!-- 仅视频类型显示时长和播放按钮 -->
  50. <template v-if="item.contentType === 'video'">
  51. <view class="video-duration">{{ item.duration || '35:56' }}</view>
  52. <view class="play-button">
  53. <view class="play-icon"></view>
  54. </view>
  55. <view class="content-type-tag video">视频</view>
  56. </template>
  57. <!-- 文章类型显示标签 -->
  58. <template v-else>
  59. <view class="content-type-tag article">文章</view>
  60. </template>
  61. </view>
  62. <view class="content-info">
  63. <text class="content-title">{{ item.title }}</text>
  64. <view class="info-row">
  65. <text class="source-name">{{ item.source || '中国农业科技' }}</text>
  66. <view class="view-count">
  67. <text class="iconfont icon-eye"></text>
  68. <text>已读 {{ item.viewCount }}</text>
  69. </view>
  70. </view>
  71. </view>
  72. </navigator>
  73. </block>
  74. <!-- 政策解读内容 -->
  75. <block v-if="currentTab === 1">
  76. <navigator
  77. class="content-card"
  78. v-for="(item, index) in policyList"
  79. :key="index"
  80. :url="`/pages/knowledge/detail?id=${item.id}&type=policy`"
  81. hover-class="card-hover"
  82. >
  83. <view class="content-thumbnail">
  84. <image
  85. :src="item.image"
  86. mode="aspectFill"
  87. class="thumbnail-image"
  88. lazy-load
  89. />
  90. <!-- 仅视频类型显示时长和播放按钮 -->
  91. <template v-if="item.contentType === 'video'">
  92. <view class="video-duration">{{ item.duration || '28:32' }}</view>
  93. <view class="play-button">
  94. <view class="play-icon"></view>
  95. </view>
  96. <view class="content-type-tag video">视频</view>
  97. </template>
  98. <!-- 文章类型显示标签 -->
  99. <template v-else>
  100. <view class="content-type-tag article">文章</view>
  101. </template>
  102. </view>
  103. <view class="content-info">
  104. <text class="content-title">{{ item.title }}</text>
  105. <view class="info-row">
  106. <text class="source-name">{{ item.source || '农业部官方' }}</text>
  107. <view class="view-count">
  108. <text class="iconfont icon-eye"></text>
  109. <text>已读 {{ item.viewCount }}</text>
  110. </view>
  111. </view>
  112. </view>
  113. </navigator>
  114. </block>
  115. <!-- 无数据状态 -->
  116. <view class="empty-state" v-if="(currentTab === 0 && techList.length === 0) || (currentTab === 1 && policyList.length === 0)">
  117. <image src="/static/images/empty.png" mode="aspectFit" class="empty-image"></image>
  118. <text class="empty-text">暂无数据</text>
  119. </view>
  120. </view>
  121. <!-- 底部安全区域 -->
  122. <view style="height: 120rpx;"></view>
  123. </scroll-view>
  124. <!-- AI问答悬浮按钮 -->
  125. <view class="assistant-btn" @click="navigateToAI" hover-class="btn-hover">
  126. <image src="/static/icons/ai.png" class="assistant-icon" mode="aspectFit"></image>
  127. <text class="btn-text">问农小禹</text>
  128. </view>
  129. </view>
  130. </template>
  131. <script setup>
  132. import { ref, onMounted } from 'vue'
  133. // 当前标签
  134. const currentTab = ref(0)
  135. // 农技知识列表
  136. const techList = ref([
  137. {
  138. id: 1,
  139. title: '水稻高产栽培技术指南',
  140. description: '详解水稻种植关键技术要点,包括育苗、插秧、水肥管理等全过程技术要领',
  141. viewCount: '289',
  142. image: 'https://img.freepik.com/free-photo/rice-field-with-beautiful-sky_74190-7490.jpg',
  143. type: '农技',
  144. contentType: 'article', // 标记为文章类型
  145. source: '农业技术研究院'
  146. },
  147. {
  148. id: 2,
  149. title: '果树病虫害防治方案视频教学',
  150. description: '常见果树病虫害的识别方法、防治时期、用药指导,助您果园增产增收',
  151. viewCount: '856',
  152. image: 'https://img.freepik.com/free-photo/apple-tree-with-ripe-red-apples_1150-9301.jpg',
  153. type: '农技',
  154. contentType: 'video', // 标记为视频类型
  155. duration: '15:32',
  156. source: '中国农业科技'
  157. },
  158. {
  159. id: 3,
  160. title: '科学施肥技术指南',
  161. description: '解析不同作物的施肥特点,平衡施肥技术,提高肥料利用率',
  162. viewCount: '667',
  163. image: 'https://img.freepik.com/free-photo/farmer-holding-chemical-fertilizer-field_1150-7167.jpg',
  164. type: '农技',
  165. contentType: 'article', // 标记为文章类型
  166. source: '农业知识库'
  167. }
  168. ])
  169. // 政策解读列表
  170. const policyList = ref([
  171. {
  172. id: 1,
  173. title: '2024年农业补贴政策要点解读',
  174. description: '最新农业补贴政策要点解读,包括种粮补贴、农机补贴等各项补贴申请指南',
  175. viewCount: '2,341',
  176. date: '05-23',
  177. image: 'https://img.freepik.com/free-photo/modern-agricultural-machinery-field_1157-46386.jpg',
  178. type: '政策',
  179. contentType: 'article', // 标记为文章类型
  180. source: '农业部官方'
  181. },
  182. {
  183. id: 2,
  184. title: '农业保险政策专家解析视频',
  185. description: '农业保险覆盖范围扩大,新增多项保障内容,理赔流程优化',
  186. viewCount: '1,856',
  187. date: '05-22',
  188. image: 'https://img.freepik.com/free-photo/farmer-working-field_1157-46384.jpg',
  189. type: '政策',
  190. contentType: 'video', // 标记为视频类型
  191. duration: '28:45',
  192. source: '农业部政策宣讲'
  193. },
  194. {
  195. id: 3,
  196. title: '绿色种植认证办理指南',
  197. description: '绿色种植认证最新申请流程及注意事项说明',
  198. viewCount: '1,667',
  199. date: '05-21',
  200. image: 'https://img.freepik.com/free-photo/organic-farm-harvest_1157-46078.jpg',
  201. type: '政策',
  202. contentType: 'article', // 标记为文章类型
  203. source: '农业部认证中心'
  204. }
  205. ])
  206. // 刷新加载状态
  207. const isRefreshing = ref(false)
  208. // 处理Tab切换
  209. const handleTabChange = (index) => {
  210. currentTab.value = index
  211. console.log('Tab changed to:', index)
  212. }
  213. // 下拉刷新
  214. const onRefresh = async () => {
  215. isRefreshing.value = true
  216. try {
  217. await new Promise(resolve => setTimeout(resolve, 1000))
  218. // 模拟刷新数据
  219. if (currentTab.value === 0) {
  220. // 刷新农技知识数据
  221. console.log('刷新农技知识数据')
  222. } else {
  223. // 刷新政策解读数据
  224. console.log('刷新政策解读数据')
  225. }
  226. } finally {
  227. isRefreshing.value = false
  228. }
  229. }
  230. // 加载更多
  231. const loadMore = () => {
  232. console.log('Loading more content')
  233. // 模拟加载更多数据
  234. if (currentTab.value === 0) {
  235. // 加载更多农技知识数据
  236. console.log('加载更多农技知识数据')
  237. } else {
  238. // 加载更多政策解读数据
  239. console.log('加载更多政策解读数据')
  240. }
  241. }
  242. // 跳转AI问答
  243. const navigateToAI = () => {
  244. uni.navigateTo({
  245. url: '/pages/ai-chat/index'
  246. })
  247. }
  248. onMounted(() => {
  249. console.log('Page mounted, current tab:', currentTab.value)
  250. })
  251. </script>
  252. <style scoped>
  253. /* 引入字体图标 */
  254. @font-face {
  255. font-family: 'iconfont';
  256. src: url('//at.alicdn.com/t/font_3266846_kxscvlm9qpp.woff2') format('woff2');
  257. }
  258. .iconfont {
  259. font-family: "iconfont" !important;
  260. font-size: 22rpx;
  261. font-style: normal;
  262. -webkit-font-smoothing: antialiased;
  263. -moz-osx-font-smoothing: grayscale;
  264. }
  265. .icon-robot:before {
  266. content: "\e64b";
  267. }
  268. .icon-eye:before {
  269. content: "\e614";
  270. }
  271. /* 页面容器 */
  272. .page-container {
  273. min-height: 100vh;
  274. background-color: #f7f8fa;
  275. position: relative;
  276. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  277. }
  278. /* 头部标签样式 */
  279. .header-tabs {
  280. display: flex;
  281. background-color: #fff;
  282. padding: 0 30rpx;
  283. position: relative;
  284. border-bottom: 1rpx solid #f2f2f2;
  285. }
  286. .tab-item {
  287. position: relative;
  288. padding: 20rpx 30rpx;
  289. margin-right: 50rpx;
  290. font-size: 30rpx;
  291. color: #666;
  292. transition: all 0.3s ease;
  293. }
  294. .tab-item.active {
  295. color: #333;
  296. font-weight: 600;
  297. }
  298. .tab-line {
  299. position: absolute;
  300. bottom: 0;
  301. left: 50%;
  302. width: 0;
  303. height: 6rpx;
  304. background-color: #4dc971;
  305. border-radius: 3rpx;
  306. transition: all 0.3s ease;
  307. transform: translateX(-50%);
  308. }
  309. .tab-line.active {
  310. width: 40rpx;
  311. }
  312. /* 内容区域样式 */
  313. .content-container {
  314. height: calc(100vh - 88rpx);
  315. box-sizing: border-box;
  316. }
  317. .cards-section {
  318. padding: 12rpx;
  319. }
  320. /* 内容卡片通用样式 */
  321. .content-card {
  322. background-color: #fff;
  323. border-radius: 16rpx;
  324. margin-bottom: 24rpx;
  325. overflow: hidden;
  326. transition: all 0.2s ease;
  327. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  328. position: relative;
  329. }
  330. .card-hover {
  331. transform: translateY(-2rpx);
  332. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.12);
  333. }
  334. /* 缩略图 */
  335. .content-thumbnail {
  336. position: relative;
  337. width: 100%;
  338. height: 300rpx;
  339. background-color: #f0f0f0;
  340. }
  341. .thumbnail-image {
  342. width: 100%;
  343. height: 100%;
  344. object-fit: cover;
  345. }
  346. /* 播放按钮 */
  347. .play-button {
  348. position: absolute;
  349. top: 50%;
  350. left: 50%;
  351. transform: translate(-50%, -50%);
  352. width: 70rpx;
  353. height: 70rpx;
  354. background-color: rgba(0, 0, 0, 0.5);
  355. border-radius: 50%;
  356. display: flex;
  357. align-items: center;
  358. justify-content: center;
  359. z-index: 2;
  360. }
  361. .play-icon {
  362. width: 0;
  363. height: 0;
  364. border-style: solid;
  365. border-width: 9rpx 0 9rpx 16rpx;
  366. border-color: transparent transparent transparent #ffffff;
  367. margin-left: 4rpx;
  368. }
  369. /* 视频时长 */
  370. .video-duration {
  371. position: absolute;
  372. bottom: 10rpx;
  373. right: 10rpx;
  374. padding: 3rpx 8rpx;
  375. background-color: rgba(0, 0, 0, 0.6);
  376. color: #fff;
  377. font-size: 18rpx;
  378. border-radius: 10rpx;
  379. }
  380. /* 内容类型标签 */
  381. .content-type-tag {
  382. position: absolute;
  383. top: 10rpx;
  384. left: 10rpx;
  385. padding: 4rpx 10rpx;
  386. font-size: 20rpx;
  387. border-radius: 6rpx;
  388. z-index: 2;
  389. }
  390. .content-type-tag.video {
  391. background-color: #4dc971;
  392. color: #fff;
  393. }
  394. .content-type-tag.article {
  395. background-color: #3498db;
  396. color: #fff;
  397. }
  398. /* 内容信息 */
  399. .content-info {
  400. padding: 16rpx;
  401. position: relative;
  402. }
  403. .content-title {
  404. font-size: 30rpx;
  405. font-weight: 600;
  406. color: #333;
  407. line-height: 1.4;
  408. margin-bottom: 10rpx;
  409. display: -webkit-box;
  410. -webkit-box-orient: vertical;
  411. -webkit-line-clamp: 2;
  412. overflow: hidden;
  413. }
  414. .source-name {
  415. color: #999;
  416. font-size: 22rpx;
  417. }
  418. .info-row {
  419. display: flex;
  420. justify-content: space-between;
  421. align-items: center;
  422. }
  423. .view-count {
  424. color: #c0c0c0;
  425. font-size: 20rpx;
  426. display: flex;
  427. align-items: center;
  428. }
  429. .view-count .iconfont {
  430. margin-right: 4rpx;
  431. }
  432. /* 空状态 */
  433. .empty-state {
  434. display: flex;
  435. flex-direction: column;
  436. align-items: center;
  437. justify-content: center;
  438. padding: 120rpx 0;
  439. }
  440. .empty-image {
  441. width: 180rpx;
  442. height: 180rpx;
  443. margin-bottom: 16rpx;
  444. }
  445. .empty-text {
  446. font-size: 26rpx;
  447. color: #999;
  448. }
  449. /* AI按钮 */
  450. .assistant-btn {
  451. position: fixed;
  452. right: 30rpx;
  453. bottom: 100rpx;
  454. height: 80rpx;
  455. border-radius: 40rpx;
  456. background: linear-gradient(135deg, #42b983, #3db160);
  457. display: flex;
  458. align-items: center;
  459. padding: 0 24rpx;
  460. box-shadow: 0 6rpx 20rpx rgba(66, 185, 131, 0.35);
  461. z-index: 99;
  462. transition: all 0.25s ease;
  463. }
  464. .assistant-icon {
  465. width: 68rpx;
  466. height: 68rpx;
  467. margin-right: 10rpx;
  468. }
  469. .btn-hover {
  470. transform: scale(1.05);
  471. box-shadow: 0 8rpx 24rpx rgba(66, 185, 131, 0.45);
  472. }
  473. .btn-text {
  474. font-size: 28rpx;
  475. color: #fff;
  476. font-weight: 500;
  477. }
  478. </style>