detail-collector.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. <template>
  2. <view class="container">
  3. <!-- 设备头部信息区域 -->
  4. <view class="device-header">
  5. <view class="device-info-row">
  6. <view class="device-name-container">
  7. <text class="device-name">{{ deviceInfo.name }}</text>
  8. <view
  9. class="status-tag"
  10. :class="deviceInfo.status === 1 ? 'status-online' : 'status-offline'"
  11. >
  12. <view class="status-dot" :class="{'offline-dot': deviceInfo.status === 1}"></view>
  13. {{ deviceInfo.status === 1 ? '在线' : '离线' }}
  14. </view>
  15. </view>
  16. <view class="refresh-btn" :class="{'refreshing': isRefreshing}" @tap="refreshData">
  17. <image src="/static/icons/refresh_icon.png" mode="aspectFit" style="width: 22px; height: 22px;"></image>
  18. </view>
  19. </view>
  20. <view class="device-meta-row">
  21. <view class="device-meta-item">
  22. <view class="meta-icon">
  23. <image src="/static/icons/device_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
  24. </view>
  25. <text class="meta-label">设备编号:</text>
  26. <text class="meta-value">{{ deviceInfo.deviceId }}</text>
  27. </view>
  28. <view class="device-meta-item">
  29. <view class="meta-icon">
  30. <image src="/static/icons/location_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
  31. </view>
  32. <text class="meta-label">安装位置:</text>
  33. <text class="meta-value">{{ deviceInfo.location }}</text>
  34. </view>
  35. <view class="device-meta-item">
  36. <view class="meta-icon">
  37. <image src="/static/icons/clock_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
  38. </view>
  39. <text class="meta-label">最近更新:</text>
  40. <text class="meta-value">{{ formatDate(deviceInfo.lastUpdate) }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 采集数据展示区域 - 气象站 -->
  45. <view class="data-section" v-if="deviceInfo.deviceTypeId === '4'">
  46. <view class="section-title data-title">
  47. <text>气象数据</text>
  48. </view>
  49. <view class="data-grid">
  50. <!-- 气温 -->
  51. <view class="data-item" hover-class="data-item-hover">
  52. <text class="data-label">气温</text>
  53. <view class="data-value-container">
  54. <template v-if="weatherData.temperature">
  55. <text class="data-value" :class="{
  56. 'updated': updatedFields.weather && updatedFields.weather.temperature,
  57. 'value-warning': parseFloat(weatherData.temperature) > 35 || parseFloat(weatherData.temperature) < 5
  58. }">{{ weatherData.temperature }}</text>
  59. <text class="data-unit">℃</text>
  60. </template>
  61. <text v-else class="data-value no-data">暂无数据</text>
  62. </view>
  63. <text class="data-time" v-if="weatherData.temperature">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
  64. </view>
  65. <!-- 湿度 -->
  66. <view class="data-item" hover-class="data-item-hover">
  67. <text class="data-label">湿度</text>
  68. <view class="data-value-container">
  69. <template v-if="weatherData.humidity">
  70. <text class="data-value" :class="{
  71. 'updated': updatedFields.weather && updatedFields.weather.humidity,
  72. 'value-warning': parseFloat(weatherData.humidity) > 85
  73. }">{{ weatherData.humidity }}</text>
  74. <text class="data-unit">%</text>
  75. </template>
  76. <text v-else class="data-value no-data">暂无数据</text>
  77. </view>
  78. <text class="data-time" v-if="weatherData.humidity">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
  79. </view>
  80. <!-- 降雨量 -->
  81. <view class="data-item" hover-class="data-item-hover">
  82. <text class="data-label">降雨量</text>
  83. <view class="data-value-container">
  84. <template v-if="weatherData.rainfall">
  85. <text class="data-value" :class="{
  86. 'updated': updatedFields.weather && updatedFields.weather.rainfall,
  87. 'value-alert': parseFloat(weatherData.rainfall) > 10
  88. }">{{ weatherData.rainfall }}</text>
  89. <text class="data-unit">mm</text>
  90. </template>
  91. <text v-else class="data-value no-data">暂无数据</text>
  92. </view>
  93. <text class="data-time" v-if="weatherData.rainfall">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
  94. </view>
  95. <!-- 风向 -->
  96. <view class="data-item" hover-class="data-item-hover">
  97. <text class="data-label">风向</text>
  98. <view class="data-value-container">
  99. <template v-if="weatherData.windDirection">
  100. <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.windDirection}">{{ weatherData.windDirection }}</text>
  101. <text class="data-unit"></text>
  102. </template>
  103. <text v-else class="data-value no-data">暂无数据</text>
  104. </view>
  105. <text class="data-time" v-if="weatherData.windDirection">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
  106. </view>
  107. <!-- 风速 -->
  108. <view class="data-item" hover-class="data-item-hover">
  109. <text class="data-label">风速</text>
  110. <view class="data-value-container">
  111. <template v-if="weatherData.windSpeed">
  112. <text class="data-value" :class="{
  113. 'updated': updatedFields.weather && updatedFields.weather.windSpeed,
  114. 'value-alert': parseFloat(weatherData.windSpeed) > 8,
  115. 'value-warning': parseFloat(weatherData.windSpeed) > 5 && parseFloat(weatherData.windSpeed) <= 8
  116. }">{{ weatherData.windSpeed }}</text>
  117. <text class="data-unit">m/s</text>
  118. </template>
  119. <text v-else class="data-value no-data">暂无数据</text>
  120. </view>
  121. <text class="data-time" v-if="weatherData.windSpeed">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
  122. </view>
  123. <!-- 气压 -->
  124. <view class="data-item" hover-class="data-item-hover">
  125. <text class="data-label">气压</text>
  126. <view class="data-value-container">
  127. <template v-if="weatherData.pressure">
  128. <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.pressure}">{{ weatherData.pressure }}</text>
  129. <text class="data-unit">hPa</text>
  130. </template>
  131. <text v-else class="data-value no-data">暂无数据</text>
  132. </view>
  133. <text class="data-time" v-if="weatherData.pressure">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
  134. </view>
  135. <!-- 光照 -->
  136. <view class="data-item" hover-class="data-item-hover">
  137. <text class="data-label">光照</text>
  138. <view class="data-value-container">
  139. <template v-if="weatherData.illumination">
  140. <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.illumination}">{{ weatherData.illumination }}</text>
  141. <text class="data-unit">lux</text>
  142. </template>
  143. <text v-else class="data-value no-data">暂无数据</text>
  144. </view>
  145. <text class="data-time" v-if="weatherData.illumination">{{ formatDate(weatherData.updateTime) || '未知' }}</text>
  146. </view>
  147. </view>
  148. </view>
  149. <!-- 采集数据展示区域 - 土壤墒情 -->
  150. <view class="data-section" v-if="deviceInfo.deviceTypeId === '1'">
  151. <view class="section-title soil-title">
  152. <text>土壤数据</text>
  153. </view>
  154. <view class="data-grid">
  155. <!-- 土壤温度 -->
  156. <view class="data-item" hover-class="data-item-hover">
  157. <text class="data-label">土壤温度</text>
  158. <view class="data-value-container">
  159. <template v-if="soilData.temperature">
  160. <text class="data-value" :class="{
  161. 'updated': updatedFields.soil && updatedFields.soil.temperature,
  162. 'value-warning': parseFloat(soilData.temperature) > 30 || parseFloat(soilData.temperature) < 5
  163. }">{{ soilData.temperature }}</text>
  164. <text class="data-unit">℃</text>
  165. </template>
  166. <text v-else class="data-value no-data">暂无数据</text>
  167. </view>
  168. <text class="data-time" v-if="soilData.temperature">{{ formatDate(soilData.updateTime) || '未知' }}</text>
  169. </view>
  170. <!-- 土壤湿度 -->
  171. <view class="data-item" hover-class="data-item-hover">
  172. <text class="data-label">土壤湿度</text>
  173. <view class="data-value-container">
  174. <template v-if="soilData.moisture">
  175. <text class="data-value" :class="{
  176. 'updated': updatedFields.soil && updatedFields.soil.moisture,
  177. 'value-warning': parseFloat(soilData.moisture) < 20,
  178. 'value-alert': parseFloat(soilData.moisture) < 10
  179. }">{{ soilData.moisture }}</text>
  180. <text class="data-unit">%</text>
  181. </template>
  182. <text v-else class="data-value no-data">暂无数据</text>
  183. </view>
  184. <text class="data-time" v-if="soilData.moisture">{{ formatDate(soilData.updateTime) || '未知' }}</text>
  185. </view>
  186. <!-- 氮含量 -->
  187. <view class="data-item" hover-class="data-item-hover">
  188. <text class="data-label">氮含量</text>
  189. <view class="data-value-container">
  190. <template v-if="soilData.nitrogen">
  191. <text class="data-value" :class="{
  192. 'updated': updatedFields.soil && updatedFields.soil.nitrogen,
  193. 'value-warning': parseFloat(soilData.nitrogen) < 120
  194. }">{{ soilData.nitrogen }}</text>
  195. <text class="data-unit">mg/kg</text>
  196. </template>
  197. <text v-else class="data-value no-data">暂无数据</text>
  198. </view>
  199. <text class="data-time" v-if="soilData.nitrogen">{{ formatDate(soilData.updateTime) || '未知' }}</text>
  200. </view>
  201. <!-- 磷含量 -->
  202. <view class="data-item" hover-class="data-item-hover">
  203. <text class="data-label">磷含量</text>
  204. <view class="data-value-container">
  205. <template v-if="soilData.phosphorus">
  206. <text class="data-value" :class="{
  207. 'updated': updatedFields.soil && updatedFields.soil.phosphorus,
  208. 'value-warning': parseFloat(soilData.phosphorus) < 30
  209. }">{{ soilData.phosphorus }}</text>
  210. <text class="data-unit">mg/kg</text>
  211. </template>
  212. <text v-else class="data-value no-data">暂无数据</text>
  213. </view>
  214. <text class="data-time" v-if="soilData.phosphorus">{{ formatDate(soilData.updateTime) || '未知' }}</text>
  215. </view>
  216. <!-- 钾含量 -->
  217. <view class="data-item" hover-class="data-item-hover">
  218. <text class="data-label">钾含量</text>
  219. <view class="data-value-container">
  220. <template v-if="soilData.potassium">
  221. <text class="data-value" :class="{
  222. 'updated': updatedFields.soil && updatedFields.soil.potassium,
  223. 'value-warning': parseFloat(soilData.potassium) < 150
  224. }">{{ soilData.potassium }}</text>
  225. <text class="data-unit">mg/kg</text>
  226. </template>
  227. <text v-else class="data-value no-data">暂无数据</text>
  228. </view>
  229. <text class="data-time" v-if="soilData.potassium">{{ formatDate(soilData.updateTime) || '未知' }}</text>
  230. </view>
  231. <!-- 土壤电导率 -->
  232. <view class="data-item" hover-class="data-item-hover">
  233. <text class="data-label">电导率</text>
  234. <view class="data-value-container">
  235. <template v-if="soilData.conductivity">
  236. <text class="data-value" :class="{
  237. 'updated': updatedFields.soil && updatedFields.soil.conductivity,
  238. 'value-alert': parseFloat(soilData.conductivity) > 0.8
  239. }">{{ soilData.conductivity }}</text>
  240. <text class="data-unit">μS/cm</text>
  241. </template>
  242. <text v-else class="data-value no-data">暂无数据</text>
  243. </view>
  244. <text class="data-time" v-if="soilData.conductivity">{{ formatDate(soilData.updateTime) || '未知' }}</text>
  245. </view>
  246. <!-- PH值 -->
  247. <view class="data-item" hover-class="data-item-hover">
  248. <text class="data-label">PH值</text>
  249. <view class="data-value-container">
  250. <template v-if="soilData.ph">
  251. <text class="data-value" :class="{
  252. 'updated': updatedFields.soil && updatedFields.soil.ph,
  253. 'value-warning': parseFloat(soilData.ph) < 5.5 || parseFloat(soilData.ph) > 8.5,
  254. 'value-alert': parseFloat(soilData.ph) < 4.5 || parseFloat(soilData.ph) > 9
  255. }">{{ soilData.ph }}</text>
  256. <text class="data-unit"></text>
  257. </template>
  258. <text v-else class="data-value no-data">暂无数据</text>
  259. </view>
  260. <text class="data-time" v-if="soilData.ph">{{ formatDate(soilData.updateTime) || '未知' }}</text>
  261. </view>
  262. </view>
  263. </view>
  264. <!-- 告警信息列表 -->
  265. <view class="alerts-section">
  266. <view class="section-title">
  267. <text>告警信息</text>
  268. <view class="alert-badge" v-if="getUnhandledAlerts.length > 0">{{ getUnhandledAlerts.length }}</view>
  269. </view>
  270. <view class="alerts-list" v-if="getUnhandledAlerts.length > 0">
  271. <view
  272. v-for="(item, index) in getUnhandledAlerts.slice(0, 3)"
  273. :key="index"
  274. class="alert-item"
  275. :class="{
  276. 'alert-urgent': item.level === 3,
  277. 'alert-warning': item.level === 2,
  278. 'alert-info': item.level === 1
  279. }"
  280. >
  281. <view class="alert-item-icon">
  282. <image v-if="item.level === 3" src="/static/icons/warning_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
  283. <image v-else-if="item.level === 2" src="/static/icons/info_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
  284. <image v-else src="/static/icons/success_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
  285. </view>
  286. <view class="alert-item-info">
  287. <text class="alert-item-type">{{ item.type }}</text>
  288. <text class="alert-item-level">
  289. {{ item.level === 3 ? '紧急' : item.level === 2 ? '警告' : '提示' }}
  290. </text>
  291. </view>
  292. <view class="alert-item-time">{{ formatSmartTime(item.time) }}</view>
  293. </view>
  294. </view>
  295. <view v-else class="empty-alert">
  296. <text class="empty-text">暂无告警信息</text>
  297. </view>
  298. </view>
  299. </view>
  300. </template>
  301. <script>
  302. import { getDeviceCollectorDetail } from "@/api/services/device.js";
  303. import { formatSmartTime, formatDate } from '@/utils/dateUtils'
  304. export default {
  305. data() {
  306. return {
  307. deviceInfo: {
  308. deviceId: '',
  309. name: '设备加载中...',
  310. status: '',
  311. location: '正在获取位置...',
  312. lastUpdate: '',
  313. deviceType: 'weather' ,// 默认类型,会根据API返回更新
  314. deviceTypeId:null
  315. },
  316. // 气象站数据
  317. weatherData: {
  318. temperature: '',
  319. humidity: '',
  320. rainfall: '',
  321. windDirection: '',
  322. windSpeed: '',
  323. pressure: '',
  324. illumination: '',
  325. updateTime: ''
  326. },
  327. // 土壤墒情数据
  328. soilData: {
  329. temperature: '',
  330. moisture: '',
  331. nitrogen: '',
  332. phosphorus: '',
  333. potassium: '',
  334. conductivity: '',
  335. ph: '',
  336. updateTime: ''
  337. },
  338. // 告警数据
  339. alertHistory: [],
  340. // 刷新状态
  341. isRefreshing: false,
  342. // 数值更新动画
  343. updatedFields: {
  344. weather: {},
  345. soil: {}
  346. },
  347. }
  348. },
  349. computed: {
  350. // 获取所有未处理的告警
  351. getUnhandledAlerts() {
  352. return this.alertHistory.filter(alert => alert.status === 0);//未处理
  353. }
  354. },
  355. onReady() {
  356. // 设置页面标题
  357. uni.setNavigationBarTitle({
  358. title: this.deviceInfo.name
  359. })
  360. },
  361. onLoad(options) {
  362. uni.$once('passDeviceData', (data) => {
  363. console.log('接收到数据', data);
  364. // 如果有传入设备ID,则获取设备信息
  365. if (data && data.deviceId) {
  366. this.deviceInfo.deviceId = data.deviceId;
  367. this.deviceInfo.location = data.fieldName;
  368. this.deviceInfo.name = data.deviceName;
  369. this.deviceInfo.status = data.status;
  370. this.deviceInfo.deviceTypeId = data.deviceTypeId || '';
  371. // 加载设备详情
  372. this.fetchDeviceCollectorDetail();
  373. }
  374. });
  375. },
  376. methods: {
  377. formatDate,
  378. formatSmartTime,
  379. // 获取设备采集器详情
  380. fetchDeviceCollectorDetail() {
  381. if (!this.deviceInfo.deviceId) return;
  382. uni.showLoading({
  383. title: '加载数据中...'
  384. });
  385. getDeviceCollectorDetail(this.deviceInfo.deviceId)
  386. .then(res => {
  387. console.log('设备详情数据:', res);
  388. if (res.data.data && res.data.code === 200) {
  389. const detail = res.data.data;
  390. this.deviceInfo.lastUpdate = detail.collectTime
  391. // 保存旧数据用于比较
  392. let oldData = null;
  393. // 根据设备类型更新数据
  394. if (this.deviceInfo.deviceTypeId === '4') { //气象设备
  395. if(this.weatherData){
  396. oldData = JSON.parse(JSON.stringify(this.weatherData));
  397. }
  398. // 更新气象数据
  399. this.weatherData = {
  400. temperature: detail.temperature || '',
  401. humidity: detail.humidity || '',
  402. rainfall: detail.rainfall || '',
  403. windDirection: detail.windDirection || '',
  404. windSpeed: detail.windSpeed || '',
  405. pressure: detail.pressure || '',
  406. illumination: detail.illumination || '',
  407. updateTime: detail.collectTime|| '暂无数据'
  408. };
  409. // 检查哪些字段发生了变化
  410. this.updatedFields.weather = {};
  411. Object.keys(this.weatherData).forEach(key => {
  412. if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
  413. this.updatedFields.weather[key] = true;
  414. // 1秒后清除动画标记
  415. setTimeout(() => {
  416. this.$set(this.updatedFields.weather, key, false);
  417. }, 1000);
  418. }
  419. });
  420. } else if (this.deviceInfo.deviceTypeId === '1') { // 土壤设备
  421. if(this.soilData){
  422. oldData = JSON.parse(JSON.stringify(this.soilData));
  423. }
  424. // 更新土壤数据
  425. this.soilData = {
  426. temperature: detail.temperature || '',
  427. moisture: detail.soilTemperature || '',
  428. nitrogen: detail.soilN || '',
  429. phosphorus: detail.soilP || '',
  430. potassium: detail.soilK || '',
  431. conductivity: detail.conductivity || '',
  432. ph: detail.ph || '',
  433. updateTime: detail.collectTime || '暂无数据'
  434. };
  435. // 检查哪些字段发生了变化
  436. this.updatedFields.soil = {};
  437. Object.keys(this.soilData).forEach(key => {
  438. if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
  439. this.updatedFields.soil[key] = true;
  440. // 1秒后清除动画标记
  441. setTimeout(() => {
  442. this.$set(this.updatedFields.soil, key, false);
  443. }, 1000);
  444. }
  445. });
  446. }
  447. // 更新告警信息
  448. if (detail.alertRecordList && detail.alertRecordList.length > 0) {
  449. this.alertHistory = detail.alertRecordList.map(alert => ({
  450. id: alert.alertId,
  451. time: alert.alertTime,
  452. type: alert.alertContent,
  453. status: alert.processStatus,
  454. level: alert.alertLevel
  455. }));
  456. }
  457. // 更新页面标题
  458. uni.setNavigationBarTitle({
  459. title: this.deviceInfo.name
  460. });
  461. } else {
  462. uni.showToast({
  463. title: '暂无设备信息',
  464. icon: 'none'
  465. });
  466. }
  467. })
  468. .catch(error => {
  469. console.error('获取设备详情失败', error);
  470. uni.showToast({
  471. title: '获取设备数据失败',
  472. icon: 'none'
  473. });
  474. })
  475. .finally(() => {
  476. uni.hideLoading();
  477. this.isRefreshing = false;
  478. });
  479. },
  480. // 格式还日期格式;返回 今天:18:00
  481. // formatSmartTime(timeStr) {
  482. // if (!timeStr) return '未知';
  483. // // iOS兼容:将 "2025-06-19 09:15:00" 转换为 "2025-06-19T09:15:00"
  484. // const safeStr = timeStr.replace(' ', 'T');
  485. // const inputDate = new Date(safeStr);
  486. // if (isNaN(inputDate.getTime())) return '时间格式错误';
  487. // const now = new Date();
  488. // // 取日期差值(单位:天)
  489. // const inputDayStart = new Date(inputDate.getFullYear(), inputDate.getMonth(), inputDate.getDate());
  490. // const nowDayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  491. // const diffTime = nowDayStart - inputDayStart;
  492. // const oneDay = 1000 * 60 * 60 * 24;
  493. // const timePart = inputDate.toTimeString().slice(0, 5); // HH:mm
  494. // if (diffTime === 0) {
  495. // return `今天 ${timePart}`;
  496. // } else if (diffTime === oneDay) {
  497. // return `昨天 ${timePart}`;
  498. // } else if (diffTime === oneDay * 2) {
  499. // return `前天 ${timePart}`;
  500. // } else {
  501. // return `${inputDate.getMonth() + 1}月${inputDate.getDate()}日 ${timePart}`;
  502. // }
  503. // },
  504. // 刷新数据
  505. refreshData() {
  506. if (this.isRefreshing) return;
  507. this.isRefreshing = true;
  508. this.fetchDeviceCollectorDetail();
  509. },
  510. // 格式化日期
  511. // formatDate(dateStr) {
  512. // if (!dateStr) return '未知';
  513. // // 解析为 Date
  514. // const parsedStr = dateStr.replace(' ', 'T');
  515. // const date = new Date(parsedStr);
  516. // if (isNaN(date)) return '无效时间';
  517. // const now = new Date();
  518. // // 计算差时长(分钟)
  519. // const diff = Math.floor((now - date) / 1000 / 60);
  520. // if (diff < 1) return '刚刚更新';
  521. // if (diff < 5) return '1分钟前更新';
  522. // if (diff < 10) return '5分钟前更新';
  523. // if (diff < 60) return `${diff}分钟前更新`;
  524. // if (diff < 120) return '1小时前更新';
  525. // if (diff < 24 * 60) return `${Math.floor(diff / 60)}小时前更新`;
  526. // if (diff < 7 * 24 * 60) return `${Math.floor(diff / (60 * 24))}天前更新`;
  527. // return parsedStr.split('T')[0] + ' 更新';
  528. // },
  529. }
  530. }
  531. </script>
  532. <style>
  533. /* 基础样式 */
  534. .container {
  535. display: flex;
  536. flex-direction: column;
  537. min-height: 100vh;
  538. background-color: #F8FCF9;
  539. padding-bottom: 30rpx;
  540. }
  541. /* 设备头部样式 */
  542. .device-header {
  543. background-color: #FFFFFF;
  544. border-radius: 20rpx;
  545. padding: 30rpx;
  546. margin: 30rpx 30rpx 30rpx;
  547. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  548. border: 1rpx solid rgba(210, 237, 217, 0.5);
  549. }
  550. .device-info-row {
  551. display: flex;
  552. justify-content: space-between;
  553. align-items: center;
  554. margin-bottom: 28rpx;
  555. }
  556. .device-name-container {
  557. display: flex;
  558. flex-direction: column;
  559. align-items: flex-start;
  560. }
  561. .refresh-btn {
  562. width: 48rpx;
  563. height: 48rpx;
  564. background-color: rgba(76, 175, 80, 0.1);
  565. border-radius: 50%;
  566. display: flex;
  567. align-items: center;
  568. justify-content: center;
  569. padding: 12rpx;
  570. transition: transform 0.3s ease;
  571. }
  572. .refresh-btn:active {
  573. transform: rotate(180deg);
  574. }
  575. .device-name {
  576. font-size: 36rpx;
  577. color: #333333;
  578. font-weight: 600;
  579. margin-bottom: 12rpx;
  580. }
  581. .status-tag {
  582. padding: 6rpx 16rpx 6rpx 28rpx;
  583. border-radius: 30rpx;
  584. font-size: 24rpx;
  585. font-weight: 500;
  586. flex-shrink: 0;
  587. position: relative;
  588. overflow: hidden;
  589. }
  590. .status-online {
  591. background-color: rgba(76, 175, 80, 0.1);
  592. color: #3BB44A;
  593. }
  594. .status-offline {
  595. background-color: rgba(245, 108, 108, 0.1);
  596. color: #F56C6C;
  597. padding-left: 28rpx;
  598. }
  599. .status-dot {
  600. position: absolute;
  601. width: 6rpx;
  602. height: 6rpx;
  603. background-color: #3BB44A;
  604. border-radius: 50%;
  605. top: 50%;
  606. left: 12rpx;
  607. transform: translateY(-50%);
  608. box-shadow: 0 0 4rpx rgba(76, 175, 80, 0.8);
  609. animation: blink 1.5s infinite;
  610. display: inline-block;
  611. }
  612. .status-dot.offline-dot {
  613. background-color: #F56C6C;
  614. box-shadow: 0 0 4rpx rgba(245, 108, 108, 0.8);
  615. }
  616. @keyframes blink {
  617. 0% {
  618. opacity: 0.4;
  619. }
  620. 50% {
  621. opacity: 1;
  622. }
  623. 100% {
  624. opacity: 0.4;
  625. }
  626. }
  627. .device-meta-row {
  628. display: flex;
  629. flex-direction: column;
  630. background-color: #F9FCFA;
  631. padding: 20rpx 24rpx;
  632. border-radius: 16rpx;
  633. border: 1rpx solid rgba(210, 237, 217, 0.8);
  634. }
  635. .device-meta-item {
  636. display: flex;
  637. align-items: center;
  638. font-size: 28rpx;
  639. margin-top: 18rpx;
  640. }
  641. .device-meta-item:first-child {
  642. margin-top: 0;
  643. }
  644. .meta-icon {
  645. width: 36rpx;
  646. height: 36rpx;
  647. display: flex;
  648. align-items: center;
  649. justify-content: center;
  650. margin-right: 12rpx;
  651. }
  652. .meta-label {
  653. color: #777777;
  654. min-width: 140rpx;
  655. font-size: 28rpx;
  656. }
  657. .meta-value {
  658. color: #333333;
  659. flex: 1;
  660. font-size: 28rpx;
  661. font-weight: 500;
  662. }
  663. /* 数据展示区域 */
  664. .data-section {
  665. margin: 0 30rpx 30rpx;
  666. background-color: #FFFFFF;
  667. border-radius: 24rpx;
  668. padding: 30rpx 24rpx;
  669. box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.05);
  670. border: 1rpx solid rgba(210, 237, 217, 0.5);
  671. }
  672. .section-title {
  673. font-size: 32rpx;
  674. font-weight: 600;
  675. color: #333333;
  676. margin-bottom: 20rpx;
  677. padding: 0 10rpx 16rpx;
  678. display: flex;
  679. align-items: center;
  680. position: relative;
  681. border-bottom: 2rpx solid rgba(59, 180, 74, 0.1);
  682. }
  683. .section-title::before {
  684. content: '';
  685. position: absolute;
  686. left: 0;
  687. top: 50%;
  688. transform: translateY(-50%);
  689. width: 8rpx;
  690. height: 32rpx;
  691. background: linear-gradient(to bottom, #4CAF50, #81C784);
  692. border-radius: 4rpx;
  693. margin-right: 10rpx;
  694. }
  695. .section-title text {
  696. margin-left: 20rpx;
  697. }
  698. .alert-badge {
  699. background-color: #F56C6C;
  700. color: #FFFFFF;
  701. font-size: 22rpx;
  702. border-radius: 30rpx;
  703. padding: 2rpx 12rpx;
  704. margin-left: 12rpx;
  705. font-weight: normal;
  706. min-width: 32rpx;
  707. text-align: center;
  708. }
  709. .data-grid {
  710. display: flex;
  711. flex-wrap: wrap;
  712. padding: 16rpx 0;
  713. width: 100%;
  714. margin: 0 -12rpx;
  715. }
  716. .data-item {
  717. width: calc(50% - 24rpx);
  718. margin: 0 12rpx 24rpx;
  719. display: flex;
  720. flex-direction: column;
  721. align-items: flex-start;
  722. justify-content: space-between;
  723. background: linear-gradient(to bottom right, #F9FFFB, #FFFFFF);
  724. border-radius: 24rpx;
  725. padding: 28rpx 24rpx;
  726. box-sizing: border-box;
  727. box-shadow: 0 6rpx 18rpx rgba(0, 0, 0, 0.06), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
  728. position: relative;
  729. border: 1rpx solid rgba(210, 237, 217, 0.6);
  730. transition: all 0.25s ease;
  731. overflow: hidden;
  732. min-height: 180rpx;
  733. }
  734. .data-item::before {
  735. content: '';
  736. position: absolute;
  737. top: 0;
  738. left: 0;
  739. width: 8rpx;
  740. height: 100%;
  741. background: linear-gradient(to bottom, #4CAF50, #81C784);
  742. opacity: 0.9;
  743. border-radius: 4rpx 0 0 4rpx;
  744. }
  745. .data-item-hover {
  746. transform: scale(1.02);
  747. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
  748. background: linear-gradient(to bottom right, #F7FFF9, #FFFFFF);
  749. }
  750. .data-label {
  751. font-size: 26rpx;
  752. color: #666666;
  753. margin-bottom: 22rpx;
  754. font-weight: 500;
  755. align-self: flex-start;
  756. }
  757. .data-value-container {
  758. display: flex;
  759. align-items: flex-end;
  760. width: 100%;
  761. margin-bottom: 18rpx;
  762. }
  763. .data-value {
  764. font-size: 40rpx;
  765. color: #222222;
  766. font-weight: 700;
  767. line-height: 1;
  768. }
  769. .data-value.no-data {
  770. font-size: 28rpx;
  771. color: #999999;
  772. font-weight: normal;
  773. }
  774. .data-unit {
  775. font-size: 24rpx;
  776. color: #999999;
  777. margin-left: 6rpx;
  778. padding-bottom: 6rpx;
  779. align-self: flex-end;
  780. }
  781. .data-time {
  782. font-size: 20rpx;
  783. color: #AAAAAA;
  784. width: 100%;
  785. text-align: right;
  786. }
  787. /* 数据更新动画 */
  788. @keyframes fadeNumberChange {
  789. 0% {
  790. opacity: 0.6;
  791. transform: scale(0.95);
  792. }
  793. 50% {
  794. opacity: 1;
  795. transform: scale(1.05);
  796. }
  797. 100% {
  798. opacity: 1;
  799. transform: scale(1);
  800. }
  801. }
  802. .data-value.updated {
  803. animation: fadeNumberChange 0.8s ease;
  804. }
  805. /* 异常值样式 */
  806. .value-warning {
  807. color: #E6A23C !important;
  808. }
  809. .value-alert {
  810. color: #F56C6C !important;
  811. }
  812. /* 点击波纹效果(可选)*/
  813. @keyframes ripple {
  814. 0% {
  815. transform: scale(0);
  816. opacity: 0.6;
  817. }
  818. 100% {
  819. transform: scale(2);
  820. opacity: 0;
  821. }
  822. }
  823. .data-item::after {
  824. content: '';
  825. position: absolute;
  826. top: 0;
  827. left: 0;
  828. right: 0;
  829. bottom: 0;
  830. background-color: rgba(76, 175, 80, 0.1);
  831. border-radius: 24rpx;
  832. opacity: 0;
  833. transition: opacity 0.3s;
  834. z-index: -1;
  835. }
  836. .data-item-hover::after {
  837. opacity: 1;
  838. }
  839. /* 告警信息列表 */
  840. .alerts-section {
  841. margin: 0 30rpx 30rpx;
  842. background-color: #FFFFFF;
  843. border-radius: 20rpx;
  844. padding: 30rpx 24rpx;
  845. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  846. border: 1rpx solid rgba(210, 237, 217, 0.5);
  847. }
  848. .alerts-list {
  849. display: flex;
  850. flex-direction: column;
  851. }
  852. .alert-item {
  853. display: flex;
  854. align-items: center;
  855. padding: 24rpx 20rpx;
  856. border-radius: 12rpx;
  857. margin-bottom: 16rpx;
  858. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  859. position: relative;
  860. border: 1rpx solid transparent;
  861. transition: transform 0.2s ease;
  862. }
  863. .alert-item:active {
  864. transform: scale(0.98);
  865. }
  866. .alert-urgent {
  867. background-color: #FEF3F3;
  868. border-left: 4rpx solid #F56C6C;
  869. border-color: rgba(245, 108, 108, 0.2);
  870. }
  871. .alert-warning {
  872. background-color: #FFF8E6;
  873. border-left: 4rpx solid #E6A23C;
  874. border-color: rgba(230, 162, 60, 0.2);
  875. }
  876. .alert-info {
  877. background-color: #F2FAF5;
  878. border-left: 4rpx solid #67C23A;
  879. border-color: rgba(103, 194, 58, 0.2);
  880. }
  881. .alert-item-icon {
  882. width: 50rpx;
  883. height: 50rpx;
  884. display: flex;
  885. align-items: center;
  886. justify-content: center;
  887. margin-right: 16rpx;
  888. }
  889. .alert-item-info {
  890. flex: 1;
  891. display: flex;
  892. flex-direction: column;
  893. }
  894. .alert-item-type {
  895. font-size: 28rpx;
  896. color: #333333;
  897. font-weight: 500;
  898. margin-bottom: 8rpx;
  899. }
  900. .alert-item-level {
  901. font-size: 24rpx;
  902. color: #999999;
  903. }
  904. .alert-item-time {
  905. font-size: 24rpx;
  906. color: #999999;
  907. margin-left: 16rpx;
  908. min-width: 100rpx;
  909. text-align: right;
  910. }
  911. .empty-alert {
  912. padding: 60rpx 0;
  913. display: flex;
  914. justify-content: center;
  915. align-items: center;
  916. }
  917. .empty-text {
  918. font-size: 28rpx;
  919. color: #999999;
  920. }
  921. /* 刷新按钮旋转动画 */
  922. @keyframes spin {
  923. 0% {
  924. transform: rotate(0deg);
  925. }
  926. 100% {
  927. transform: rotate(360deg);
  928. }
  929. }
  930. .refresh-btn.refreshing {
  931. animation: spin 1.2s linear infinite;
  932. }
  933. /* 土壤数据标题样式调整 */
  934. .soil-title, .data-title {
  935. display: flex;
  936. align-items: center;
  937. position: relative;
  938. padding-left: 24rpx;
  939. }
  940. .soil-title::before, .data-title::before {
  941. content: '';
  942. position: absolute;
  943. left: 0;
  944. top: 50%;
  945. transform: translateY(-50%);
  946. width: 8rpx;
  947. height: 36rpx;
  948. background: linear-gradient(to bottom, #4CAF50, #81C784);
  949. border-radius: 4rpx;
  950. }
  951. .soil-title text, .data-title text {
  952. margin-left: 16rpx;
  953. font-weight: 600;
  954. }
  955. </style>