| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208 |
- <template>
- <view class="container">
- <!-- 设备头部信息区域 -->
- <view class="device-header">
- <view class="device-info-row">
- <view class="device-name-container">
- <text class="device-name">{{ deviceInfo.name }}</text>
- <view
- class="status-tag"
- :class="deviceInfo.status === 'online' ? 'status-online' : 'status-offline'"
- >
- <view class="status-dot" :class="{'offline-dot': deviceInfo.status === 'offline'}"></view>
- {{ deviceInfo.status === 'online' ? '在线' : '离线' }}
- </view>
- </view>
-
- <view class="refresh-btn" :class="{'refreshing': isRefreshing}" @tap="refreshData">
- <image src="/static/icons/refresh_icon.png" mode="aspectFit" style="width: 22px; height: 22px;"></image>
- </view>
- </view>
-
- <view class="device-meta-row">
- <view class="device-meta-item">
- <view class="meta-icon">
- <image src="/static/icons/device_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
- </view>
- <text class="meta-label">设备编号:</text>
- <text class="meta-value">{{ deviceInfo.deviceId }}</text>
- </view>
-
- <view class="device-meta-item">
- <view class="meta-icon">
- <image src="/static/icons/location_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
- </view>
- <text class="meta-label">安装位置:</text>
- <text class="meta-value">{{ deviceInfo.location }}</text>
- </view>
-
- <view class="device-meta-item">
- <view class="meta-icon">
- <image src="/static/icons/clock_icon.png" mode="aspectFit" style="width: 36rpx; height: 36rpx;"></image>
- </view>
- <text class="meta-label">最近更新:</text>
- <text class="meta-value">{{ deviceInfo.lastUpdate }}</text>
- </view>
- </view>
- </view>
-
- <!-- 采集数据展示区域 - 气象站 -->
- <view class="data-section" v-if="deviceInfo.deviceType === 'weather'">
- <view class="section-title data-title">
- <text>气象数据</text>
- </view>
-
- <view class="data-grid">
- <!-- 气温 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">气温</text>
- <view class="data-value-container">
- <template v-if="weatherData.temperature">
- <text class="data-value" :class="{
- 'updated': updatedFields.weather && updatedFields.weather.temperature,
- 'value-warning': parseFloat(weatherData.temperature) > 35 || parseFloat(weatherData.temperature) < 5
- }">{{ weatherData.temperature }}</text>
- <text class="data-unit">℃</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ weatherData.updateTime || '2分钟前' }}</text>
- </view>
-
- <!-- 湿度 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">湿度</text>
- <view class="data-value-container">
- <template v-if="weatherData.humidity">
- <text class="data-value" :class="{
- 'updated': updatedFields.weather && updatedFields.weather.humidity,
- 'value-warning': parseFloat(weatherData.humidity) > 85
- }">{{ weatherData.humidity }}</text>
- <text class="data-unit">%</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ weatherData.updateTime || '2分钟前' }}</text>
- </view>
-
- <!-- 降雨量 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">降雨量</text>
- <view class="data-value-container">
- <template v-if="weatherData.rainfall">
- <text class="data-value" :class="{
- 'updated': updatedFields.weather && updatedFields.weather.rainfall,
- 'value-alert': parseFloat(weatherData.rainfall) > 10
- }">{{ weatherData.rainfall }}</text>
- <text class="data-unit">mm</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ weatherData.updateTime || '2分钟前' }}</text>
- </view>
-
- <!-- 风向 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">风向</text>
- <view class="data-value-container">
- <template v-if="weatherData.windDirection">
- <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.windDirection}">{{ weatherData.windDirection }}</text>
- <text class="data-unit"></text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ weatherData.updateTime || '2分钟前' }}</text>
- </view>
-
- <!-- 风速 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">风速</text>
- <view class="data-value-container">
- <template v-if="weatherData.windSpeed">
- <text class="data-value" :class="{
- 'updated': updatedFields.weather && updatedFields.weather.windSpeed,
- 'value-alert': parseFloat(weatherData.windSpeed) > 8,
- 'value-warning': parseFloat(weatherData.windSpeed) > 5 && parseFloat(weatherData.windSpeed) <= 8
- }">{{ weatherData.windSpeed }}</text>
- <text class="data-unit">m/s</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ weatherData.updateTime || '2分钟前' }}</text>
- </view>
-
- <!-- 气压 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">气压</text>
- <view class="data-value-container">
- <template v-if="weatherData.pressure">
- <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.pressure}">{{ weatherData.pressure }}</text>
- <text class="data-unit">hPa</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ weatherData.updateTime || '2分钟前' }}</text>
- </view>
-
- <!-- 光照 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">光照</text>
- <view class="data-value-container">
- <template v-if="weatherData.illumination">
- <text class="data-value" :class="{'updated': updatedFields.weather && updatedFields.weather.illumination}">{{ weatherData.illumination }}</text>
- <text class="data-unit">lux</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ weatherData.updateTime || '2分钟前' }}</text>
- </view>
- </view>
- </view>
-
- <!-- 采集数据展示区域 - 土壤墒情 -->
- <view class="data-section" v-if="deviceInfo.deviceType === 'soil'">
- <view class="section-title soil-title">
- <text>土壤数据</text>
- </view>
-
- <view class="data-grid">
- <!-- 土壤温度 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">土壤温度</text>
- <view class="data-value-container">
- <template v-if="soilData.temperature">
- <text class="data-value" :class="{
- 'updated': updatedFields.soil && updatedFields.soil.temperature,
- 'value-warning': parseFloat(soilData.temperature) > 30 || parseFloat(soilData.temperature) < 5
- }">{{ soilData.temperature }}</text>
- <text class="data-unit">℃</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ soilData.updateTime || '5分钟前' }}</text>
- </view>
-
- <!-- 土壤湿度 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">土壤湿度</text>
- <view class="data-value-container">
- <template v-if="soilData.moisture">
- <text class="data-value" :class="{
- 'updated': updatedFields.soil && updatedFields.soil.moisture,
- 'value-warning': parseFloat(soilData.moisture) < 20,
- 'value-alert': parseFloat(soilData.moisture) < 10
- }">{{ soilData.moisture }}</text>
- <text class="data-unit">%</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ soilData.updateTime || '5分钟前' }}</text>
- </view>
-
- <!-- 氮含量 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">氮含量</text>
- <view class="data-value-container">
- <template v-if="soilData.nitrogen">
- <text class="data-value" :class="{
- 'updated': updatedFields.soil && updatedFields.soil.nitrogen,
- 'value-warning': parseFloat(soilData.nitrogen) < 120
- }">{{ soilData.nitrogen }}</text>
- <text class="data-unit">mg/kg</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ soilData.updateTime || '5分钟前' }}</text>
- </view>
-
- <!-- 磷含量 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">磷含量</text>
- <view class="data-value-container">
- <template v-if="soilData.phosphorus">
- <text class="data-value" :class="{
- 'updated': updatedFields.soil && updatedFields.soil.phosphorus,
- 'value-warning': parseFloat(soilData.phosphorus) < 30
- }">{{ soilData.phosphorus }}</text>
- <text class="data-unit">mg/kg</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ soilData.updateTime || '5分钟前' }}</text>
- </view>
-
- <!-- 钾含量 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">钾含量</text>
- <view class="data-value-container">
- <template v-if="soilData.potassium">
- <text class="data-value" :class="{
- 'updated': updatedFields.soil && updatedFields.soil.potassium,
- 'value-warning': parseFloat(soilData.potassium) < 150
- }">{{ soilData.potassium }}</text>
- <text class="data-unit">mg/kg</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ soilData.updateTime || '5分钟前' }}</text>
- </view>
-
- <!-- 土壤电导率 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">电导率</text>
- <view class="data-value-container">
- <template v-if="soilData.conductivity">
- <text class="data-value" :class="{
- 'updated': updatedFields.soil && updatedFields.soil.conductivity,
- 'value-alert': parseFloat(soilData.conductivity) > 0.8
- }">{{ soilData.conductivity }}</text>
- <text class="data-unit">μS/cm</text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ soilData.updateTime || '5分钟前' }}</text>
- </view>
-
- <!-- PH值 -->
- <view class="data-item" hover-class="data-item-hover">
- <text class="data-label">PH值</text>
- <view class="data-value-container">
- <template v-if="soilData.ph">
- <text class="data-value" :class="{
- 'updated': updatedFields.soil && updatedFields.soil.ph,
- 'value-warning': parseFloat(soilData.ph) < 5.5 || parseFloat(soilData.ph) > 8.5,
- 'value-alert': parseFloat(soilData.ph) < 4.5 || parseFloat(soilData.ph) > 9
- }">{{ soilData.ph }}</text>
- <text class="data-unit"></text>
- </template>
- <text v-else class="data-value no-data">暂无数据</text>
- </view>
- <text class="data-time">{{ soilData.updateTime || '5分钟前' }}</text>
- </view>
- </view>
- </view>
-
- <!-- 告警信息列表 -->
- <view class="alerts-section">
- <view class="section-title">
- <text>告警信息</text>
- <view class="alert-badge" v-if="getUnhandledAlerts.length > 0">{{ getUnhandledAlerts.length }}</view>
- </view>
-
- <view class="alerts-list" v-if="getUnhandledAlerts.length > 0">
- <view
- v-for="(item, index) in getUnhandledAlerts.slice(0, 3)"
- :key="index"
- class="alert-item"
- :class="{
- 'alert-urgent': item.level === 'high',
- 'alert-warning': item.level === 'medium',
- 'alert-info': item.level === 'low'
- }"
- >
- <view class="alert-item-icon">
- <image v-if="item.level === 'high'" src="/static/icons/warning_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
- <image v-else-if="item.level === 'medium'" src="/static/icons/info_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
- <image v-else src="/static/icons/success_icon.png" mode="aspectFit" style="width: 24px; height: 24px;"></image>
- </view>
-
- <view class="alert-item-info">
- <text class="alert-item-type">{{ item.type }}</text>
- <text class="alert-item-level">
- {{ item.level === 'high' ? '紧急' : item.level === 'medium' ? '警告' : '提示' }}
- </text>
- </view>
-
- <view class="alert-item-time">{{ item.time }}</view>
- </view>
- </view>
-
- <view v-else class="empty-alert">
- <text class="empty-text">暂无告警信息</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- deviceInfo: {
- deviceId: 'COL1002',
- name: '采集设备-1',
- status: 'online',
- location: '西区B2地块',
- lastUpdate: '5分钟前',
- deviceType: 'weather' // 'weather' 或 'soil'
- },
-
- // 气象站数据
- weatherData: {
- temperature: '26.5',
- humidity: '68',
- rainfall: '0.0',
- windDirection: '东北',
- windSpeed: '3.2',
- pressure: '1013.5',
- illumination: '45000',
- updateTime: '2分钟前更新'
- },
-
- // 土壤墒情数据
- soilData: {
- temperature: '22.3',
- moisture: '35.8',
- nitrogen: '138.5',
- phosphorus: '42.7',
- potassium: '185.2',
- conductivity: '0.35',
- ph: '6.8',
- updateTime: '5分钟前更新'
- },
-
- // 模拟告警数据
- alertHistory: [
- { id: 1, time: '今天 13:05', type: '数据异常', status: '未处理', level: 'high' },
- { id: 2, time: '今天 09:30', type: '设备离线', status: '未处理', level: 'medium' },
- { id: 3, time: '昨天 15:45', type: '通信错误', status: '已处理', level: 'low' },
- { id: 4, time: '昨天 10:20', type: '电量不足', status: '未处理', level: 'low' }
- ],
-
- // 刷新状态
- isRefreshing: false,
-
- // 数值更新动画
- updatedFields: {
- weather: {},
- soil: {}
- }
- }
- },
-
- computed: {
- // 获取所有未处理的告警
- getUnhandledAlerts() {
- return this.alertHistory.filter(alert => alert.status === '未处理');
- }
- },
-
- onReady() {
- // 设置页面标题
- uni.setNavigationBarTitle({
- title: this.deviceInfo.name
- })
- },
-
- onLoad(options) {
- // 如果有传入设备ID,则获取设备信息
- if (options && options.id) {
- let deviceId = options.id;
- let deviceCode = options.code || '';
-
- // 如果有传入设备编码,优先使用编码判断设备类型
- if (deviceCode) {
- this.fetchDeviceInfoWithCode(deviceId, deviceCode);
- } else {
- this.fetchDeviceInfo(deviceId);
- }
- }
- },
-
- methods: {
- // 获取设备信息(带编码)
- fetchDeviceInfoWithCode(deviceId, deviceCode) {
- // 这里应该是API请求,暂时用模拟数据
- console.log('获取设备信息:', deviceId, deviceCode);
-
- // 模拟异步获取数据
- setTimeout(() => {
- // 根据设备编码判断是气象站还是土壤墒情
- if (deviceCode.startsWith('W')) {
- this.deviceInfo.deviceType = 'weather';
-
- // 保存旧数据用于比较
- const oldData = JSON.parse(JSON.stringify(this.weatherData));
-
- // 模拟更新气象数据
- this.weatherData = {
- temperature: (Math.random() * 10 + 20).toFixed(1),
- humidity: (Math.random() * 30 + 50).toFixed(0),
- rainfall: Math.random() < 0.3 ? (Math.random() * 5).toFixed(1) : '0.0',
- windDirection: ['东北', '东南', '西北', '西南', '东', '南', '西', '北'][Math.floor(Math.random() * 8)],
- windSpeed: (Math.random() * 5 + 1).toFixed(1),
- pressure: (Math.random() * 20 + 1000).toFixed(1),
- illumination: Math.floor(Math.random() * 50000 + 10000).toString(),
- updateTime: '刚刚更新'
- };
-
- // 检查哪些字段发生了变化
- this.updatedFields.weather = {};
- Object.keys(this.weatherData).forEach(key => {
- if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
- this.updatedFields.weather[key] = true;
-
- // 1秒后清除动画标记
- setTimeout(() => {
- this.$set(this.updatedFields.weather, key, false);
- }, 1000);
- }
- });
-
- } else if (deviceCode.startsWith('S')) {
- this.deviceInfo.deviceType = 'soil';
-
- // 保存旧数据用于比较
- const oldData = JSON.parse(JSON.stringify(this.soilData));
-
- // 模拟更新土壤数据
- this.soilData = {
- temperature: (Math.random() * 10 + 18).toFixed(1),
- moisture: (Math.random() * 30 + 20).toFixed(1),
- nitrogen: (Math.random() * 100 + 100).toFixed(1),
- phosphorus: (Math.random() * 50 + 20).toFixed(1),
- potassium: (Math.random() * 100 + 150).toFixed(1),
- conductivity: (Math.random() * 0.5 + 0.2).toFixed(2),
- ph: (Math.random() * 2 + 5.5).toFixed(1),
- updateTime: '刚刚更新'
- };
-
- // 检查哪些字段发生了变化
- this.updatedFields.soil = {};
- Object.keys(this.soilData).forEach(key => {
- if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
- this.updatedFields.soil[key] = true;
-
- // 1秒后清除动画标记
- setTimeout(() => {
- this.$set(this.updatedFields.soil, key, false);
- }, 1000);
- }
- });
-
- } else {
- // 如果编码无法判断类型,使用原有判断逻辑
- this.fetchDeviceInfo(deviceId);
- return;
- }
-
- // 更新设备基本信息
- this.deviceInfo.deviceId = deviceCode;
- this.deviceInfo.name = `采集设备-${deviceCode.slice(-4)}`;
- this.deviceInfo.lastUpdate = '刚刚';
-
- // 实际应该是API请求结果
- }, 500);
- },
-
- // 获取设备信息
- fetchDeviceInfo(deviceId) {
- // 这里应该是API请求,暂时用模拟数据
- console.log('获取设备信息:', deviceId)
-
- // 模拟异步获取数据
- setTimeout(() => {
- // 根据设备ID判断是气象站还是土壤墒情
- if (deviceId.startsWith('W') || deviceId.includes('weather')) {
- this.deviceInfo.deviceType = 'weather';
-
- // 保存旧数据用于比较
- const oldData = JSON.parse(JSON.stringify(this.weatherData));
-
- // 模拟更新气象数据
- this.weatherData = {
- temperature: (Math.random() * 10 + 20).toFixed(1),
- humidity: (Math.random() * 30 + 50).toFixed(0),
- rainfall: Math.random() < 0.3 ? (Math.random() * 5).toFixed(1) : '0.0',
- windDirection: ['东北', '东南', '西北', '西南', '东', '南', '西', '北'][Math.floor(Math.random() * 8)],
- windSpeed: (Math.random() * 5 + 1).toFixed(1),
- pressure: (Math.random() * 20 + 1000).toFixed(1),
- illumination: Math.floor(Math.random() * 50000 + 10000).toString(),
- updateTime: Math.floor(Math.random() * 10 + 1) + '分钟前更新'
- };
-
- // 检查哪些字段发生了变化
- this.updatedFields.weather = {};
- Object.keys(this.weatherData).forEach(key => {
- if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
- this.updatedFields.weather[key] = true;
-
- // 1秒后清除动画标记
- setTimeout(() => {
- this.$set(this.updatedFields.weather, key, false);
- }, 1000);
- }
- });
-
- } else if (deviceId.startsWith('S') || deviceId.includes('soil')) {
- this.deviceInfo.deviceType = 'soil';
-
- // 保存旧数据用于比较
- const oldData = JSON.parse(JSON.stringify(this.soilData));
-
- // 模拟更新土壤数据
- this.soilData = {
- temperature: (Math.random() * 10 + 18).toFixed(1),
- moisture: (Math.random() * 30 + 20).toFixed(1),
- nitrogen: (Math.random() * 100 + 100).toFixed(1),
- phosphorus: (Math.random() * 50 + 20).toFixed(1),
- potassium: (Math.random() * 100 + 150).toFixed(1),
- conductivity: (Math.random() * 0.5 + 0.2).toFixed(2),
- ph: (Math.random() * 2 + 5.5).toFixed(1),
- updateTime: Math.floor(Math.random() * 10 + 1) + '分钟前更新'
- };
-
- // 检查哪些字段发生了变化
- this.updatedFields.soil = {};
- Object.keys(this.soilData).forEach(key => {
- if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
- this.updatedFields.soil[key] = true;
-
- // 1秒后清除动画标记
- setTimeout(() => {
- this.$set(this.updatedFields.soil, key, false);
- }, 1000);
- }
- });
-
- } else {
- // 如果ID无法判断类型,根据偶数/奇数ID模拟不同类型
- const idNum = parseInt(deviceId.replace(/\D/g, ''));
- this.deviceInfo.deviceType = idNum % 2 === 0 ? 'weather' : 'soil';
-
- if (this.deviceInfo.deviceType === 'weather') {
- // 模拟更新气象数据
- this.weatherData = {
- temperature: (Math.random() * 10 + 20).toFixed(1),
- humidity: (Math.random() * 30 + 50).toFixed(0),
- rainfall: Math.random() < 0.3 ? (Math.random() * 5).toFixed(1) : '0.0',
- windDirection: ['东北', '东南', '西北', '西南', '东', '南', '西', '北'][Math.floor(Math.random() * 8)],
- windSpeed: (Math.random() * 5 + 1).toFixed(1),
- pressure: (Math.random() * 20 + 1000).toFixed(1),
- illumination: Math.floor(Math.random() * 50000 + 10000).toString(),
- updateTime: Math.floor(Math.random() * 10 + 1) + '分钟前更新'
- };
- } else {
- // 模拟更新土壤数据
- this.soilData = {
- temperature: (Math.random() * 10 + 18).toFixed(1),
- moisture: (Math.random() * 30 + 20).toFixed(1),
- nitrogen: (Math.random() * 100 + 100).toFixed(1),
- phosphorus: (Math.random() * 50 + 20).toFixed(1),
- potassium: (Math.random() * 100 + 150).toFixed(1),
- conductivity: (Math.random() * 0.5 + 0.2).toFixed(2),
- ph: (Math.random() * 2 + 5.5).toFixed(1),
- updateTime: Math.floor(Math.random() * 10 + 1) + '分钟前更新'
- };
- }
- }
-
- // 更新设备基本信息
- this.deviceInfo.deviceId = deviceId;
- this.deviceInfo.name = `采集设备-${deviceId.slice(-4)}`;
- this.deviceInfo.lastUpdate = (Math.floor(Math.random() * 5) + 1) + '分钟前';
-
- // 实际应该是API请求结果
- }, 500)
- },
-
- // 刷新数据
- refreshData() {
- if (this.isRefreshing) return;
-
- this.isRefreshing = true;
-
- uni.showLoading({
- title: '数据刷新中...'
- });
-
- setTimeout(() => {
- if (this.deviceInfo.deviceType === 'weather') {
- // 保存旧数据用于比较
- const oldData = JSON.parse(JSON.stringify(this.weatherData));
-
- // 模拟更新气象数据
- this.weatherData = {
- temperature: (Math.random() * 10 + 20).toFixed(1),
- humidity: (Math.random() * 30 + 50).toFixed(0),
- rainfall: Math.random() < 0.3 ? (Math.random() * 5).toFixed(1) : '0.0',
- windDirection: ['东北', '东南', '西北', '西南', '东', '南', '西', '北'][Math.floor(Math.random() * 8)],
- windSpeed: (Math.random() * 5 + 1).toFixed(1),
- pressure: (Math.random() * 20 + 1000).toFixed(1),
- illumination: Math.floor(Math.random() * 50000 + 10000).toString(),
- updateTime: '刚刚更新'
- };
-
- // 检查哪些字段发生了变化
- this.updatedFields.weather = {};
- Object.keys(this.weatherData).forEach(key => {
- if (key !== 'updateTime' && this.weatherData[key] !== oldData[key]) {
- this.updatedFields.weather[key] = true;
-
- // 1秒后清除动画标记
- setTimeout(() => {
- this.$set(this.updatedFields.weather, key, false);
- }, 1000);
- }
- });
-
- } else {
- // 保存旧数据用于比较
- const oldData = JSON.parse(JSON.stringify(this.soilData));
-
- // 模拟更新土壤数据
- this.soilData = {
- temperature: (Math.random() * 10 + 18).toFixed(1),
- moisture: (Math.random() * 30 + 20).toFixed(1),
- nitrogen: (Math.random() * 100 + 100).toFixed(1),
- phosphorus: (Math.random() * 50 + 20).toFixed(1),
- potassium: (Math.random() * 100 + 150).toFixed(1),
- conductivity: (Math.random() * 0.5 + 0.2).toFixed(2),
- ph: (Math.random() * 2 + 5.5).toFixed(1),
- updateTime: '刚刚更新'
- };
-
- // 检查哪些字段发生了变化
- this.updatedFields.soil = {};
- Object.keys(this.soilData).forEach(key => {
- if (key !== 'updateTime' && this.soilData[key] !== oldData[key]) {
- this.updatedFields.soil[key] = true;
-
- // 1秒后清除动画标记
- setTimeout(() => {
- this.$set(this.updatedFields.soil, key, false);
- }, 1000);
- }
- });
- }
-
- this.deviceInfo.lastUpdate = '刚刚';
-
- uni.hideLoading();
- uni.showToast({
- title: '数据已更新',
- icon: 'success'
- });
-
- // 停止刷新动画
- setTimeout(() => {
- this.isRefreshing = false;
- }, 500);
- }, 1500);
- }
- }
- }
- </script>
- <style>
- /* 基础样式 */
- .container {
- display: flex;
- flex-direction: column;
- min-height: 100vh;
- background-color: #F8FCF9;
- padding-bottom: 30rpx;
- }
- /* 设备头部样式 */
- .device-header {
- background-color: #FFFFFF;
- border-radius: 20rpx;
- padding: 30rpx;
- margin: 30rpx 30rpx 30rpx;
- box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
- border: 1rpx solid rgba(210, 237, 217, 0.5);
- }
- .device-info-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 28rpx;
- }
- .device-name-container {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- }
- .refresh-btn {
- width: 48rpx;
- height: 48rpx;
- background-color: rgba(76, 175, 80, 0.1);
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 12rpx;
- transition: transform 0.3s ease;
- }
- .refresh-btn:active {
- transform: rotate(180deg);
- }
- .device-name {
- font-size: 36rpx;
- color: #333333;
- font-weight: 600;
- margin-bottom: 12rpx;
- }
- .status-tag {
- padding: 6rpx 16rpx 6rpx 28rpx;
- border-radius: 30rpx;
- font-size: 24rpx;
- font-weight: 500;
- flex-shrink: 0;
- position: relative;
- overflow: hidden;
- }
- .status-online {
- background-color: rgba(76, 175, 80, 0.1);
- color: #3BB44A;
- }
- .status-offline {
- background-color: rgba(245, 108, 108, 0.1);
- color: #F56C6C;
- padding-left: 28rpx;
- }
- .status-dot {
- position: absolute;
- width: 6rpx;
- height: 6rpx;
- background-color: #3BB44A;
- border-radius: 50%;
- top: 50%;
- left: 12rpx;
- transform: translateY(-50%);
- box-shadow: 0 0 4rpx rgba(76, 175, 80, 0.8);
- animation: blink 1.5s infinite;
- display: inline-block;
- }
- .status-dot.offline-dot {
- background-color: #F56C6C;
- box-shadow: 0 0 4rpx rgba(245, 108, 108, 0.8);
- }
- @keyframes blink {
- 0% {
- opacity: 0.4;
- }
- 50% {
- opacity: 1;
- }
- 100% {
- opacity: 0.4;
- }
- }
- .device-meta-row {
- display: flex;
- flex-direction: column;
- background-color: #F9FCFA;
- padding: 20rpx 24rpx;
- border-radius: 16rpx;
- border: 1rpx solid rgba(210, 237, 217, 0.8);
- }
- .device-meta-item {
- display: flex;
- align-items: center;
- font-size: 28rpx;
- margin-top: 18rpx;
- }
- .device-meta-item:first-child {
- margin-top: 0;
- }
- .meta-icon {
- width: 36rpx;
- height: 36rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- margin-right: 12rpx;
- }
- .meta-label {
- color: #777777;
- min-width: 140rpx;
- font-size: 28rpx;
- }
- .meta-value {
- color: #333333;
- flex: 1;
- font-size: 28rpx;
- font-weight: 500;
- }
- /* 数据展示区域 */
- .data-section {
- margin: 0 30rpx 30rpx;
- background-color: #FFFFFF;
- border-radius: 24rpx;
- padding: 30rpx 24rpx;
- box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.05);
- border: 1rpx solid rgba(210, 237, 217, 0.5);
- }
- .section-title {
- font-size: 32rpx;
- font-weight: 600;
- color: #333333;
- margin-bottom: 20rpx;
- padding: 0 10rpx 16rpx;
- display: flex;
- align-items: center;
- position: relative;
- border-bottom: 2rpx solid rgba(59, 180, 74, 0.1);
- }
- .section-title::before {
- content: '';
- position: absolute;
- left: 0;
- top: 50%;
- transform: translateY(-50%);
- width: 8rpx;
- height: 32rpx;
- background: linear-gradient(to bottom, #4CAF50, #81C784);
- border-radius: 4rpx;
- margin-right: 10rpx;
- }
- .section-title text {
- margin-left: 20rpx;
- }
- .alert-badge {
- background-color: #F56C6C;
- color: #FFFFFF;
- font-size: 22rpx;
- border-radius: 30rpx;
- padding: 2rpx 12rpx;
- margin-left: 12rpx;
- font-weight: normal;
- min-width: 32rpx;
- text-align: center;
- }
- .data-grid {
- display: flex;
- flex-wrap: wrap;
- padding: 16rpx 0;
- width: 100%;
- margin: 0 -12rpx;
- }
- .data-item {
- width: calc(50% - 24rpx);
- margin: 0 12rpx 24rpx;
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- justify-content: space-between;
- background: linear-gradient(to bottom right, #F9FFFB, #FFFFFF);
- border-radius: 24rpx;
- padding: 28rpx 24rpx;
- box-sizing: border-box;
- box-shadow: 0 6rpx 18rpx rgba(0, 0, 0, 0.06), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
- position: relative;
- border: 1rpx solid rgba(210, 237, 217, 0.6);
- transition: all 0.25s ease;
- overflow: hidden;
- min-height: 180rpx;
- }
- .data-item::before {
- content: '';
- position: absolute;
- top: 0;
- left: 0;
- width: 8rpx;
- height: 100%;
- background: linear-gradient(to bottom, #4CAF50, #81C784);
- opacity: 0.9;
- border-radius: 4rpx 0 0 4rpx;
- }
- .data-item-hover {
- transform: scale(1.02);
- box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08), inset 0 1rpx 3rpx rgba(255, 255, 255, 0.8);
- background: linear-gradient(to bottom right, #F7FFF9, #FFFFFF);
- }
- .data-label {
- font-size: 26rpx;
- color: #666666;
- margin-bottom: 22rpx;
- font-weight: 500;
- align-self: flex-start;
- }
- .data-value-container {
- display: flex;
- align-items: flex-end;
- width: 100%;
- margin-bottom: 18rpx;
- }
- .data-value {
- font-size: 40rpx;
- color: #222222;
- font-weight: 700;
- line-height: 1;
- }
- .data-value.no-data {
- font-size: 28rpx;
- color: #999999;
- font-weight: normal;
- }
- .data-unit {
- font-size: 24rpx;
- color: #999999;
- margin-left: 6rpx;
- padding-bottom: 6rpx;
- align-self: flex-end;
- }
- .data-time {
- font-size: 20rpx;
- color: #AAAAAA;
- width: 100%;
- text-align: right;
- }
- /* 数据更新动画 */
- @keyframes fadeNumberChange {
- 0% {
- opacity: 0.6;
- transform: scale(0.95);
- }
- 50% {
- opacity: 1;
- transform: scale(1.05);
- }
- 100% {
- opacity: 1;
- transform: scale(1);
- }
- }
- .data-value.updated {
- animation: fadeNumberChange 0.8s ease;
- }
- /* 异常值样式 */
- .value-warning {
- color: #E6A23C !important;
- }
- .value-alert {
- color: #F56C6C !important;
- }
- /* 点击波纹效果(可选)*/
- @keyframes ripple {
- 0% {
- transform: scale(0);
- opacity: 0.6;
- }
- 100% {
- transform: scale(2);
- opacity: 0;
- }
- }
- .data-item::after {
- content: '';
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(76, 175, 80, 0.1);
- border-radius: 24rpx;
- opacity: 0;
- transition: opacity 0.3s;
- z-index: -1;
- }
- .data-item-hover::after {
- opacity: 1;
- }
- /* 告警信息列表 */
- .alerts-section {
- margin: 0 30rpx 30rpx;
- background-color: #FFFFFF;
- border-radius: 20rpx;
- padding: 30rpx 24rpx;
- box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
- border: 1rpx solid rgba(210, 237, 217, 0.5);
- }
- .alerts-section .section-title {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 32rpx;
- font-weight: 600;
- color: #333333;
- margin-bottom: 24rpx;
- padding-bottom: 16rpx;
- border-bottom: 2rpx solid #f0f0f0;
- padding-left: 0;
- }
- .alerts-section .section-title::before {
- display: none;
- }
- .alert-badge {
- background-color: #F56C6C;
- color: #FFFFFF;
- font-size: 22rpx;
- border-radius: 30rpx;
- padding: 2rpx 12rpx;
- margin-left: 12rpx;
- font-weight: normal;
- min-width: 32rpx;
- text-align: center;
- }
- .alerts-list {
- display: flex;
- flex-direction: column;
- }
- .alert-item {
- display: flex;
- align-items: center;
- padding: 24rpx 20rpx;
- border-radius: 12rpx;
- margin-bottom: 16rpx;
- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
- position: relative;
- border: 1rpx solid transparent;
- transition: transform 0.2s ease;
- }
- .alert-item:active {
- transform: scale(0.98);
- }
- .alert-urgent {
- background-color: #FEF3F3;
- border-left: 4rpx solid #F56C6C;
- border-color: rgba(245, 108, 108, 0.2);
- }
- .alert-warning {
- background-color: #FFF8E6;
- border-left: 4rpx solid #E6A23C;
- border-color: rgba(230, 162, 60, 0.2);
- }
- .alert-info {
- background-color: #F2FAF5;
- border-left: 4rpx solid #67C23A;
- border-color: rgba(103, 194, 58, 0.2);
- }
- .alert-item-icon {
- width: 50rpx;
- height: 50rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- margin-right: 16rpx;
- }
- .alert-item-info {
- flex: 1;
- display: flex;
- flex-direction: column;
- }
- .alert-item-type {
- font-size: 28rpx;
- color: #333333;
- font-weight: 500;
- margin-bottom: 8rpx;
- }
- .alert-item-level {
- font-size: 24rpx;
- color: #999999;
- }
- .alert-item-time {
- font-size: 24rpx;
- color: #999999;
- margin-left: 16rpx;
- min-width: 100rpx;
- text-align: right;
- }
- .empty-alert {
- padding: 60rpx 0;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .empty-text {
- font-size: 28rpx;
- color: #999999;
- }
- /* 刷新按钮旋转动画 */
- @keyframes spin {
- 0% {
- transform: rotate(0deg);
- }
- 100% {
- transform: rotate(360deg);
- }
- }
- .refresh-btn.refreshing {
- animation: spin 1.2s linear infinite;
- }
- /* 土壤数据标题样式调整 */
- .soil-title, .data-title {
- display: flex;
- align-items: center;
- position: relative;
- padding-left: 24rpx;
- }
- .soil-title::before, .data-title::before {
- content: '';
- position: absolute;
- left: 0;
- top: 50%;
- transform: translateY(-50%);
- width: 8rpx;
- height: 36rpx;
- background: linear-gradient(to bottom, #4CAF50, #81C784);
- border-radius: 4rpx;
- }
- .soil-title text, .data-title text {
- margin-left: 16rpx;
- font-weight: 600;
- }
- </style>
|