二维码生成和下载保存列表 优化 切换ws遗留的上一个在线设备数据 增加预定义路线生成 完善任务规划界面 的中英文

This commit is contained in:
mmc
2026-11-09 16:01:23 +08:00
parent 8924272656
commit 6401327522
9 changed files with 371 additions and 330 deletions

View File

@@ -30,6 +30,9 @@ export default class DeviceController {
this.wsStatus = 'disconnected';
this.wsDeviceInfo = {};
this.locationInfo = {};
// 切换设备后的实时数据门禁:AUTH 确认前丢弃无设备标识的遗留消息
this.authConfirmed = true;
this.switchAt = 0;
this.controlTimeout = null;
this.keepAliveInterval = null;
@@ -360,6 +363,9 @@ export default class DeviceController {
this.connectedDeviceSn = newSn;
this.wsDeviceInfo = {};
this.locationInfo = {};
// 切换设备:AUTH 确认前丢弃旧设备遗留的实时数据
this.authConfirmed = false;
this.switchAt = Date.now();
this.isControlled = false;
this.onControlStatusChange?.(false);
@@ -437,6 +443,20 @@ export default class DeviceController {
});
}
// 判断实时消息是否属于当前连接设备;设备切换过程中旧设备的遗留消息返回 true
isStaleRealtimeMessage(msg, data) {
const msgSn = data?.deviceId ?? data?.device_id ?? data?.deviceSn
?? msg?.deviceId ?? msg?.device_id ?? msg?.deviceSn ?? msg?.sn;
if (msgSn != null && String(msgSn) !== '') {
if (String(msgSn) !== String(this.connectedDeviceSn)) return true;
this.authConfirmed = true;
return false;
}
// 无设备标识:切换后 AUTH 确认前一律视为遗留数据(兜底 2 秒防止永久丢弃)
if (!this.authConfirmed) return Date.now() - (this.switchAt || 0) < 2000;
return false;
}
handleWsMessage(msg) {
console.log('WS message:', msg);
switch (msg.type) {
@@ -446,7 +466,7 @@ export default class DeviceController {
data[item.name] = item.value;
});
// 切换任务/切换设备时,忽略上一个设备遗留的实时数据
if (data?.deviceId && data.deviceId !== this.connectedDeviceSn) {
if (this.isStaleRealtimeMessage(msg, data)) {
break;
}
this.wsDeviceInfo = data;
@@ -459,7 +479,7 @@ export default class DeviceController {
data[item.name] = item.value;
});
// 切换任务/切换设备时,忽略上一个设备遗留的实时经纬度,只显示当前连接设备的实时轨迹
if (data?.deviceId && data.deviceId !== this.connectedDeviceSn) {
if (this.isStaleRealtimeMessage(msg, data)) {
break;
}
this.locationInfo = data;
@@ -469,6 +489,7 @@ export default class DeviceController {
case 'AUTH': {
if (msg.isAuth) {
this.authConfirmed = true;
this.getControl(this.connectedDeviceSn);
}
break;