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