首页设备在线状态修改为实时

feasure
lld 2026-03-07 23:38:31 +08:00
parent 84dadc658a
commit a5718c6ea0
3 changed files with 81 additions and 31 deletions

View File

@ -864,6 +864,13 @@ export default {
"操作提示"); "操作提示");
return; return;
} }
// 300/2.13
const isValidTotalLen = this.rollerParam.manualTotalLen > 300 || this.rollerParam.autoTotalLen > 300;
if (isValidTotalLen) {
this.$modal.alert(`风口长度设置不能大于300cm`,
"操作提示");
return;
}
if (!(this.rollerParam.reservedLen && this.rollerParam.reservedLen > 0)) { if (!(this.rollerParam.reservedLen && this.rollerParam.reservedLen > 0)) {
this.$modal.alert(`请填写预留风口!`, this.$modal.alert(`请填写预留风口!`,
"操作提示"); "操作提示");
@ -948,6 +955,11 @@ export default {
validate: (rollerParam, term) => !((rollerParam.manualTotalLen && rollerParam.manualTotalLen > 0) || validate: (rollerParam, term) => !((rollerParam.manualTotalLen && rollerParam.manualTotalLen > 0) ||
(rollerParam.autoTotalLen && rollerParam.autoTotalLen > 0)) (rollerParam.autoTotalLen && rollerParam.autoTotalLen > 0))
}, },
{
tip: '风口长度设置不能大于300cm',
validate: (rollerParam, term) => (rollerParam.manualTotalLen && rollerParam.manualTotalLen > 300) ||
(rollerParam.autoTotalLen && rollerParam.autoTotalLen > 300)
},
{ {
tip: '预留风口长度未设置,请点击相应页签右上角设置后重试!', tip: '预留风口长度未设置,请点击相应页签右上角设置后重试!',
validate: (rollerParam, term) => !(rollerParam.reservedLen && rollerParam.reservedLen > 0) validate: (rollerParam, term) => !(rollerParam.reservedLen && rollerParam.reservedLen > 0)

View File

@ -96,6 +96,7 @@ import TimeUtil from "../utils/TimeUtil";
import {getNewSpecialData} from "../api/data/specialData"; 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";
export default { export default {
computed: { computed: {
@ -135,32 +136,33 @@ export default {
// vertical: 'bottom', // vertical: 'bottom',
// direction: 'horizontal', // direction: 'horizontal',
searchValue: null, searchValue: null,
/* pattern: { imeiToDeviceMap: new Map(),
color: '#7A7E83', /* pattern: {
backgroundColor: '#fff', color: '#7A7E83',
selectedColor: '#007AFF', backgroundColor: '#fff',
buttonColor: '#007AFF', selectedColor: '#007AFF',
iconColor: '#fff' buttonColor: '#007AFF',
}, iconColor: '#fff'
content: [{ },
iconPath: '/static/image.png', content: [{
selectedIconPath: '/static/image-active.png', iconPath: '/static/image.png',
text: '添加大棚', selectedIconPath: '/static/image-active.png',
active: false text: '添加大棚',
}, active: false
{ },
iconPath: '/static/home.png', {
selectedIconPath: '/static/home-active.png', iconPath: '/static/home.png',
text: '', selectedIconPath: '/static/home-active.png',
active: false text: '',
}, active: false
{ },
iconPath: '/static/star.png', {
selectedIconPath: '/static/star-active.png', iconPath: '/static/star.png',
text: '收藏', selectedIconPath: '/static/star-active.png',
active: false text: '收藏',
} active: false
]*/ }
]*/
} }
}, },
@ -172,12 +174,15 @@ export default {
return false*/ return false*/
}, },
onShow() { onShow() {
mqttUtil.setOnMessageCallback(this.ackMessage);
}, },
onLoad() { onLoad() {
this.$modal.loading("数据加载中,请耐心等待...") this.$modal.loading("数据加载中,请耐心等待...")
this.refresh(); this.refresh();
}, },
onHide() {
mqttUtil.removeOnMessageCallback();
},
onReady() { onReady() {
}, },
@ -239,23 +244,27 @@ export default {
getAgriInfo().then(response => { getAgriInfo().then(response => {
if (response.code === 200) { if (response.code === 200) {
//
this.imeiToDeviceMap.clear();
// 1. map forEach undefined // 1. map forEach undefined
// 2. / listData // 2. / listData
this.listData = response.data.map(item => { this.listData = response.data.map(item => {
// const deviceItem = {
return {
...item, ...item,
deviceStatus: TimeUtil.isLessThanSpecifiedSeconds(item.time, 90) ? '在线' : '离线', deviceStatus: TimeUtil.isLessThanSpecifiedSeconds(item.time, 90) ? '在线' : '离线',
online: TimeUtil.isLessThanSpecifiedSeconds(item.time, 90) ? '在线' : '离线', // online online: TimeUtil.isLessThanSpecifiedSeconds(item.time, 90) ? '在线' : '离线',
agriName: item.agriName || '未知大棚', agriName: item.agriName || '未知大棚',
imei: `${item.imei || '未知'}`, imei: `${item.imei || '未知'}`,
workModeDesc: item.workMode === 0? '手动模式':'自动模式', workModeDesc: item.workMode === 0 ? '手动模式':'自动模式',
workMode: item.workMode, workMode: item.workMode,
temp1: item.temp1, temp1: item.temp1,
temp2: item.temp2, temp2: item.temp2,
temp3: item.temp3, temp3: item.temp3,
temp4: item.temp4 temp4: item.temp4
}; };
// Map
this.imeiToDeviceMap.set(deviceItem.imei, deviceItem);
return deviceItem;
}); });
// 5. // 5.
this.noMore = this.listData.length >= this.total; this.noMore = this.listData.length >= this.total;
@ -280,6 +289,7 @@ export default {
} }
}, },
refresh() { refresh() {
mqttUtil.setOnMessageCallback(this.ackMessage);
this.getListData(); this.getListData();
}, },
onDeleteItem(item, agri) { onDeleteItem(item, agri) {
@ -358,6 +368,33 @@ export default {
}, },
) )
}, },
ackMessage(topic, payload) {
const regex2 = /^device\/\d+\/status$/;
if (!regex2.test(topic)) return;
let msgData = {};
// JSON
try {
msgData = JSON.parse(payload);
} catch (e) {
console.error("MQTT消息解析失败", e, payload);
return;
}
// 线
if (msgData.online && "time" in msgData && "imei" in msgData) {
this.updateDeviceStatusFast(msgData.imei, msgData.online)
}
},
updateDeviceStatusFast(targetImei, isOnline) {
// Map
const targetDevice = this.imeiToDeviceMap.get(targetImei);
if (!targetDevice) return;
const statusText = isOnline ? '在线' : '离线';
//
targetDevice.deviceStatus = statusText;
targetDevice.online = statusText;
}
} }
} }
</script> </script>

View File

@ -345,6 +345,7 @@ export function updateSubscribeTopic() {
response.rows.forEach(item => { response.rows.forEach(item => {
if (item?.imei) { if (item?.imei) {
subscribeList.push(`frontend/${clientId}/dtu/${item.imei}/+`); subscribeList.push(`frontend/${clientId}/dtu/${item.imei}/+`);
subscribeList.push(`device/${item.imei}/+`);
} }
}); });
// 管理员额外订阅指定设备 // 管理员额外订阅指定设备