detail-collector.vue 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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 === 'online' ? 'status-online' : 'status-offline'"
  11. >
  12. <view class="status-dot" :class="{'offline-dot': deviceInfo.status === 'offline'}"></view>
  13. {{ deviceInfo.status === 'online' ? '在线' : '离线' }}
  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">{{ deviceInfo.lastUpdate }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 采集数据展示区域 - 气象站 -->
  45. <view class="data-section" v-if="deviceInfo.deviceType === 'weather'">
  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">{{ weatherData.updateTime || '2分钟前' }}</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">{{ weatherData.updateTime || '2分钟前' }}</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">{{ weatherData.updateTime || '2分钟前' }}</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">{{ weatherData.updateTime || '2分钟前' }}</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">{{ weatherData.updateTime || '2分钟前' }}</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">{{ weatherData.updateTime || '2分钟前' }}</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">{{ weatherData.updateTime || '2分钟前' }}</text>
  146. </view>
  147. </view>
  148. </view>
  149. <!-- 采集数据展示区域 - 土壤墒情 -->
  150. <view class="data-section" v-if="deviceInfo.deviceType === 'soil'">
  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">{{ soilData.updateTime || '5分钟前' }}</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">{{ soilData.updateTime || '5分钟前' }}</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">{{ soilData.updateTime || '5分钟前' }}</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">{{ soilData.updateTime || '5分钟前' }}</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">{{ soilData.updateTime || '5分钟前' }}</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">{{ soilData.updateTime || '5分钟前' }}</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">{{ soilData.updateTime || '5分钟前' }}</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 === 'high',
  277. 'alert-warning': item.level === 'medium',
  278. 'alert-info': item.level === 'low'
  279. }"
  280. >
  281. <view class="alert-item-icon">
  282. <image v-if="item.level === 'high'" src="/static/icons/warning_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
  283. <image v-else-if="item.level === 'medium'" 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 === 'high' ? '紧急' : item.level === 'medium' ? '警告' : '提示' }}
  290. </text>
  291. </view>
  292. <view class="alert-item-time">{{ 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. export default {
  303. data() {
  304. return {
  305. deviceInfo: {
  306. deviceId: 'COL1002',
  307. name: '采集设备-1',
  308. status: 'online',
  309. location: '西区B2地块',
  310. lastUpdate: '5分钟前',
  311. deviceType: 'weather' // 'weather' 或 'soil'
  312. },
  313. // 气象站数据
  314. weatherData: {
  315. temperature: '26.5',
  316. humidity: '68',
  317. rainfall: '0.0',
  318. windDirection: '东北',
  319. windSpeed: '3.2',
  320. pressure: '1013.5',
  321. illumination: '45000',
  322. updateTime: '2分钟前更新'
  323. },
  324. // 土壤墒情数据
  325. soilData: {
  326. temperature: '22.3',
  327. moisture: '35.8',
  328. nitrogen: '138.5',
  329. phosphorus: '42.7',
  330. potassium: '185.2',
  331. conductivity: '0.35',
  332. ph: '6.8',
  333. updateTime: '5分钟前更新'
  334. },
  335. // 模拟告警数据
  336. alertHistory: [
  337. { id: 1, time: '今天 13:05', type: '数据异常', status: '未处理', level: 'high' },
  338. { id: 2, time: '今天 09:30', type: '设备离线', status: '未处理', level: 'medium' },
  339. { id: 3, time: '昨天 15:45', type: '通信错误', status: '已处理', level: 'low' },
  340. { id: 4, time: '昨天 10:20', type: '电量不足', status: '未处理', level: 'low' }
  341. ],
  342. // 刷新状态
  343. isRefreshing: false,
  344. // 数值更新动画
  345. updatedFields: {
  346. weather: {},
  347. soil: {}
  348. }
  349. }
  350. },
  351. computed: {
  352. // 获取所有未处理的告警
  353. getUnhandledAlerts() {
  354. return this.alertHistory.filter(alert => alert.status === '未处理');
  355. }
  356. },
  357. onReady() {
  358. // 设置页面标题
  359. uni.setNavigationBarTitle({
  360. title: this.deviceInfo.name
  361. })
  362. },
  363. onLoad(options) {
  364. // 如果有传入设备ID,则获取设备信息
  365. if (options && options.id) {
  366. let deviceId = options.id;
  367. let deviceCode = options.code || '';
  368. // 如果有传入设备编码,优先使用编码判断设备类型
  369. if (deviceCode) {
  370. this.fetchDeviceInfoWithCode(deviceId, deviceCode);
  371. } else {
  372. this.fetchDeviceInfo(deviceId);
  373. }
  374. }
  375. },
  376. methods: {
  377. // 获取设备信息(带编码)
  378. fetchDeviceInfoWithCode(deviceId, deviceCode) {
  379. // 这里应该是API请求,暂时用模拟数据
  380. console.log('获取设备信息:', deviceId, deviceCode);
  381. // 模拟异步获取数据
  382. setTimeout(() => {
  383. // 根据设备编码判断是气象站还是土壤墒情
  384. if (deviceCode.startsWith('W')) {
  385. this.deviceInfo.deviceType = 'weather';
  386. // 保存旧数据用于比较
  387. const oldData = JSON.parse(JSON.stringify(this.weatherData));
  388. // 模拟更新气象数据
  389. this.weatherData = {
  390. temperature: (Math.random() * 10 + 20).toFixed(1),
  391. humidity: (Math.random() * 30 + 50).toFixed(0),
  392. rainfall: Math.random() < 0.3 ? (Math.random() * 5).toFixed(1) : '0.0',
  393. windDirection: ['东北', '东南', '西北', '西南', '东', '南', '西', '北'][Math.floor(Math.random() * 8)],
  394. windSpeed: (Math.random() * 5 + 1).toFixed(1),
  395. pressure: (Math.random() * 20 + 1000).toFixed(1),
  396. illumination: Math.floor(Math.random() * 50000 + 10000).toString(),
  397. updateTime: '刚刚更新'
  398. };
  399. // 检查哪些字段发生了变化
  400. this.updatedFields.weather = {};
  401. Object.keys(this.weatherData).forEach(key => {
  402. if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
  403. this.updatedFields.weather[key] = true;
  404. // 1秒后清除动画标记
  405. setTimeout(() => {
  406. this.$set(this.updatedFields.weather, key, false);
  407. }, 1000);
  408. }
  409. });
  410. } else if (deviceCode.startsWith('S')) {
  411. this.deviceInfo.deviceType = 'soil';
  412. // 保存旧数据用于比较
  413. const oldData = JSON.parse(JSON.stringify(this.soilData));
  414. // 模拟更新土壤数据
  415. this.soilData = {
  416. temperature: (Math.random() * 10 + 18).toFixed(1),
  417. moisture: (Math.random() * 30 + 20).toFixed(1),
  418. nitrogen: (Math.random() * 100 + 100).toFixed(1),
  419. phosphorus: (Math.random() * 50 + 20).toFixed(1),
  420. potassium: (Math.random() * 100 + 150).toFixed(1),
  421. conductivity: (Math.random() * 0.5 + 0.2).toFixed(2),
  422. ph: (Math.random() * 2 + 5.5).toFixed(1),
  423. updateTime: '刚刚更新'
  424. };
  425. // 检查哪些字段发生了变化
  426. this.updatedFields.soil = {};
  427. Object.keys(this.soilData).forEach(key => {
  428. if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
  429. this.updatedFields.soil[key] = true;
  430. // 1秒后清除动画标记
  431. setTimeout(() => {
  432. this.$set(this.updatedFields.soil, key, false);
  433. }, 1000);
  434. }
  435. });
  436. } else {
  437. // 如果编码无法判断类型,使用原有判断逻辑
  438. this.fetchDeviceInfo(deviceId);
  439. return;
  440. }
  441. // 更新设备基本信息
  442. this.deviceInfo.deviceId = deviceCode;
  443. this.deviceInfo.name = `采集设备-${deviceCode.slice(-4)}`;
  444. this.deviceInfo.lastUpdate = '刚刚';
  445. // 实际应该是API请求结果
  446. }, 500);
  447. },
  448. // 获取设备信息
  449. fetchDeviceInfo(deviceId) {
  450. // 这里应该是API请求,暂时用模拟数据
  451. console.log('获取设备信息:', deviceId)
  452. // 模拟异步获取数据
  453. setTimeout(() => {
  454. // 根据设备ID判断是气象站还是土壤墒情
  455. if (deviceId.startsWith('W') || deviceId.includes('weather')) {
  456. this.deviceInfo.deviceType = 'weather';
  457. // 保存旧数据用于比较
  458. const oldData = JSON.parse(JSON.stringify(this.weatherData));
  459. // 模拟更新气象数据
  460. this.weatherData = {
  461. temperature: (Math.random() * 10 + 20).toFixed(1),
  462. humidity: (Math.random() * 30 + 50).toFixed(0),
  463. rainfall: Math.random() < 0.3 ? (Math.random() * 5).toFixed(1) : '0.0',
  464. windDirection: ['东北', '东南', '西北', '西南', '东', '南', '西', '北'][Math.floor(Math.random() * 8)],
  465. windSpeed: (Math.random() * 5 + 1).toFixed(1),
  466. pressure: (Math.random() * 20 + 1000).toFixed(1),
  467. illumination: Math.floor(Math.random() * 50000 + 10000).toString(),
  468. updateTime: Math.floor(Math.random() * 10 + 1) + '分钟前更新'
  469. };
  470. // 检查哪些字段发生了变化
  471. this.updatedFields.weather = {};
  472. Object.keys(this.weatherData).forEach(key => {
  473. if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
  474. this.updatedFields.weather[key] = true;
  475. // 1秒后清除动画标记
  476. setTimeout(() => {
  477. this.$set(this.updatedFields.weather, key, false);
  478. }, 1000);
  479. }
  480. });
  481. } else if (deviceId.startsWith('S') || deviceId.includes('soil')) {
  482. this.deviceInfo.deviceType = 'soil';
  483. // 保存旧数据用于比较
  484. const oldData = JSON.parse(JSON.stringify(this.soilData));
  485. // 模拟更新土壤数据
  486. this.soilData = {
  487. temperature: (Math.random() * 10 + 18).toFixed(1),
  488. moisture: (Math.random() * 30 + 20).toFixed(1),
  489. nitrogen: (Math.random() * 100 + 100).toFixed(1),
  490. phosphorus: (Math.random() * 50 + 20).toFixed(1),
  491. potassium: (Math.random() * 100 + 150).toFixed(1),
  492. conductivity: (Math.random() * 0.5 + 0.2).toFixed(2),
  493. ph: (Math.random() * 2 + 5.5).toFixed(1),
  494. updateTime: Math.floor(Math.random() * 10 + 1) + '分钟前更新'
  495. };
  496. // 检查哪些字段发生了变化
  497. this.updatedFields.soil = {};
  498. Object.keys(this.soilData).forEach(key => {
  499. if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
  500. this.updatedFields.soil[key] = true;
  501. // 1秒后清除动画标记
  502. setTimeout(() => {
  503. this.$set(this.updatedFields.soil, key, false);
  504. }, 1000);
  505. }
  506. });
  507. } else {
  508. // 如果ID无法判断类型,根据偶数/奇数ID模拟不同类型
  509. const idNum = parseInt(deviceId.replace(/\D/g, ''));
  510. this.deviceInfo.deviceType = idNum % 2 === 0 ? 'weather' : 'soil';
  511. if (this.deviceInfo.deviceType === 'weather') {
  512. // 模拟更新气象数据
  513. this.weatherData = {
  514. temperature: (Math.random() * 10 + 20).toFixed(1),
  515. humidity: (Math.random() * 30 + 50).toFixed(0),
  516. rainfall: Math.random() < 0.3 ? (Math.random() * 5).toFixed(1) : '0.0',
  517. windDirection: ['东北', '东南', '西北', '西南', '东', '南', '西', '北'][Math.floor(Math.random() * 8)],
  518. windSpeed: (Math.random() * 5 + 1).toFixed(1),
  519. pressure: (Math.random() * 20 + 1000).toFixed(1),
  520. illumination: Math.floor(Math.random() * 50000 + 10000).toString(),
  521. updateTime: Math.floor(Math.random() * 10 + 1) + '分钟前更新'
  522. };
  523. } else {
  524. // 模拟更新土壤数据
  525. this.soilData = {
  526. temperature: (Math.random() * 10 + 18).toFixed(1),
  527. moisture: (Math.random() * 30 + 20).toFixed(1),
  528. nitrogen: (Math.random() * 100 + 100).toFixed(1),
  529. phosphorus: (Math.random() * 50 + 20).toFixed(1),
  530. potassium: (Math.random() * 100 + 150).toFixed(1),
  531. conductivity: (Math.random() * 0.5 + 0.2).toFixed(2),
  532. ph: (Math.random() * 2 + 5.5).toFixed(1),
  533. updateTime: Math.floor(Math.random() * 10 + 1) + '分钟前更新'
  534. };
  535. }
  536. }
  537. // 更新设备基本信息
  538. this.deviceInfo.deviceId = deviceId;
  539. this.deviceInfo.name = `采集设备-${deviceId.slice(-4)}`;
  540. this.deviceInfo.lastUpdate = (Math.floor(Math.random() * 5) + 1) + '分钟前';
  541. // 实际应该是API请求结果
  542. }, 500)
  543. },
  544. // 刷新数据
  545. refreshData() {
  546. if (this.isRefreshing) return;
  547. this.isRefreshing = true;
  548. uni.showLoading({
  549. title: '数据刷新中...'
  550. });
  551. setTimeout(() => {
  552. if (this.deviceInfo.deviceType === 'weather') {
  553. // 保存旧数据用于比较
  554. const oldData = JSON.parse(JSON.stringify(this.weatherData));
  555. // 模拟更新气象数据
  556. this.weatherData = {
  557. temperature: (Math.random() * 10 + 20).toFixed(1),
  558. humidity: (Math.random() * 30 + 50).toFixed(0),
  559. rainfall: Math.random() < 0.3 ? (Math.random() * 5).toFixed(1) : '0.0',
  560. windDirection: ['东北', '东南', '西北', '西南', '东', '南', '西', '北'][Math.floor(Math.random() * 8)],
  561. windSpeed: (Math.random() * 5 + 1).toFixed(1),
  562. pressure: (Math.random() * 20 + 1000).toFixed(1),
  563. illumination: Math.floor(Math.random() * 50000 + 10000).toString(),
  564. updateTime: '刚刚更新'
  565. };
  566. // 检查哪些字段发生了变化
  567. this.updatedFields.weather = {};
  568. Object.keys(this.weatherData).forEach(key => {
  569. if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
  570. this.updatedFields.weather[key] = true;
  571. // 1秒后清除动画标记
  572. setTimeout(() => {
  573. this.$set(this.updatedFields.weather, key, false);
  574. }, 1000);
  575. }
  576. });
  577. } else {
  578. // 保存旧数据用于比较
  579. const oldData = JSON.parse(JSON.stringify(this.soilData));
  580. // 模拟更新土壤数据
  581. this.soilData = {
  582. temperature: (Math.random() * 10 + 18).toFixed(1),
  583. moisture: (Math.random() * 30 + 20).toFixed(1),
  584. nitrogen: (Math.random() * 100 + 100).toFixed(1),
  585. phosphorus: (Math.random() * 50 + 20).toFixed(1),
  586. potassium: (Math.random() * 100 + 150).toFixed(1),
  587. conductivity: (Math.random() * 0.5 + 0.2).toFixed(2),
  588. ph: (Math.random() * 2 + 5.5).toFixed(1),
  589. updateTime: '刚刚更新'
  590. };
  591. // 检查哪些字段发生了变化
  592. this.updatedFields.soil = {};
  593. Object.keys(this.soilData).forEach(key => {
  594. if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
  595. this.updatedFields.soil[key] = true;
  596. // 1秒后清除动画标记
  597. setTimeout(() => {
  598. this.$set(this.updatedFields.soil, key, false);
  599. }, 1000);
  600. }
  601. });
  602. }
  603. this.deviceInfo.lastUpdate = '刚刚';
  604. uni.hideLoading();
  605. uni.showToast({
  606. title: '数据已更新',
  607. icon: 'success'
  608. });
  609. // 停止刷新动画
  610. setTimeout(() => {
  611. this.isRefreshing = false;
  612. }, 500);
  613. }, 1500);
  614. }
  615. }
  616. }
  617. </script>
  618. <style>
  619. /* 基础样式 */
  620. .container {
  621. display: flex;
  622. flex-direction: column;
  623. min-height: 100vh;
  624. background-color: #F8FCF9;
  625. padding-bottom: 30rpx;
  626. }
  627. /* 设备头部样式 */
  628. .device-header {
  629. background-color: #FFFFFF;
  630. border-radius: 20rpx;
  631. padding: 30rpx;
  632. margin: 30rpx 30rpx 30rpx;
  633. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  634. border: 1rpx solid rgba(210, 237, 217, 0.5);
  635. }
  636. .device-info-row {
  637. display: flex;
  638. justify-content: space-between;
  639. align-items: center;
  640. margin-bottom: 28rpx;
  641. }
  642. .device-name-container {
  643. display: flex;
  644. flex-direction: column;
  645. align-items: flex-start;
  646. }
  647. .refresh-btn {
  648. width: 48rpx;
  649. height: 48rpx;
  650. background-color: rgba(76, 175, 80, 0.1);
  651. border-radius: 50%;
  652. display: flex;
  653. align-items: center;
  654. justify-content: center;
  655. padding: 12rpx;
  656. transition: transform 0.3s ease;
  657. }
  658. .refresh-btn:active {
  659. transform: rotate(180deg);
  660. }
  661. .device-name {
  662. font-size: 36rpx;
  663. color: #333333;
  664. font-weight: 600;
  665. margin-bottom: 12rpx;
  666. }
  667. .status-tag {
  668. padding: 6rpx 16rpx 6rpx 28rpx;
  669. border-radius: 30rpx;
  670. font-size: 24rpx;
  671. font-weight: 500;
  672. flex-shrink: 0;
  673. position: relative;
  674. overflow: hidden;
  675. }
  676. .status-online {
  677. background-color: rgba(76, 175, 80, 0.1);
  678. color: #3BB44A;
  679. }
  680. .status-offline {
  681. background-color: rgba(245, 108, 108, 0.1);
  682. color: #F56C6C;
  683. padding-left: 28rpx;
  684. }
  685. .status-dot {
  686. position: absolute;
  687. width: 6rpx;
  688. height: 6rpx;
  689. background-color: #3BB44A;
  690. border-radius: 50%;
  691. top: 50%;
  692. left: 12rpx;
  693. transform: translateY(-50%);
  694. box-shadow: 0 0 4rpx rgba(76, 175, 80, 0.8);
  695. animation: blink 1.5s infinite;
  696. display: inline-block;
  697. }
  698. .status-dot.offline-dot {
  699. background-color: #F56C6C;
  700. box-shadow: 0 0 4rpx rgba(245, 108, 108, 0.8);
  701. }
  702. @keyframes blink {
  703. 0% {
  704. opacity: 0.4;
  705. }
  706. 50% {
  707. opacity: 1;
  708. }
  709. 100% {
  710. opacity: 0.4;
  711. }
  712. }
  713. .device-meta-row {
  714. display: flex;
  715. flex-direction: column;
  716. background-color: #F9FCFA;
  717. padding: 20rpx 24rpx;
  718. border-radius: 16rpx;
  719. border: 1rpx solid rgba(210, 237, 217, 0.8);
  720. }
  721. .device-meta-item {
  722. display: flex;
  723. align-items: center;
  724. font-size: 28rpx;
  725. margin-top: 18rpx;
  726. }
  727. .device-meta-item:first-child {
  728. margin-top: 0;
  729. }
  730. .meta-icon {
  731. width: 36rpx;
  732. height: 36rpx;
  733. display: flex;
  734. align-items: center;
  735. justify-content: center;
  736. margin-right: 12rpx;
  737. }
  738. .meta-label {
  739. color: #777777;
  740. min-width: 140rpx;
  741. font-size: 28rpx;
  742. }
  743. .meta-value {
  744. color: #333333;
  745. flex: 1;
  746. font-size: 28rpx;
  747. font-weight: 500;
  748. }
  749. /* 数据展示区域 */
  750. .data-section {
  751. margin: 0 30rpx 30rpx;
  752. background-color: #FFFFFF;
  753. border-radius: 24rpx;
  754. padding: 30rpx 24rpx;
  755. box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.05);
  756. border: 1rpx solid rgba(210, 237, 217, 0.5);
  757. }
  758. .section-title {
  759. font-size: 32rpx;
  760. font-weight: 600;
  761. color: #333333;
  762. margin-bottom: 20rpx;
  763. padding: 0 10rpx 16rpx;
  764. display: flex;
  765. align-items: center;
  766. position: relative;
  767. border-bottom: 2rpx solid rgba(59, 180, 74, 0.1);
  768. }
  769. .section-title::before {
  770. content: '';
  771. position: absolute;
  772. left: 0;
  773. top: 50%;
  774. transform: translateY(-50%);
  775. width: 8rpx;
  776. height: 32rpx;
  777. background: linear-gradient(to bottom, #4CAF50, #81C784);
  778. border-radius: 4rpx;
  779. margin-right: 10rpx;
  780. }
  781. .section-title text {
  782. margin-left: 20rpx;
  783. }
  784. .alert-badge {
  785. background-color: #F56C6C;
  786. color: #FFFFFF;
  787. font-size: 22rpx;
  788. border-radius: 30rpx;
  789. padding: 2rpx 12rpx;
  790. margin-left: 12rpx;
  791. font-weight: normal;
  792. min-width: 32rpx;
  793. text-align: center;
  794. }
  795. .data-grid {
  796. display: flex;
  797. flex-wrap: wrap;
  798. padding: 16rpx 0;
  799. width: 100%;
  800. margin: 0 -12rpx;
  801. }
  802. .data-item {
  803. width: calc(50% - 24rpx);
  804. margin: 0 12rpx 24rpx;
  805. display: flex;
  806. flex-direction: column;
  807. align-items: flex-start;
  808. justify-content: space-between;
  809. background: linear-gradient(to bottom right, #F9FFFB, #FFFFFF);
  810. border-radius: 24rpx;
  811. padding: 28rpx 24rpx;
  812. box-sizing: border-box;
  813. box-shadow: 0 6rpx 18rpx rgba(0, 0, 0, 0.06), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
  814. position: relative;
  815. border: 1rpx solid rgba(210, 237, 217, 0.6);
  816. transition: all 0.25s ease;
  817. overflow: hidden;
  818. min-height: 180rpx;
  819. }
  820. .data-item::before {
  821. content: '';
  822. position: absolute;
  823. top: 0;
  824. left: 0;
  825. width: 8rpx;
  826. height: 100%;
  827. background: linear-gradient(to bottom, #4CAF50, #81C784);
  828. opacity: 0.9;
  829. border-radius: 4rpx 0 0 4rpx;
  830. }
  831. .data-item-hover {
  832. transform: scale(1.02);
  833. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
  834. background: linear-gradient(to bottom right, #F7FFF9, #FFFFFF);
  835. }
  836. .data-label {
  837. font-size: 26rpx;
  838. color: #666666;
  839. margin-bottom: 22rpx;
  840. font-weight: 500;
  841. align-self: flex-start;
  842. }
  843. .data-value-container {
  844. display: flex;
  845. align-items: flex-end;
  846. width: 100%;
  847. margin-bottom: 18rpx;
  848. }
  849. .data-value {
  850. font-size: 40rpx;
  851. color: #222222;
  852. font-weight: 700;
  853. line-height: 1;
  854. }
  855. .data-value.no-data {
  856. font-size: 28rpx;
  857. color: #999999;
  858. font-weight: normal;
  859. }
  860. .data-unit {
  861. font-size: 24rpx;
  862. color: #999999;
  863. margin-left: 6rpx;
  864. padding-bottom: 6rpx;
  865. align-self: flex-end;
  866. }
  867. .data-time {
  868. font-size: 20rpx;
  869. color: #AAAAAA;
  870. width: 100%;
  871. text-align: right;
  872. }
  873. /* 数据更新动画 */
  874. @keyframes fadeNumberChange {
  875. 0% {
  876. opacity: 0.6;
  877. transform: scale(0.95);
  878. }
  879. 50% {
  880. opacity: 1;
  881. transform: scale(1.05);
  882. }
  883. 100% {
  884. opacity: 1;
  885. transform: scale(1);
  886. }
  887. }
  888. .data-value.updated {
  889. animation: fadeNumberChange 0.8s ease;
  890. }
  891. /* 异常值样式 */
  892. .value-warning {
  893. color: #E6A23C !important;
  894. }
  895. .value-alert {
  896. color: #F56C6C !important;
  897. }
  898. /* 点击波纹效果(可选)*/
  899. @keyframes ripple {
  900. 0% {
  901. transform: scale(0);
  902. opacity: 0.6;
  903. }
  904. 100% {
  905. transform: scale(2);
  906. opacity: 0;
  907. }
  908. }
  909. .data-item::after {
  910. content: '';
  911. position: absolute;
  912. top: 0;
  913. left: 0;
  914. right: 0;
  915. bottom: 0;
  916. background-color: rgba(76, 175, 80, 0.1);
  917. border-radius: 24rpx;
  918. opacity: 0;
  919. transition: opacity 0.3s;
  920. z-index: -1;
  921. }
  922. .data-item-hover::after {
  923. opacity: 1;
  924. }
  925. /* 告警信息列表 */
  926. .alerts-section {
  927. margin: 0 30rpx 30rpx;
  928. background-color: #FFFFFF;
  929. border-radius: 20rpx;
  930. padding: 30rpx 24rpx;
  931. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  932. border: 1rpx solid rgba(210, 237, 217, 0.5);
  933. }
  934. .alerts-section .section-title {
  935. display: flex;
  936. justify-content: space-between;
  937. align-items: center;
  938. font-size: 32rpx;
  939. font-weight: 600;
  940. color: #333333;
  941. margin-bottom: 24rpx;
  942. padding-bottom: 16rpx;
  943. border-bottom: 2rpx solid #f0f0f0;
  944. padding-left: 0;
  945. }
  946. .alerts-section .section-title::before {
  947. display: none;
  948. }
  949. .alert-badge {
  950. background-color: #F56C6C;
  951. color: #FFFFFF;
  952. font-size: 22rpx;
  953. border-radius: 30rpx;
  954. padding: 2rpx 12rpx;
  955. margin-left: 12rpx;
  956. font-weight: normal;
  957. min-width: 32rpx;
  958. text-align: center;
  959. }
  960. .alerts-list {
  961. display: flex;
  962. flex-direction: column;
  963. }
  964. .alert-item {
  965. display: flex;
  966. align-items: center;
  967. padding: 24rpx 20rpx;
  968. border-radius: 12rpx;
  969. margin-bottom: 16rpx;
  970. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  971. position: relative;
  972. border: 1rpx solid transparent;
  973. transition: transform 0.2s ease;
  974. }
  975. .alert-item:active {
  976. transform: scale(0.98);
  977. }
  978. .alert-urgent {
  979. background-color: #FEF3F3;
  980. border-left: 4rpx solid #F56C6C;
  981. border-color: rgba(245, 108, 108, 0.2);
  982. }
  983. .alert-warning {
  984. background-color: #FFF8E6;
  985. border-left: 4rpx solid #E6A23C;
  986. border-color: rgba(230, 162, 60, 0.2);
  987. }
  988. .alert-info {
  989. background-color: #F2FAF5;
  990. border-left: 4rpx solid #67C23A;
  991. border-color: rgba(103, 194, 58, 0.2);
  992. }
  993. .alert-item-icon {
  994. width: 50rpx;
  995. height: 50rpx;
  996. display: flex;
  997. align-items: center;
  998. justify-content: center;
  999. margin-right: 16rpx;
  1000. }
  1001. .alert-item-info {
  1002. flex: 1;
  1003. display: flex;
  1004. flex-direction: column;
  1005. }
  1006. .alert-item-type {
  1007. font-size: 28rpx;
  1008. color: #333333;
  1009. font-weight: 500;
  1010. margin-bottom: 8rpx;
  1011. }
  1012. .alert-item-level {
  1013. font-size: 24rpx;
  1014. color: #999999;
  1015. }
  1016. .alert-item-time {
  1017. font-size: 24rpx;
  1018. color: #999999;
  1019. margin-left: 16rpx;
  1020. min-width: 100rpx;
  1021. text-align: right;
  1022. }
  1023. .empty-alert {
  1024. padding: 60rpx 0;
  1025. display: flex;
  1026. justify-content: center;
  1027. align-items: center;
  1028. }
  1029. .empty-text {
  1030. font-size: 28rpx;
  1031. color: #999999;
  1032. }
  1033. /* 刷新按钮旋转动画 */
  1034. @keyframes spin {
  1035. 0% {
  1036. transform: rotate(0deg);
  1037. }
  1038. 100% {
  1039. transform: rotate(360deg);
  1040. }
  1041. }
  1042. .refresh-btn.refreshing {
  1043. animation: spin 1.2s linear infinite;
  1044. }
  1045. /* 土壤数据标题样式调整 */
  1046. .soil-title, .data-title {
  1047. display: flex;
  1048. align-items: center;
  1049. position: relative;
  1050. padding-left: 24rpx;
  1051. }
  1052. .soil-title::before, .data-title::before {
  1053. content: '';
  1054. position: absolute;
  1055. left: 0;
  1056. top: 50%;
  1057. transform: translateY(-50%);
  1058. width: 8rpx;
  1059. height: 36rpx;
  1060. background: linear-gradient(to bottom, #4CAF50, #81C784);
  1061. border-radius: 4rpx;
  1062. }
  1063. .soil-title text, .data-title text {
  1064. margin-left: 16rpx;
  1065. font-weight: 600;
  1066. }
  1067. </style>