| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179 |
- <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-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>
|