首页在线状态改为实时
parent
b7705ae680
commit
c69c033703
|
|
@ -66,6 +66,6 @@ export function switchAgriMode(imei, code) {
|
||||||
return request({
|
return request({
|
||||||
url: '/assets/agri/switchAgriMode/' + imei,
|
url: '/assets/agri/switchAgriMode/' + imei,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
param: code
|
params: code
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -46,4 +46,13 @@ export function status() {
|
||||||
url: '/api/mqtt/batch',
|
url: '/api/mqtt/batch',
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getAgriStatus(data) {
|
||||||
|
return request({
|
||||||
|
url: '/api/mqtt/getAgriStatus',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,6 @@ export default {
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
// 移除MQTT消息回调(避免内存泄漏)
|
// 移除MQTT消息回调(避免内存泄漏)
|
||||||
mqttUtil.removeOnMessageCallback();
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
refresh() {
|
refresh() {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<uni-section class="mb-10" title="温室列表" style="background:transparent;" type="line">
|
<uni-section class="mb-10" title="温室列表" style="background:transparent;" type="line">
|
||||||
|
<template v-slot:right>
|
||||||
|
<view>
|
||||||
|
<text style="color: #f64040">{{ dataDetails.online }} 在线 </text>
|
||||||
|
<text style="color: #2d56d8"> {{ dataDetails.offline }} 离线</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
<scroll-view
|
<scroll-view
|
||||||
scroll-y
|
scroll-y
|
||||||
class="list-scroll"
|
class="list-scroll"
|
||||||
|
|
@ -97,6 +103,7 @@ import {getNewSpecialData} from "../api/data/specialData";
|
||||||
import AddAgri from "../components/addAgri/addAgri.vue";
|
import AddAgri from "../components/addAgri/addAgri.vue";
|
||||||
import {removeAgri} from "../api/system/assets/userAgri";
|
import {removeAgri} from "../api/system/assets/userAgri";
|
||||||
import * as mqttUtil from "../utils/mqtt";
|
import * as mqttUtil from "../utils/mqtt";
|
||||||
|
import {getAgriStatus} from "../api/system/mqtt";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -137,6 +144,11 @@ export default {
|
||||||
// direction: 'horizontal',
|
// direction: 'horizontal',
|
||||||
searchValue: null,
|
searchValue: null,
|
||||||
imeiToDeviceMap: new Map(),
|
imeiToDeviceMap: new Map(),
|
||||||
|
dataDetails: {
|
||||||
|
tip: null,
|
||||||
|
online: 0,
|
||||||
|
offline: 0
|
||||||
|
}
|
||||||
/* pattern: {
|
/* pattern: {
|
||||||
color: '#7A7E83',
|
color: '#7A7E83',
|
||||||
backgroundColor: '#fff',
|
backgroundColor: '#fff',
|
||||||
|
|
@ -273,7 +285,10 @@ export default {
|
||||||
if (store.getters && store.getters.name === 'admin') {
|
if (store.getters && store.getters.name === 'admin') {
|
||||||
this.getNewSpecialData();
|
this.getNewSpecialData();
|
||||||
}
|
}
|
||||||
|
// 左上角详情
|
||||||
|
this.getDataDetails();
|
||||||
this.datas = [...this.listData]
|
this.datas = [...this.listData]
|
||||||
|
this.getAgriStatus();
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error("获取大棚信息失败:", err);
|
console.error("获取大棚信息失败:", err);
|
||||||
|
|
@ -391,9 +406,9 @@ export default {
|
||||||
// 温度
|
// 温度
|
||||||
const allKeysNumeric2 = Object.keys(msgData).every(key => /^\d+$/.test(key));
|
const allKeysNumeric2 = Object.keys(msgData).every(key => /^\d+$/.test(key));
|
||||||
if (regex1.test(topic) && Object.keys(msgData).length > 0 && allKeysNumeric2) {
|
if (regex1.test(topic) && Object.keys(msgData).length > 0 && allKeysNumeric2) {
|
||||||
this.updateTempFast(msgData)
|
this.updateTempFast(msgData, topic)
|
||||||
}
|
}
|
||||||
|
this.getDataDetails();
|
||||||
},
|
},
|
||||||
updateDeviceStatusFast(targetImei, isOnline) {
|
updateDeviceStatusFast(targetImei, isOnline) {
|
||||||
// 直接从Map里取设备项,无需遍历数组
|
// 直接从Map里取设备项,无需遍历数组
|
||||||
|
|
@ -406,9 +421,9 @@ export default {
|
||||||
targetDevice.online = statusText;
|
targetDevice.online = statusText;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateTempFast: function (msgData) {
|
updateTempFast: function (msgData,topic) {
|
||||||
const regexWithGroup = /^frontend\/(.+)\/dtu\/(\d+)\/listener$/;
|
const regexWithGroup = /^frontend\/(.+)\/dtu\/(\d+)\/listener$/;
|
||||||
const matchResult = regexWithGroup.match(msgData);
|
const matchResult = topic.match(regexWithGroup);
|
||||||
const imei = matchResult[2]; // 提取结果:'1234567890'
|
const imei = matchResult[2]; // 提取结果:'1234567890'
|
||||||
// 直接从Map里取设备项,无需遍历数组
|
// 直接从Map里取设备项,无需遍历数组
|
||||||
const targetDevice = this.imeiToDeviceMap.get(imei);
|
const targetDevice = this.imeiToDeviceMap.get(imei);
|
||||||
|
|
@ -416,10 +431,36 @@ export default {
|
||||||
const div10 = (v) => (v == null ? null : Math.round((Number(v) / 10) * 10) / 10);
|
const div10 = (v) => (v == null ? null : Math.round((Number(v) / 10) * 10) / 10);
|
||||||
// 直接修改对象属性,响应式正常生效
|
// 直接修改对象属性,响应式正常生效
|
||||||
|
|
||||||
targetDevice.temp1 = msgData['201'];
|
targetDevice.temp1 = div10(msgData['201']);
|
||||||
targetDevice.temp2 = msgData['202'];
|
targetDevice.temp2 = div10(msgData['202']);
|
||||||
targetDevice.temp3 = msgData['203'];
|
targetDevice.temp3 = div10(msgData['203']);
|
||||||
targetDevice.temp4 = msgData['204'];
|
targetDevice.temp4 = div10(msgData['204']);
|
||||||
|
},
|
||||||
|
getDataDetails() {
|
||||||
|
this.dataDetails = {
|
||||||
|
tip: null,
|
||||||
|
online: 0,
|
||||||
|
offline: 0
|
||||||
|
}
|
||||||
|
var online = 0;
|
||||||
|
var offline = 0;
|
||||||
|
this.listData.forEach(item => {
|
||||||
|
if (item.online === '离线') {
|
||||||
|
offline += 1;
|
||||||
|
} else {
|
||||||
|
online += 1;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.dataDetails = {
|
||||||
|
tip: null,
|
||||||
|
online: online,
|
||||||
|
offline: offline,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getAgriStatus() {
|
||||||
|
if (!this.listData || this.listData.length === 0) return []; // 空列表处理
|
||||||
|
const allImei = this.listData.map(item => item.imei).filter(imei => imei);
|
||||||
|
getAgriStatus([...new Set(allImei)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue