detail-collector.vue 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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. export default {
  304. data() {
  305. return {
  306. deviceInfo: {
  307. deviceId: '',
  308. name: '设备加载中...',
  309. status: '',
  310. location: '正在获取位置...',
  311. lastUpdate: '',
  312. deviceType: 'weather' ,// 默认类型,会根据API返回更新
  313. deviceTypeId:null
  314. },
  315. // 气象站数据
  316. weatherData: {
  317. temperature: '',
  318. humidity: '',
  319. rainfall: '',
  320. windDirection: '',
  321. windSpeed: '',
  322. pressure: '',
  323. illumination: '',
  324. updateTime: ''
  325. },
  326. // 土壤墒情数据
  327. soilData: {
  328. temperature: '',
  329. moisture: '',
  330. nitrogen: '',
  331. phosphorus: '',
  332. potassium: '',
  333. conductivity: '',
  334. ph: '',
  335. updateTime: ''
  336. },
  337. // 告警数据
  338. alertHistory: [],
  339. // 刷新状态
  340. isRefreshing: false,
  341. // 数值更新动画
  342. updatedFields: {
  343. weather: {},
  344. soil: {}
  345. },
  346. }
  347. },
  348. computed: {
  349. // 获取所有未处理的告警
  350. getUnhandledAlerts() {
  351. return this.alertHistory.filter(alert => alert.status === 0);//未处理
  352. }
  353. },
  354. onReady() {
  355. // 设置页面标题
  356. uni.setNavigationBarTitle({
  357. title: this.deviceInfo.name
  358. })
  359. },
  360. onLoad(options) {
  361. uni.$once('passDeviceData', (data) => {
  362. console.log('接收到数据', data);
  363. // 如果有传入设备ID,则获取设备信息
  364. if (data && data.deviceId) {
  365. this.deviceInfo.deviceId = data.deviceId;
  366. this.deviceInfo.location = data.fieldName;
  367. this.deviceInfo.name = data.deviceName;
  368. this.deviceInfo.status = data.status;
  369. this.deviceInfo.deviceTypeId = data.deviceTypeId || '';
  370. // 加载设备详情
  371. this.fetchDeviceCollectorDetail();
  372. }
  373. });
  374. },
  375. methods: {
  376. // 获取设备采集器详情
  377. fetchDeviceCollectorDetail() {
  378. if (!this.deviceInfo.deviceId) return;
  379. uni.showLoading({
  380. title: '加载数据中...'
  381. });
  382. getDeviceCollectorDetail(this.deviceInfo.deviceId)
  383. .then(res => {
  384. console.log('设备详情数据:', res);
  385. if (res.data.data && res.data.code === 200) {
  386. const detail = res.data.data;
  387. this.deviceInfo.lastUpdate = detail.collectTime
  388. // 保存旧数据用于比较
  389. let oldData = null;
  390. // 根据设备类型更新数据
  391. if (this.deviceInfo.deviceTypeId === '4') { //气象设备
  392. if(this.weatherData){
  393. oldData = JSON.parse(JSON.stringify(this.weatherData));
  394. }
  395. // 更新气象数据
  396. this.weatherData = {
  397. temperature: detail.temperature || '',
  398. humidity: detail.humidity || '',
  399. rainfall: detail.rainfall || '',
  400. windDirection: detail.windDirection || '',
  401. windSpeed: detail.windSpeed || '',
  402. pressure: detail.pressure || '',
  403. illumination: detail.illumination || '',
  404. updateTime: detail.collectTime|| '暂无数据'
  405. };
  406. // 检查哪些字段发生了变化
  407. this.updatedFields.weather = {};
  408. Object.keys(this.weatherData).forEach(key => {
  409. if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
  410. this.updatedFields.weather[key] = true;
  411. // 1秒后清除动画标记
  412. setTimeout(() => {
  413. this.$set(this.updatedFields.weather, key, false);
  414. }, 1000);
  415. }
  416. });
  417. } else if (this.deviceInfo.deviceTypeId === '1') { // 土壤设备
  418. if(this.soilData){
  419. oldData = JSON.parse(JSON.stringify(this.soilData));
  420. }
  421. // 更新土壤数据
  422. this.soilData = {
  423. temperature: detail.temperature || '',
  424. moisture: detail.soilTemperature || '',
  425. nitrogen: detail.soilN || '',
  426. phosphorus: detail.soilP || '',
  427. potassium: detail.soilK || '',
  428. conductivity: detail.conductivity || '',
  429. ph: detail.ph || '',
  430. updateTime: detail.collectTime || '暂无数据'
  431. };
  432. // 检查哪些字段发生了变化
  433. this.updatedFields.soil = {};
  434. Object.keys(this.soilData).forEach(key => {
  435. if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
  436. this.updatedFields.soil[key] = true;
  437. // 1秒后清除动画标记
  438. setTimeout(() => {
  439. this.$set(this.updatedFields.soil, key, false);
  440. }, 1000);
  441. }
  442. });
  443. }
  444. // 更新告警信息
  445. if (detail.alertRecordList && detail.alertRecordList.length > 0) {
  446. this.alertHistory = detail.alertRecordList.map(alert => ({
  447. id: alert.alertId,
  448. time: alert.alertTime,
  449. type: alert.alertContent,
  450. status: alert.processStatus,
  451. level: alert.alertLevel
  452. }));
  453. }
  454. // 更新页面标题
  455. uni.setNavigationBarTitle({
  456. title: this.deviceInfo.name
  457. });
  458. } else {
  459. uni.showToast({
  460. title: '暂无设备信息',
  461. icon: 'none'
  462. });
  463. }
  464. })
  465. .catch(error => {
  466. console.error('获取设备详情失败', error);
  467. uni.showToast({
  468. title: '获取设备数据失败',
  469. icon: 'none'
  470. });
  471. })
  472. .finally(() => {
  473. uni.hideLoading();
  474. this.isRefreshing = false;
  475. });
  476. },
  477. // 格式还日期格式;返回 今天:18:00
  478. formatSmartTime(timeStr) {
  479. if (!timeStr) return '未知';
  480. // iOS兼容:将 "2025-06-19 09:15:00" 转换为 "2025-06-19T09:15:00"
  481. const safeStr = timeStr.replace(' ', 'T');
  482. const inputDate = new Date(safeStr);
  483. if (isNaN(inputDate.getTime())) return '时间格式错误';
  484. const now = new Date();
  485. // 取日期差值(单位:天)
  486. const inputDayStart = new Date(inputDate.getFullYear(), inputDate.getMonth(), inputDate.getDate());
  487. const nowDayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  488. const diffTime = nowDayStart - inputDayStart;
  489. const oneDay = 1000 * 60 * 60 * 24;
  490. const timePart = inputDate.toTimeString().slice(0, 5); // HH:mm
  491. if (diffTime === 0) {
  492. return `今天 ${timePart}`;
  493. } else if (diffTime === oneDay) {
  494. return `昨天 ${timePart}`;
  495. } else if (diffTime === oneDay * 2) {
  496. return `前天 ${timePart}`;
  497. } else {
  498. return `${inputDate.getMonth() + 1}月${inputDate.getDate()}日 ${timePart}`;
  499. }
  500. },
  501. // 刷新数据
  502. refreshData() {
  503. if (this.isRefreshing) return;
  504. this.isRefreshing = true;
  505. this.fetchDeviceCollectorDetail();
  506. },
  507. // 格式化日期
  508. formatDate(dateStr) {
  509. if (!dateStr) return '未知';
  510. // 解析为 Date
  511. const parsedStr = dateStr.replace(' ', 'T');
  512. const date = new Date(parsedStr);
  513. if (isNaN(date)) return '无效时间';
  514. const now = new Date();
  515. // 计算差时长(分钟)
  516. const diff = Math.floor((now - date) / 1000 / 60);
  517. if (diff < 1) return '刚刚更新';
  518. if (diff < 5) return '1分钟前更新';
  519. if (diff < 10) return '5分钟前更新';
  520. if (diff < 60) return `${diff}分钟前更新`;
  521. if (diff < 120) return '1小时前更新';
  522. if (diff < 24 * 60) return `${Math.floor(diff / 60)}小时前更新`;
  523. if (diff < 7 * 24 * 60) return `${Math.floor(diff / (60 * 24))}天前更新`;
  524. return parsedStr.split('T')[0] + ' 更新';
  525. },
  526. }
  527. }
  528. </script>
  529. <style>
  530. /* 基础样式 */
  531. .container {
  532. display: flex;
  533. flex-direction: column;
  534. min-height: 100vh;
  535. background-color: #F8FCF9;
  536. padding-bottom: 30rpx;
  537. }
  538. /* 设备头部样式 */
  539. .device-header {
  540. background-color: #FFFFFF;
  541. border-radius: 20rpx;
  542. padding: 30rpx;
  543. margin: 30rpx 30rpx 30rpx;
  544. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  545. border: 1rpx solid rgba(210, 237, 217, 0.5);
  546. }
  547. .device-info-row {
  548. display: flex;
  549. justify-content: space-between;
  550. align-items: center;
  551. margin-bottom: 28rpx;
  552. }
  553. .device-name-container {
  554. display: flex;
  555. flex-direction: column;
  556. align-items: flex-start;
  557. }
  558. .refresh-btn {
  559. width: 48rpx;
  560. height: 48rpx;
  561. background-color: rgba(76, 175, 80, 0.1);
  562. border-radius: 50%;
  563. display: flex;
  564. align-items: center;
  565. justify-content: center;
  566. padding: 12rpx;
  567. transition: transform 0.3s ease;
  568. }
  569. .refresh-btn:active {
  570. transform: rotate(180deg);
  571. }
  572. .device-name {
  573. font-size: 36rpx;
  574. color: #333333;
  575. font-weight: 600;
  576. margin-bottom: 12rpx;
  577. }
  578. .status-tag {
  579. padding: 6rpx 16rpx 6rpx 28rpx;
  580. border-radius: 30rpx;
  581. font-size: 24rpx;
  582. font-weight: 500;
  583. flex-shrink: 0;
  584. position: relative;
  585. overflow: hidden;
  586. }
  587. .status-online {
  588. background-color: rgba(76, 175, 80, 0.1);
  589. color: #3BB44A;
  590. }
  591. .status-offline {
  592. background-color: rgba(245, 108, 108, 0.1);
  593. color: #F56C6C;
  594. padding-left: 28rpx;
  595. }
  596. .status-dot {
  597. position: absolute;
  598. width: 6rpx;
  599. height: 6rpx;
  600. background-color: #3BB44A;
  601. border-radius: 50%;
  602. top: 50%;
  603. left: 12rpx;
  604. transform: translateY(-50%);
  605. box-shadow: 0 0 4rpx rgba(76, 175, 80, 0.8);
  606. animation: blink 1.5s infinite;
  607. display: inline-block;
  608. }
  609. .status-dot.offline-dot {
  610. background-color: #F56C6C;
  611. box-shadow: 0 0 4rpx rgba(245, 108, 108, 0.8);
  612. }
  613. @keyframes blink {
  614. 0% {
  615. opacity: 0.4;
  616. }
  617. 50% {
  618. opacity: 1;
  619. }
  620. 100% {
  621. opacity: 0.4;
  622. }
  623. }
  624. .device-meta-row {
  625. display: flex;
  626. flex-direction: column;
  627. background-color: #F9FCFA;
  628. padding: 20rpx 24rpx;
  629. border-radius: 16rpx;
  630. border: 1rpx solid rgba(210, 237, 217, 0.8);
  631. }
  632. .device-meta-item {
  633. display: flex;
  634. align-items: center;
  635. font-size: 28rpx;
  636. margin-top: 18rpx;
  637. }
  638. .device-meta-item:first-child {
  639. margin-top: 0;
  640. }
  641. .meta-icon {
  642. width: 36rpx;
  643. height: 36rpx;
  644. display: flex;
  645. align-items: center;
  646. justify-content: center;
  647. margin-right: 12rpx;
  648. }
  649. .meta-label {
  650. color: #777777;
  651. min-width: 140rpx;
  652. font-size: 28rpx;
  653. }
  654. .meta-value {
  655. color: #333333;
  656. flex: 1;
  657. font-size: 28rpx;
  658. font-weight: 500;
  659. }
  660. /* 数据展示区域 */
  661. .data-section {
  662. margin: 0 30rpx 30rpx;
  663. background-color: #FFFFFF;
  664. border-radius: 24rpx;
  665. padding: 30rpx 24rpx;
  666. box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.05);
  667. border: 1rpx solid rgba(210, 237, 217, 0.5);
  668. }
  669. .section-title {
  670. font-size: 32rpx;
  671. font-weight: 600;
  672. color: #333333;
  673. margin-bottom: 20rpx;
  674. padding: 0 10rpx 16rpx;
  675. display: flex;
  676. align-items: center;
  677. position: relative;
  678. border-bottom: 2rpx solid rgba(59, 180, 74, 0.1);
  679. }
  680. .section-title::before {
  681. content: '';
  682. position: absolute;
  683. left: 0;
  684. top: 50%;
  685. transform: translateY(-50%);
  686. width: 8rpx;
  687. height: 32rpx;
  688. background: linear-gradient(to bottom, #4CAF50, #81C784);
  689. border-radius: 4rpx;
  690. margin-right: 10rpx;
  691. }
  692. .section-title text {
  693. margin-left: 20rpx;
  694. }
  695. .alert-badge {
  696. background-color: #F56C6C;
  697. color: #FFFFFF;
  698. font-size: 22rpx;
  699. border-radius: 30rpx;
  700. padding: 2rpx 12rpx;
  701. margin-left: 12rpx;
  702. font-weight: normal;
  703. min-width: 32rpx;
  704. text-align: center;
  705. }
  706. .data-grid {
  707. display: flex;
  708. flex-wrap: wrap;
  709. padding: 16rpx 0;
  710. width: 100%;
  711. margin: 0 -12rpx;
  712. }
  713. .data-item {
  714. width: calc(50% - 24rpx);
  715. margin: 0 12rpx 24rpx;
  716. display: flex;
  717. flex-direction: column;
  718. align-items: flex-start;
  719. justify-content: space-between;
  720. background: linear-gradient(to bottom right, #F9FFFB, #FFFFFF);
  721. border-radius: 24rpx;
  722. padding: 28rpx 24rpx;
  723. box-sizing: border-box;
  724. box-shadow: 0 6rpx 18rpx rgba(0, 0, 0, 0.06), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
  725. position: relative;
  726. border: 1rpx solid rgba(210, 237, 217, 0.6);
  727. transition: all 0.25s ease;
  728. overflow: hidden;
  729. min-height: 180rpx;
  730. }
  731. .data-item::before {
  732. content: '';
  733. position: absolute;
  734. top: 0;
  735. left: 0;
  736. width: 8rpx;
  737. height: 100%;
  738. background: linear-gradient(to bottom, #4CAF50, #81C784);
  739. opacity: 0.9;
  740. border-radius: 4rpx 0 0 4rpx;
  741. }
  742. .data-item-hover {
  743. transform: scale(1.02);
  744. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
  745. background: linear-gradient(to bottom right, #F7FFF9, #FFFFFF);
  746. }
  747. .data-label {
  748. font-size: 26rpx;
  749. color: #666666;
  750. margin-bottom: 22rpx;
  751. font-weight: 500;
  752. align-self: flex-start;
  753. }
  754. .data-value-container {
  755. display: flex;
  756. align-items: flex-end;
  757. width: 100%;
  758. margin-bottom: 18rpx;
  759. }
  760. .data-value {
  761. font-size: 40rpx;
  762. color: #222222;
  763. font-weight: 700;
  764. line-height: 1;
  765. }
  766. .data-value.no-data {
  767. font-size: 28rpx;
  768. color: #999999;
  769. font-weight: normal;
  770. }
  771. .data-unit {
  772. font-size: 24rpx;
  773. color: #999999;
  774. margin-left: 6rpx;
  775. padding-bottom: 6rpx;
  776. align-self: flex-end;
  777. }
  778. .data-time {
  779. font-size: 20rpx;
  780. color: #AAAAAA;
  781. width: 100%;
  782. text-align: right;
  783. }
  784. /* 数据更新动画 */
  785. @keyframes fadeNumberChange {
  786. 0% {
  787. opacity: 0.6;
  788. transform: scale(0.95);
  789. }
  790. 50% {
  791. opacity: 1;
  792. transform: scale(1.05);
  793. }
  794. 100% {
  795. opacity: 1;
  796. transform: scale(1);
  797. }
  798. }
  799. .data-value.updated {
  800. animation: fadeNumberChange 0.8s ease;
  801. }
  802. /* 异常值样式 */
  803. .value-warning {
  804. color: #E6A23C !important;
  805. }
  806. .value-alert {
  807. color: #F56C6C !important;
  808. }
  809. /* 点击波纹效果(可选)*/
  810. @keyframes ripple {
  811. 0% {
  812. transform: scale(0);
  813. opacity: 0.6;
  814. }
  815. 100% {
  816. transform: scale(2);
  817. opacity: 0;
  818. }
  819. }
  820. .data-item::after {
  821. content: '';
  822. position: absolute;
  823. top: 0;
  824. left: 0;
  825. right: 0;
  826. bottom: 0;
  827. background-color: rgba(76, 175, 80, 0.1);
  828. border-radius: 24rpx;
  829. opacity: 0;
  830. transition: opacity 0.3s;
  831. z-index: -1;
  832. }
  833. .data-item-hover::after {
  834. opacity: 1;
  835. }
  836. /* 告警信息列表 */
  837. .alerts-section {
  838. margin: 0 30rpx 30rpx;
  839. background-color: #FFFFFF;
  840. border-radius: 20rpx;
  841. padding: 30rpx 24rpx;
  842. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  843. border: 1rpx solid rgba(210, 237, 217, 0.5);
  844. }
  845. .alerts-list {
  846. display: flex;
  847. flex-direction: column;
  848. }
  849. .alert-item {
  850. display: flex;
  851. align-items: center;
  852. padding: 24rpx 20rpx;
  853. border-radius: 12rpx;
  854. margin-bottom: 16rpx;
  855. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  856. position: relative;
  857. border: 1rpx solid transparent;
  858. transition: transform 0.2s ease;
  859. }
  860. .alert-item:active {
  861. transform: scale(0.98);
  862. }
  863. .alert-urgent {
  864. background-color: #FEF3F3;
  865. border-left: 4rpx solid #F56C6C;
  866. border-color: rgba(245, 108, 108, 0.2);
  867. }
  868. .alert-warning {
  869. background-color: #FFF8E6;
  870. border-left: 4rpx solid #E6A23C;
  871. border-color: rgba(230, 162, 60, 0.2);
  872. }
  873. .alert-info {
  874. background-color: #F2FAF5;
  875. border-left: 4rpx solid #67C23A;
  876. border-color: rgba(103, 194, 58, 0.2);
  877. }
  878. .alert-item-icon {
  879. width: 50rpx;
  880. height: 50rpx;
  881. display: flex;
  882. align-items: center;
  883. justify-content: center;
  884. margin-right: 16rpx;
  885. }
  886. .alert-item-info {
  887. flex: 1;
  888. display: flex;
  889. flex-direction: column;
  890. }
  891. .alert-item-type {
  892. font-size: 28rpx;
  893. color: #333333;
  894. font-weight: 500;
  895. margin-bottom: 8rpx;
  896. }
  897. .alert-item-level {
  898. font-size: 24rpx;
  899. color: #999999;
  900. }
  901. .alert-item-time {
  902. font-size: 24rpx;
  903. color: #999999;
  904. margin-left: 16rpx;
  905. min-width: 100rpx;
  906. text-align: right;
  907. }
  908. .empty-alert {
  909. padding: 60rpx 0;
  910. display: flex;
  911. justify-content: center;
  912. align-items: center;
  913. }
  914. .empty-text {
  915. font-size: 28rpx;
  916. color: #999999;
  917. }
  918. /* 刷新按钮旋转动画 */
  919. @keyframes spin {
  920. 0% {
  921. transform: rotate(0deg);
  922. }
  923. 100% {
  924. transform: rotate(360deg);
  925. }
  926. }
  927. .refresh-btn.refreshing {
  928. animation: spin 1.2s linear infinite;
  929. }
  930. /* 土壤数据标题样式调整 */
  931. .soil-title, .data-title {
  932. display: flex;
  933. align-items: center;
  934. position: relative;
  935. padding-left: 24rpx;
  936. }
  937. .soil-title::before, .data-title::before {
  938. content: '';
  939. position: absolute;
  940. left: 0;
  941. top: 50%;
  942. transform: translateY(-50%);
  943. width: 8rpx;
  944. height: 36rpx;
  945. background: linear-gradient(to bottom, #4CAF50, #81C784);
  946. border-radius: 4rpx;
  947. }
  948. .soil-title text, .data-title text {
  949. margin-left: 16rpx;
  950. font-weight: 600;
  951. }
  952. </style>