index.vue 33 KB

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