index.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. <template>
  2. <view class="dashboard-container">
  3. <!-- 顶部 TopBar -->
  4. <view class="top-bar">
  5. <text class="greeting">农事有序,心里有数</text>
  6. <text class="top-sub-guide">从今天的田间环境开始</text>
  7. </view>
  8. <!-- 田间环境/天气区域 (降级为扁平状态块) -->
  9. <view class="environmental-status-block" @click="showWeatherDetail">
  10. <view class="status-main">
  11. <view class="main-info">
  12. <text class="main-text">{{ weatherData.infos.temperature }}° · {{ weatherData.infos.weather }}</text>
  13. <text class="fixed-subtitle">田间环境概览</text>
  14. </view>
  15. <view class="refresh-btn" :class="{ 'rotating': isLoadingWeather }" @click.stop="handleRefresh">
  16. <u-icon name="reload" :color="isLoadingWeather ? '#999' : '#3BB44A'" size="20"></u-icon>
  17. </view>
  18. </view>
  19. <view class="metrics-row">
  20. <view class="metric-item">
  21. <text class="label">湿度</text>
  22. <text class="value">{{ weatherData.infos.humidity }}%</text>
  23. </view>
  24. <view class="metric-item">
  25. <text class="label">风力</text>
  26. <text class="value">{{ weatherData.infos.wind_power_v2 }}</text>
  27. </view>
  28. <view class="metric-item">
  29. <text class="label">气压</text>
  30. <text class="value">{{ weatherData.infos.air_pressure }} hPa</text>
  31. </view>
  32. </view>
  33. <view class="update-time" v-if="weatherData.update_time">
  34. <text>更新时间:{{ weatherData.update_time }}</text>
  35. </view>
  36. </view>
  37. <!-- AI 主卡 -->
  38. <view class="card ai-card">
  39. <view class="ai-header">
  40. <view class="ai-pill">AI 农小禹</view>
  41. <text class="ai-subtitle">今天安排从这里开始</text>
  42. </view>
  43. <view class="ai-body">
  44. <text class="ai-title">{{ aiQuestion.title }}</text>
  45. <text class="ai-desc">问问 AI 农小禹,给你具体建议</text>
  46. </view>
  47. <view class="ai-footer">
  48. <view class="ai-cta">
  49. <u-button
  50. type="primary"
  51. color="#2F7D32"
  52. shape="round"
  53. :custom-style="{
  54. height: '60rpx',
  55. width: 'auto',
  56. minWidth: '200rpx',
  57. borderRadius: '30rpx',
  58. padding: '0 32rpx',
  59. fontSize: '28rpx',
  60. fontWeight: '600',
  61. margin: '0'
  62. }"
  63. @click="goToAI"
  64. >
  65. 立即提问
  66. <u-icon name="arrow-right" color="white" size="16" style="margin-left: 8rpx;"></u-icon>
  67. </u-button>
  68. </view>
  69. </view>
  70. <!-- 玻璃感噪点纹理 -->
  71. <view class="ai-texture"></view>
  72. </view>
  73. <!-- 农资精选 -->
  74. <view class="card">
  75. <view class="card-header">
  76. <view class="title-section">
  77. <view class="title-line"></view>
  78. <text class="card-title">农资精选</text>
  79. </view>
  80. <view class="more-btn" @click="goToMall">
  81. <text>去农资</text>
  82. <u-icon name="arrow-right" color="#3BB44A" size="14"></u-icon>
  83. </view>
  84. </view>
  85. <view class="products-grid">
  86. <view
  87. class="product-card"
  88. v-for="(product, index) in products"
  89. :key="index"
  90. @click="showProductDetail(product)"
  91. >
  92. <image
  93. :src="product.image"
  94. mode="aspectFill"
  95. class="product-image"
  96. lazy-load
  97. ></image>
  98. <view class="product-info">
  99. <text class="product-title">{{ product.title }}</text>
  100. <text class="product-desc">{{ product.desc }}</text>
  101. <view class="price-row">
  102. <text class="price">¥{{ product.price }}</text>
  103. <text class="unit">/{{ product.unit }}</text>
  104. </view>
  105. <u-button
  106. type="primary"
  107. color="linear-gradient(135deg, #3BB44A, #66CC6A)"
  108. size="mini"
  109. shape="round"
  110. >
  111. 了解更多
  112. </u-button>
  113. </view>
  114. </view>
  115. </view>
  116. </view>
  117. <!-- 农技推荐 -->
  118. <view class="card">
  119. <view class="card-header">
  120. <view class="title-section">
  121. <view class="title-line"></view>
  122. <text class="card-title">农技推荐</text>
  123. </view>
  124. <view class="more-btn" @click="goToKnowledge">
  125. <text>更多</text>
  126. <u-icon name="arrow-right" color="#3BB44A" size="14"></u-icon>
  127. </view>
  128. </view>
  129. <view class="articles-list">
  130. <view
  131. class="article-card"
  132. v-for="(article, index) in articles"
  133. :key="index"
  134. @click="showArticleDetail(article)"
  135. >
  136. <view class="article-image-wrapper">
  137. <image
  138. :src="article.image"
  139. mode="aspectFill"
  140. class="article-image"
  141. lazy-load
  142. ></image>
  143. <view class="article-tag">文章</view>
  144. </view>
  145. <view class="article-info">
  146. <text class="article-title">{{ article.title }}</text>
  147. <text class="article-source">{{ article.source }}</text>
  148. <view class="article-stats">
  149. <u-icon name="eye" color="#999" size="12"></u-icon>
  150. <text class="read-count">{{ article.readCount }}</text>
  151. </view>
  152. </view>
  153. </view>
  154. </view>
  155. </view>
  156. <!-- 天气详情弹窗 -->
  157. <!-- <u-popup
  158. :show="showWeatherPopup"
  159. mode="bottom"
  160. round="20"
  161. @close="showWeatherPopup = false"
  162. >
  163. <view class="popup-content">
  164. <view class="popup-header">
  165. <text class="popup-title">今日农事详情</text>
  166. <u-icon name="close" color="#999" size="20" @click="showWeatherPopup = false"></u-icon>
  167. </view>
  168. <view class="weather-detail">
  169. <view class="detail-item">
  170. <text class="detail-label">天气状况</text>
  171. <text class="detail-value">{{ weatherData.weatherText }}</text>
  172. </view>
  173. <view class="detail-item">
  174. <text class="detail-label">当前温度</text>
  175. <text class="detail-value">{{ weatherData.tempNow }}°C</text>
  176. </view>
  177. <view class="detail-item">
  178. <text class="detail-label">湿度</text>
  179. <text class="detail-value">{{ weatherData.humidity }}%</text>
  180. </view>
  181. <view class="detail-item">
  182. <text class="detail-label">风力</text>
  183. <text class="detail-value">{{ weatherData.windScale }}级</text>
  184. </view>
  185. <view class="detail-item">
  186. <text class="detail-label">降水量</text>
  187. <text class="detail-value">{{ weatherData.precipMm }}mm</text>
  188. </view>
  189. <view class="advice-detail">
  190. <text class="advice-label">今日建议:</text>
  191. <text class="advice-content">{{ weatherData.adviceText }}</text>
  192. </view>
  193. </view>
  194. <u-button
  195. type="primary"
  196. color="linear-gradient(135deg, #3BB44A, #66CC6A)"
  197. shape="round"
  198. @click="askAIAboutWeather"
  199. >
  200. 去问 AI
  201. </u-button>
  202. </view>
  203. </u-popup> -->
  204. <!-- 文章详情弹窗 -->
  205. <u-popup
  206. :show="showArticlePopup"
  207. mode="bottom"
  208. round="20"
  209. @close="showArticlePopup = false"
  210. >
  211. <view class="popup-content">
  212. <view class="popup-header">
  213. <text class="popup-title">文章详情</text>
  214. <u-icon name="close" color="#999" size="20" @click="showArticlePopup = false"></u-icon>
  215. </view>
  216. <view class="article-detail" v-if="currentArticle">
  217. <text class="article-detail-title">{{ currentArticle.title }}</text>
  218. <text class="article-detail-time">{{ currentArticle.time }}</text>
  219. <view class="article-detail-content">
  220. <text class="content-paragraph">{{ currentArticle.content }}</text>
  221. <text class="content-subtitle">主要要点:</text>
  222. <view class="content-list">
  223. <text class="list-item" v-for="(item, index) in currentArticle.points" :key="index">
  224. • {{ item }}
  225. </text>
  226. </view>
  227. </view>
  228. </view>
  229. <u-button
  230. type="primary"
  231. color="linear-gradient(135deg, #3BB44A, #66CC6A)"
  232. shape="round"
  233. @click="askAIAboutArticle"
  234. >
  235. 去问 AI
  236. </u-button>
  237. </view>
  238. </u-popup>
  239. </view>
  240. </template>
  241. <script setup>
  242. import { ref, reactive, onMounted } from 'vue'
  243. import { getWeatherInfo, getLocation } from '@/api/services/weather.js'
  244. import { getMallList } from '@/api/services/mall.js'
  245. import { getTopArticles } from '@/api/services/knowledge.js'
  246. // 天气数据
  247. const weatherData = reactive({
  248. infos: {
  249. weather: "加载中...",
  250. temperature: "--",
  251. humidity: "--",
  252. wind_power_v2: "--",
  253. air_pressure: "--"
  254. },
  255. update_time: "" // 更新时间
  256. })
  257. // 加载状态
  258. const isLoadingWeather = ref(false)
  259. const aiQuestions = [
  260. {
  261. title: '叶片发黄该从哪查?',
  262. recommend: '最近阴雨天多,管理要点?'
  263. },
  264. {
  265. title: '水稻分蘖期怎么管理?',
  266. recommend: '如何提高分蘖成穗率?'
  267. },
  268. {
  269. title: '玉米倒伏了怎么办?',
  270. recommend: '预防玉米倒伏的措施?'
  271. }
  272. ]
  273. const aiQuestion = ref(aiQuestions[0])
  274. // 商品列表数据
  275. const products = ref([])
  276. // 文章列表数据
  277. const articles = ref([])
  278. // 弹窗控制
  279. const showWeatherPopup = ref(false)
  280. const showArticlePopup = ref(false)
  281. const currentArticle = ref(null)
  282. // 方法
  283. const showTip = () => {
  284. uni.showToast({
  285. title: '建议先看今日农事,再去问 AI',
  286. icon: 'none',
  287. duration: 2000
  288. })
  289. }
  290. const showWeatherDetail = () => {
  291. showWeatherPopup.value = true
  292. }
  293. const showArticleDetail = (article) => {
  294. if (!article.id) {
  295. uni.showToast({
  296. title: '文章信息不完整',
  297. icon: 'none',
  298. duration: 2000
  299. })
  300. return;
  301. }
  302. // 跳转到农技详情页
  303. uni.navigateTo({
  304. url: `/pages/knowledge/detail?id=${article.id}`
  305. })
  306. }
  307. const showProductDetail = (product) => {
  308. if (!product.id) {
  309. uni.showToast({
  310. title: '商品信息不完整',
  311. icon: 'none',
  312. duration: 2000
  313. })
  314. return;
  315. }
  316. // 跳转到农资详情页
  317. uni.navigateTo({
  318. url: `/pages/service/mall-detail?id=${product.id}`
  319. })
  320. }
  321. const goToAI = () => {
  322. uni.switchTab({
  323. url: '/pages/knowledge/ai-chat/index'
  324. });
  325. }
  326. const goToMall = () => {
  327. uni.switchTab({
  328. url: '/pages/service/mall'
  329. })
  330. }
  331. const goToKnowledge = () => {
  332. uni.switchTab({
  333. url: '/pages/knowledge/index'
  334. })
  335. }
  336. const askAIAboutWeather = () => {
  337. showWeatherPopup.value = false
  338. uni.navigateTo({
  339. url: '/pages/knowledge/ai-chat/index?question=' + encodeURIComponent('今日天气适宜哪些农事活动?')
  340. })
  341. }
  342. const askAIAboutArticle = () => {
  343. showArticlePopup.value = false
  344. if (currentArticle.value) {
  345. uni.navigateTo({
  346. url: '/pages/knowledge/ai-chat/index?question=' + encodeURIComponent('关于' + currentArticle.value.title + '有什么建议?')
  347. })
  348. }
  349. }
  350. const handleRefresh = () => {
  351. if (isLoadingWeather.value) {
  352. uni.showToast({
  353. title: '正在刷新中...',
  354. icon: 'none',
  355. duration: 1500
  356. });
  357. return;
  358. }
  359. fetchWeatherData(true);
  360. }
  361. /**
  362. * 获取实时天气数据
  363. */
  364. const fetchWeatherData = async (showToast = false) => {
  365. if (isLoadingWeather.value) {
  366. return;
  367. }
  368. // 如果是手动刷新,显示提示
  369. if (showToast) {
  370. uni.showToast({
  371. title: '正在刷新天气...',
  372. icon: 'loading',
  373. duration: 2000
  374. });
  375. }
  376. isLoadingWeather.value = true;
  377. try {
  378. // 1. 获取当前位置
  379. const location = await getLocation();
  380. console.log('获取到位置信息:', location);
  381. // 2. 根据位置查询天气
  382. const weatherResult = await getWeatherInfo({
  383. latitude: location.latitude,
  384. longitude: location.longitude,
  385. type: 'now', // 查询实时天气
  386. added_fields: 'air' // 附加空气质量信息
  387. });
  388. console.log('天气查询结果:', weatherResult);
  389. // 3. 更新天气数据
  390. if (weatherResult && weatherResult.result && weatherResult.result.realtime) {
  391. const realtime = weatherResult.result.realtime;
  392. const infos = realtime[0].infos || {};
  393. weatherData.infos = {
  394. weather: infos.weather || '未知',
  395. temperature: infos.temperature !== undefined ? infos.temperature : '--',
  396. humidity: infos.humidity !== undefined ? infos.humidity : '--',
  397. wind_power_v2: infos.wind_power_v2 || '--',
  398. air_pressure: infos.air_pressure !== undefined ? infos.air_pressure : '--'
  399. };
  400. // 更新时间
  401. weatherData.update_time = realtime.update_time || '';
  402. console.log('天气数据更新成功:', weatherData);
  403. // 刷新成功提示
  404. if (showToast) {
  405. uni.showToast({
  406. title: '刷新成功',
  407. icon: 'success',
  408. duration: 1500
  409. });
  410. }
  411. }
  412. } catch (error) {
  413. console.error('获取天气失败:', error);
  414. uni.showToast({
  415. title: `${error}`,
  416. icon: 'none',
  417. duration: 2000
  418. })
  419. // 错误处理
  420. let errorMsg = '获取天气失败';
  421. if (error.errMsg) {
  422. if (error.errMsg.includes('auth deny')) {
  423. errorMsg = '定位权限被拒绝,请在设置中开启定位权限';
  424. } else if (error.errMsg.includes('timeout')) {
  425. errorMsg = '定位超时,请检查网络连接';
  426. }
  427. } else if (error.message) {
  428. errorMsg = error.message;
  429. }
  430. uni.showToast({
  431. title: errorMsg,
  432. icon: 'none',
  433. duration: 2000
  434. });
  435. // 设置默认值
  436. weatherData.infos = {
  437. weather: "暂无数据",
  438. temperature: "--",
  439. humidity: "--",
  440. wind_power_v2: "--",
  441. air_pressure: "--"
  442. };
  443. } finally {
  444. isLoadingWeather.value = false;
  445. }
  446. }
  447. /**
  448. * 获取第一张图片地址
  449. * @param {string} swiperImages - 图片地址字符串,可能包含多个用逗号分隔的地址
  450. * @returns {string} - 返回第一张图片地址
  451. */
  452. const getFirstImage = (swiperImages) => {
  453. if (!swiperImages) {
  454. return '/static/images/products/agriculture-tools.jpg';
  455. }
  456. // 如果包含逗号,说明有多张图片,取第一张
  457. if (swiperImages.includes(',')) {
  458. return swiperImages.split(',')[0].trim();
  459. }
  460. // 否则直接返回
  461. return swiperImages;
  462. }
  463. /**
  464. * 格式化阅读量显示
  465. * @param {number} count - 阅读量数字
  466. * @returns {string} - 格式化后的阅读量(如:1.2k)
  467. */
  468. const formatReadCount = (count) => {
  469. if (!count || count === 0) return '0';
  470. if (count >= 1000) {
  471. return (count / 1000).toFixed(1) + 'k';
  472. }
  473. return count.toString();
  474. }
  475. /**
  476. * 获取推荐商品列表
  477. */
  478. const fetchRecommendedProducts = async () => {
  479. try {
  480. const result = await getMallList({
  481. isRecommended: 1, // 查询推荐商品
  482. pageNum: 1,
  483. pageSize: 4 // 只获取4个推荐商品
  484. });
  485. console.log('推荐商品查询结果:', result);
  486. if (result.data && result.data.rows && result.data.rows.length > 0) {
  487. // 映射后端数据到前端展示格式
  488. products.value = result.data.rows.map(item => ({
  489. id: item.id,
  490. title: item.name || item.title || '商品名称',
  491. desc: item.description || item.desc || '暂无描述',
  492. price: item.price || '0',
  493. unit: item.unit || '件',
  494. image: getFirstImage(item.swiperImages)
  495. }));
  496. console.log('推荐商品数据更新成功:', products.value);
  497. } else {
  498. // 如果没有推荐商品,使用默认数据
  499. console.log('暂无推荐商品,使用默认数据');
  500. products.value = [
  501. {
  502. title: '优质玉米种子',
  503. desc: '高产抗病品种',
  504. price: '68',
  505. unit: '袋',
  506. image: '/static/images/products/corn-seeds-new.jpg'
  507. },
  508. {
  509. title: '有机肥料',
  510. desc: '纯天然环保',
  511. price: '128',
  512. unit: '袋',
  513. image: '/static/images/products/organic-fertilizer-new.jpg'
  514. },
  515. {
  516. title: '杀虫剂',
  517. desc: '广谱高效',
  518. price: '45',
  519. unit: '瓶',
  520. image: '/static/images/products/insecticide.jpg'
  521. },
  522. {
  523. title: '农用地膜',
  524. desc: '保湿保温',
  525. price: '89',
  526. unit: '卷',
  527. image: '/static/images/products/plastic-film.jpg'
  528. }
  529. ];
  530. }
  531. } catch (error) {
  532. console.error('获取推荐商品失败:', error);
  533. // 失败时使用默认数据
  534. products.value = [
  535. {
  536. title: '优质玉米种子',
  537. desc: '高产抗病品种',
  538. price: '68',
  539. unit: '袋',
  540. image: '/static/images/products/corn-seeds-new.jpg'
  541. },
  542. {
  543. title: '有机肥料',
  544. desc: '纯天然环保',
  545. price: '128',
  546. unit: '袋',
  547. image: '/static/images/products/organic-fertilizer-new.jpg'
  548. },
  549. {
  550. title: '杀虫剂',
  551. desc: '广谱高效',
  552. price: '45',
  553. unit: '瓶',
  554. image: '/static/images/products/insecticide.jpg'
  555. },
  556. {
  557. title: '农用地膜',
  558. desc: '保湿保温',
  559. price: '89',
  560. unit: '卷',
  561. image: '/static/images/products/plastic-film.jpg'
  562. }
  563. ];
  564. }
  565. }
  566. /**
  567. * 获取热门文章列表(根据阅读量)
  568. */
  569. const fetchTopArticles = async () => {
  570. try {
  571. const result = await getTopArticles();
  572. console.log('热门文章查询结果:', result);
  573. if (result.data && result.data.length > 0) {
  574. // 映射后端数据到前端展示格式
  575. articles.value = result.data.slice(0, 4).map(item => ({
  576. id: item.id,
  577. title: item.title || '文章标题',
  578. source: item.category || item.source || '农技知识',
  579. readCount: formatReadCount(item.viewCount || item.readCount || 0),
  580. image: getFirstImage(item.imageUrl) || '/static/images/rice-farming/rice-field1.jpg',
  581. time: item.createTime || item.publishTime || '',
  582. content: item.content || item.summary || '暂无内容',
  583. points: [] // 后端如果有要点字段可以映射
  584. }));
  585. console.log('热门文章数据更新成功:', articles.value);
  586. } else {
  587. // 如果没有热门文章,使用默认数据
  588. console.log('暂无热门文章,使用默认数据');
  589. articles.value = [
  590. {
  591. title: '春季水稻种植技术要点',
  592. source: '农技知识',
  593. readCount: '1.2k',
  594. image: '/static/images/rice-farming/rice-field1.jpg',
  595. time: '2024-03-15',
  596. content: '春季是水稻种植的关键时期,需要掌握以下技术要点。',
  597. points: []
  598. },
  599. {
  600. title: '玉米病虫害防治指南',
  601. source: '植保技术',
  602. readCount: '856',
  603. image: '/static/images/rice-farming/rice-field2.jpg',
  604. time: '2024-03-14',
  605. content: '玉米病虫害防治是确保产量的重要环节。',
  606. points: []
  607. },
  608. {
  609. title: '现代农业机械化作业规范',
  610. source: '农机管理',
  611. readCount: '2.1k',
  612. image: '/static/images/rice-farming/rice-field3.jpg',
  613. time: '2024-03-13',
  614. content: '提升农业机械化作业水平是现代农业发展的必然要求。',
  615. points: []
  616. },
  617. {
  618. title: '土壤肥力提升与改良方案',
  619. source: '土肥管理',
  620. readCount: '1.5k',
  621. image: '/static/images/rice-farming/rice-field4.jpg',
  622. time: '2024-03-12',
  623. content: '健康的土壤是丰收的基础。',
  624. points: []
  625. }
  626. ];
  627. }
  628. } catch (error) {
  629. console.error('获取热门文章失败:', error);
  630. // 失败时使用默认数据
  631. articles.value = [
  632. {
  633. title: '春季水稻种植技术要点',
  634. source: '农技知识',
  635. readCount: '1.2k',
  636. image: '/static/images/rice-farming/rice-field1.jpg',
  637. time: '2024-03-15',
  638. content: '春季是水稻种植的关键时期,需要掌握以下技术要点。',
  639. points: []
  640. },
  641. {
  642. title: '玉米病虫害防治指南',
  643. source: '植保技术',
  644. readCount: '856',
  645. image: '/static/images/rice-farming/rice-field2.jpg',
  646. time: '2024-03-14',
  647. content: '玉米病虫害防治是确保产量的重要环节。',
  648. points: []
  649. },
  650. {
  651. title: '现代农业机械化作业规范',
  652. source: '农机管理',
  653. readCount: '2.1k',
  654. image: '/static/images/rice-farming/rice-field3.jpg',
  655. time: '2024-03-13',
  656. content: '提升农业机械化作业水平是现代农业发展的必然要求。',
  657. points: []
  658. },
  659. {
  660. title: '土壤肥力提升与改良方案',
  661. source: '土肥管理',
  662. readCount: '1.5k',
  663. image: '/static/images/rice-farming/rice-field4.jpg',
  664. time: '2024-03-12',
  665. content: '健康的土壤是丰收的基础。',
  666. points: []
  667. }
  668. ];
  669. }
  670. }
  671. // 页面加载时获取天气、推荐商品和热门文章
  672. onMounted(() => {
  673. fetchWeatherData();
  674. fetchRecommendedProducts();
  675. fetchTopArticles();
  676. })
  677. </script>
  678. <style lang="scss" scoped>
  679. .dashboard-container {
  680. padding: 24rpx;
  681. background-color: #F6FDF9;
  682. min-height: 100vh;
  683. }
  684. // 顶部 TopBar
  685. .top-bar {
  686. display: flex;
  687. flex-direction: column;
  688. justify-content: flex-start;
  689. align-items: flex-start;
  690. margin-bottom: 12rpx;
  691. padding: 0 8rpx;
  692. .greeting {
  693. font-size: 32rpx;
  694. font-weight: 600;
  695. color: #1A3026;
  696. letter-spacing: 1rpx;
  697. line-height: 1.4;
  698. }
  699. .top-sub-guide {
  700. font-size: 24rpx;
  701. color: rgba(0, 0, 0, 0.45);
  702. margin-top: 4rpx;
  703. }
  704. }
  705. // Card 基础样式(复用旧首页)
  706. .card {
  707. background: white;
  708. border-radius: 20rpx;
  709. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.04), 0 1rpx 4rpx rgba(0, 0, 0, 0.02);
  710. margin-bottom: 24rpx;
  711. overflow: hidden;
  712. .card-header {
  713. display: flex;
  714. justify-content: space-between;
  715. align-items: center;
  716. padding: 24rpx 28rpx;
  717. border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  718. .title-section {
  719. display: flex;
  720. align-items: center;
  721. .title-line {
  722. width: 4rpx;
  723. height: 28rpx;
  724. border-radius: 0;
  725. background: linear-gradient(180deg, #3BB44A, #66CC6A);
  726. margin-right: 16rpx;
  727. }
  728. .card-title {
  729. font-size: 28rpx;
  730. font-weight: 600;
  731. color: #2C3E50;
  732. }
  733. }
  734. .tag {
  735. background: linear-gradient(135deg, #3BB44A, #66CC6A);
  736. color: white;
  737. font-size: 22rpx;
  738. padding: 6rpx 16rpx;
  739. border-radius: 16rpx;
  740. }
  741. .more-btn {
  742. display: flex;
  743. align-items: center;
  744. color: #3BB44A;
  745. font-size: 24rpx;
  746. text {
  747. margin-right: 6rpx;
  748. }
  749. }
  750. }
  751. }
  752. // 田间环境状态块 (降级为扁平化背景块)
  753. .environmental-status-block {
  754. position: relative;
  755. padding: 24rpx 28rpx;
  756. background: linear-gradient(135deg, #FFFFFF 0%, #F4FAF7 100%);
  757. border: 1rpx solid rgba(59, 180, 74, 0.08);
  758. border-radius: 24rpx;
  759. margin-bottom: 24rpx;
  760. overflow: hidden;
  761. .status-main {
  762. display: flex;
  763. justify-content: space-between;
  764. // align-items: flex-end;
  765. margin-bottom: 20rpx;
  766. .main-info {
  767. display: flex;
  768. flex-direction: column;
  769. .main-text {
  770. font-size: 48rpx;
  771. font-weight: 800;
  772. color: #1A3026;
  773. line-height: 1;
  774. }
  775. .fixed-subtitle {
  776. font-size: 24rpx;
  777. color: #7A9086;
  778. margin-top: 8rpx;
  779. }
  780. }
  781. .refresh-btn {
  782. display: flex;
  783. align-items: center;
  784. justify-content: center;
  785. width: 60rpx;
  786. height: 60rpx;
  787. border-radius: 50%;
  788. background: rgba(59, 180, 74, 0.08);
  789. transition: all 0.3s ease;
  790. &:active {
  791. background: rgba(59, 180, 74, 0.15);
  792. transform: scale(0.95);
  793. }
  794. &.rotating {
  795. animation: rotate 1s linear infinite;
  796. }
  797. }
  798. }
  799. @keyframes rotate {
  800. from {
  801. transform: rotate(0deg);
  802. }
  803. to {
  804. transform: rotate(360deg);
  805. }
  806. }
  807. .metrics-row {
  808. display: flex;
  809. justify-content: space-between;
  810. align-items: center;
  811. padding-top: 16rpx;
  812. border-top: 1rpx solid rgba(0, 0, 0, 0.03);
  813. .metric-item {
  814. flex: 1;
  815. display: flex;
  816. align-items: center;
  817. gap: 8rpx;
  818. .label {
  819. font-size: 22rpx;
  820. color: #8EAC9D;
  821. }
  822. .value {
  823. font-size: 24rpx;
  824. font-weight: 600;
  825. color: #2D4035;
  826. }
  827. }
  828. }
  829. .update-time {
  830. margin-top: 12rpx;
  831. text-align: right;
  832. text {
  833. font-size: 20rpx;
  834. color: #999;
  835. }
  836. }
  837. }
  838. // AI 主卡
  839. .ai-card {
  840. position: relative;
  841. background: linear-gradient(135deg, rgba(59, 180, 74, 0.18), rgba(102, 204, 106, 0.10));
  842. border: 1rpx solid rgba(59, 180, 74, 0.08);
  843. border-radius: 20rpx;
  844. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.04), 0 1rpx 4rpx rgba(0, 0, 0, 0.02);
  845. margin-bottom: 24rpx;
  846. overflow: hidden;
  847. transition: transform 0.2s ease, box-shadow 0.2s ease;
  848. &:active {
  849. transform: scale(0.99);
  850. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.03);
  851. }
  852. // 多层背景光斑效果 (底层氛围)
  853. &::before {
  854. content: '';
  855. position: absolute;
  856. top: 0;
  857. left: 0;
  858. right: 0;
  859. bottom: 0;
  860. background:
  861. radial-gradient(circle at 85% 25%, rgba(59, 180, 74, 0.22), transparent 60%),
  862. radial-gradient(circle at 20% 80%, rgba(76, 175, 80, 0.14), transparent 55%);
  863. pointer-events: none;
  864. z-index: 1;
  865. }
  866. // 抽象 AI 设计母题层 (右侧增强设计感)
  867. &::after {
  868. content: '';
  869. position: absolute;
  870. top: -20%;
  871. right: -10%;
  872. width: 80%;
  873. height: 140%;
  874. background:
  875. radial-gradient(circle at 75% 35%, rgba(59, 180, 74, 0.06) 0%, transparent 45%),
  876. radial-gradient(circle at 85% 65%, rgba(76, 175, 80, 0.04) 0%, transparent 40%),
  877. radial-gradient(circle at 60% 85%, rgba(59, 180, 74, 0.03) 0%, transparent 50%);
  878. filter: blur(30rpx);
  879. pointer-events: none;
  880. z-index: 2;
  881. }
  882. .ai-texture {
  883. position: absolute;
  884. top: 0;
  885. left: 0;
  886. right: 0;
  887. bottom: 0;
  888. background: repeating-linear-gradient(
  889. 45deg,
  890. transparent,
  891. transparent 2rpx,
  892. rgba(255, 255, 255, 0.03) 2rpx,
  893. rgba(255, 255, 255, 0.03) 4rpx
  894. );
  895. pointer-events: none;
  896. z-index: 2;
  897. opacity: 0.5;
  898. }
  899. .ai-header {
  900. position: relative;
  901. z-index: 3;
  902. display: flex;
  903. flex-direction: row;
  904. align-items: center;
  905. padding: 32rpx 28rpx 16rpx;
  906. .ai-pill {
  907. background: #FFFFFF;
  908. color: #3BB44A;
  909. font-size: 24rpx;
  910. font-weight: 600;
  911. padding: 8rpx 24rpx;
  912. border-radius: 40rpx;
  913. margin-right: 20rpx;
  914. margin-bottom: 0;
  915. }
  916. .ai-subtitle {
  917. font-size: 28rpx;
  918. color: #5C6A70;
  919. font-weight: 500;
  920. }
  921. }
  922. .ai-body {
  923. position: relative;
  924. z-index: 3;
  925. padding: 12rpx 28rpx 20rpx;
  926. .ai-title {
  927. font-size: 40rpx;
  928. font-weight: 700;
  929. color: #2C3E50;
  930. line-height: 1.3;
  931. margin-bottom: 12rpx;
  932. display: block;
  933. }
  934. .ai-desc {
  935. font-size: 26rpx;
  936. color: rgba(44, 62, 80, 0.6);
  937. line-height: 1.4;
  938. display: block;
  939. }
  940. }
  941. .ai-footer {
  942. position: relative;
  943. z-index: 3;
  944. display: flex;
  945. justify-content: flex-start;
  946. padding: 16rpx 28rpx 24rpx;
  947. .ai-cta {
  948. display: flex;
  949. align-items: center;
  950. }
  951. }
  952. }
  953. // 农资精选
  954. .products-grid {
  955. display: grid;
  956. grid-template-columns: repeat(2, 1fr);
  957. gap: 16rpx;
  958. padding: 16rpx;
  959. .product-card {
  960. background: white;
  961. border-radius: 16rpx;
  962. overflow: hidden;
  963. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.03);
  964. border: 1px solid rgba(0, 0, 0, 0.02);
  965. .product-image {
  966. width: 100%;
  967. height: 160rpx;
  968. background: #f5f5f5;
  969. }
  970. .product-info {
  971. padding: 16rpx;
  972. .product-title {
  973. font-size: 26rpx;
  974. font-weight: 600;
  975. color: #2C3E50;
  976. margin-bottom: 6rpx;
  977. overflow: hidden;
  978. text-overflow: ellipsis;
  979. white-space: nowrap;
  980. }
  981. .product-desc {
  982. font-size: 22rpx;
  983. color: #8C9396;
  984. margin-bottom: 12rpx;
  985. overflow: hidden;
  986. text-overflow: ellipsis;
  987. white-space: nowrap;
  988. }
  989. .price-row {
  990. display: flex;
  991. align-items: baseline;
  992. margin-bottom: 12rpx;
  993. .price {
  994. font-size: 32rpx;
  995. font-weight: 700;
  996. color: #3BB44A;
  997. }
  998. .unit {
  999. font-size: 22rpx;
  1000. color: #8C9396;
  1001. margin-left: 4rpx;
  1002. }
  1003. }
  1004. }
  1005. }
  1006. }
  1007. // 农技推荐
  1008. .articles-list {
  1009. padding: 16rpx;
  1010. .article-card {
  1011. display: flex;
  1012. background: white;
  1013. border-radius: 16rpx;
  1014. overflow: hidden;
  1015. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.03);
  1016. border: 1px solid rgba(0, 0, 0, 0.02);
  1017. margin-bottom: 16rpx;
  1018. .article-image-wrapper {
  1019. position: relative;
  1020. width: 200rpx;
  1021. height: 140rpx;
  1022. flex-shrink: 0;
  1023. .article-image {
  1024. width: 100%;
  1025. height: 100%;
  1026. background: #f5f5f5;
  1027. }
  1028. .article-tag {
  1029. position: absolute;
  1030. top: 8rpx;
  1031. left: 8rpx;
  1032. background: #2196F3;
  1033. color: white;
  1034. font-size: 20rpx;
  1035. padding: 4rpx 8rpx;
  1036. border-radius: 6rpx;
  1037. }
  1038. }
  1039. .article-info {
  1040. flex: 1;
  1041. padding: 16rpx;
  1042. display: flex;
  1043. flex-direction: column;
  1044. justify-content: space-between;
  1045. .article-title {
  1046. font-size: 26rpx;
  1047. font-weight: 600;
  1048. color: #2C3E50;
  1049. margin-bottom: 6rpx;
  1050. overflow: hidden;
  1051. text-overflow: ellipsis;
  1052. display: -webkit-box;
  1053. -webkit-line-clamp: 2;
  1054. -webkit-box-orient: vertical;
  1055. }
  1056. .article-source {
  1057. font-size: 22rpx;
  1058. color: #8C9396;
  1059. margin-bottom: 8rpx;
  1060. }
  1061. .article-stats {
  1062. display: flex;
  1063. align-items: center;
  1064. .read-count {
  1065. font-size: 22rpx;
  1066. color: #999;
  1067. margin-left: 6rpx;
  1068. }
  1069. }
  1070. }
  1071. }
  1072. }
  1073. // 弹窗样式
  1074. .popup-content {
  1075. padding: 32rpx;
  1076. max-height: 80vh;
  1077. overflow-y: auto;
  1078. .popup-header {
  1079. display: flex;
  1080. justify-content: space-between;
  1081. align-items: center;
  1082. margin-bottom: 24rpx;
  1083. .popup-title {
  1084. font-size: 32rpx;
  1085. font-weight: 600;
  1086. color: #2C3E50;
  1087. }
  1088. }
  1089. .weather-detail {
  1090. margin-bottom: 32rpx;
  1091. .detail-item {
  1092. display: flex;
  1093. justify-content: space-between;
  1094. align-items: center;
  1095. padding: 16rpx 0;
  1096. border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  1097. .detail-label {
  1098. font-size: 26rpx;
  1099. color: #8C9396;
  1100. }
  1101. .detail-value {
  1102. font-size: 26rpx;
  1103. font-weight: 600;
  1104. color: #2C3E50;
  1105. }
  1106. }
  1107. .advice-detail {
  1108. margin-top: 24rpx;
  1109. padding: 20rpx;
  1110. background: rgba(59, 180, 74, 0.05);
  1111. border-radius: 16rpx;
  1112. .advice-label {
  1113. font-size: 26rpx;
  1114. font-weight: 600;
  1115. color: #2C3E50;
  1116. margin-bottom: 8rpx;
  1117. }
  1118. .advice-content {
  1119. font-size: 26rpx;
  1120. color: #2C3E50;
  1121. line-height: 1.4;
  1122. }
  1123. }
  1124. }
  1125. .article-detail {
  1126. margin-bottom: 32rpx;
  1127. .article-detail-title {
  1128. font-size: 32rpx;
  1129. font-weight: 700;
  1130. color: #2C3E50;
  1131. margin-bottom: 12rpx;
  1132. }
  1133. .article-detail-time {
  1134. font-size: 22rpx;
  1135. color: #8C9396;
  1136. margin-bottom: 24rpx;
  1137. }
  1138. .article-detail-content {
  1139. .content-paragraph {
  1140. font-size: 26rpx;
  1141. color: #2C3E50;
  1142. line-height: 1.6;
  1143. margin-bottom: 20rpx;
  1144. }
  1145. .content-subtitle {
  1146. font-size: 28rpx;
  1147. font-weight: 600;
  1148. color: #2C3E50;
  1149. margin-bottom: 12rpx;
  1150. }
  1151. .content-list {
  1152. .list-item {
  1153. font-size: 26rpx;
  1154. color: #2C3E50;
  1155. line-height: 1.5;
  1156. margin-bottom: 8rpx;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. }
  1162. // 旋转动画
  1163. @keyframes rotate {
  1164. from {
  1165. transform: rotate(0deg);
  1166. }
  1167. to {
  1168. transform: rotate(360deg);
  1169. }
  1170. }
  1171. </style>