detail-collector.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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-list {
  935. display: flex;
  936. flex-direction: column;
  937. }
  938. .alert-item {
  939. display: flex;
  940. align-items: center;
  941. padding: 24rpx 20rpx;
  942. border-radius: 12rpx;
  943. margin-bottom: 16rpx;
  944. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  945. position: relative;
  946. border: 1rpx solid transparent;
  947. transition: transform 0.2s ease;
  948. }
  949. .alert-item:active {
  950. transform: scale(0.98);
  951. }
  952. .alert-urgent {
  953. background-color: #FEF3F3;
  954. border-left: 4rpx solid #F56C6C;
  955. border-color: rgba(245, 108, 108, 0.2);
  956. }
  957. .alert-warning {
  958. background-color: #FFF8E6;
  959. border-left: 4rpx solid #E6A23C;
  960. border-color: rgba(230, 162, 60, 0.2);
  961. }
  962. .alert-info {
  963. background-color: #F2FAF5;
  964. border-left: 4rpx solid #67C23A;
  965. border-color: rgba(103, 194, 58, 0.2);
  966. }
  967. .alert-item-icon {
  968. width: 50rpx;
  969. height: 50rpx;
  970. display: flex;
  971. align-items: center;
  972. justify-content: center;
  973. margin-right: 16rpx;
  974. }
  975. .alert-item-info {
  976. flex: 1;
  977. display: flex;
  978. flex-direction: column;
  979. }
  980. .alert-item-type {
  981. font-size: 28rpx;
  982. color: #333333;
  983. font-weight: 500;
  984. margin-bottom: 8rpx;
  985. }
  986. .alert-item-level {
  987. font-size: 24rpx;
  988. color: #999999;
  989. }
  990. .alert-item-time {
  991. font-size: 24rpx;
  992. color: #999999;
  993. margin-left: 16rpx;
  994. min-width: 100rpx;
  995. text-align: right;
  996. }
  997. .empty-alert {
  998. padding: 60rpx 0;
  999. display: flex;
  1000. justify-content: center;
  1001. align-items: center;
  1002. }
  1003. .empty-text {
  1004. font-size: 28rpx;
  1005. color: #999999;
  1006. }
  1007. /* 刷新按钮旋转动画 */
  1008. @keyframes spin {
  1009. 0% {
  1010. transform: rotate(0deg);
  1011. }
  1012. 100% {
  1013. transform: rotate(360deg);
  1014. }
  1015. }
  1016. .refresh-btn.refreshing {
  1017. animation: spin 1.2s linear infinite;
  1018. }
  1019. /* 土壤数据标题样式调整 */
  1020. .soil-title, .data-title {
  1021. display: flex;
  1022. align-items: center;
  1023. position: relative;
  1024. padding-left: 24rpx;
  1025. }
  1026. .soil-title::before, .data-title::before {
  1027. content: '';
  1028. position: absolute;
  1029. left: 0;
  1030. top: 50%;
  1031. transform: translateY(-50%);
  1032. width: 8rpx;
  1033. height: 36rpx;
  1034. background: linear-gradient(to bottom, #4CAF50, #81C784);
  1035. border-radius: 4rpx;
  1036. }
  1037. .soil-title text, .data-title text {
  1038. margin-left: 16rpx;
  1039. font-weight: 600;
  1040. }
  1041. </style>