自动暂停+设备暂停运行不弹窗

master
xce 2026-01-10 07:51:06 +08:00
parent 610814d178
commit 347082bb30
1 changed files with 107 additions and 15 deletions

View File

@ -222,7 +222,9 @@ export default {
//
currentCard: {}, //
currentCardTime: 0, //
newLimitTime: 0 //
newLimitTime: 0, //
// key=typevalue={timerId, snapInfo}
timers: {}
};
},
onLoad() {
@ -251,8 +253,19 @@ export default {
onUnload() {
// MQTT
mqttUtil.removeOnMessageCallback();
//
this.clearAllTimers();
},
methods: {
//
clearAllTimers() {
Object.keys(this.timers).forEach(type => {
if (this.timers[type]?.timerId) {
clearTimeout(this.timers[type].timerId);
}
});
this.timers = {};
},
change(e) {
this.imei = e;
// 使MQTT
@ -317,13 +330,13 @@ export default {
});
this.limitTimes= {
jbkLimit: 0,
jbgLimit: 0,
jm1kLimit: 0,
jm1gLimit: 0,
jm2kLimit: 0,
jm2gLimit: 0,
jm3kLimit: 0,
jm3gLimit: 0
jbgLimit: 0,
jm1kLimit: 0,
jm1gLimit: 0,
jm2kLimit: 0,
jm2gLimit: 0,
jm3kLimit: 0,
jm3gLimit: 0
};
this.deviceType = '';
this.control = '正在加载中...';
@ -376,13 +389,13 @@ export default {
//
this.message = JSON.stringify({[type]: status})
//
// this.publishMessage();
this.publishMessage();
//
this.deviceType = type;
//todo
this.$set(this.status, type, this.status[type] === 0 ? 1 : 0);
this.$set(this.show, type, this.status[type] === 0 ? "暂停" : "运行");
// this.$set(this.status, type, this.status[type] === 0 ? 1 : 0);
// this.$set(this.show, type, this.status[type] === 0 ? "" : "");
}
}
@ -433,23 +446,99 @@ export default {
console.info("提示消息:" + content)
},
//
// +
handleCommandAck(ackData, type) {
// jm2ksuc
const commandField = Object.keys(ackData.prop)[0]; // "jm2k"
const commandValue = ackData.prop[commandField]; // 0
const commandValue = ackData.prop[commandField]; // 0/1
const isSuccess = ackData.suc; // true
if (isSuccess) {
// 使$set
this.$set(this.status, type, this.status[type] === 0 ? 1 : 0);
this.$set(this.show, type, this.status[type] === 0 ? "暂停" : "运行");
// ========== ==========
const isStartCommand = commandValue === 1; // 1=0=
if (isStartCommand) {
// 1. type
if (this.timers[type]?.timerId) {
clearTimeout(this.timers[type].timerId);
delete this.timers[type];
}
// 2.
const snapInfo = {
imei: this.imei, // imei
publishTopic: this.publishTopic, // Topic
delayTime: Number(this.limitTimes[`${type}Limit`] || 0) * 1000, //
deviceType: type, //
connected: this.connected //
};
// 3.
if (snapInfo.delayTime && snapInfo.delayTime > 0) {
// 4. timerId
const timerId = setTimeout(() => {
// 使
this.sendAutoStopCommand(snapInfo);
//
delete this.timers[type];
}, snapInfo.delayTime);
// 5.
this.timers[type] = {
timerId: timerId,
snapInfo: snapInfo
};
}
}
}
this.deviceType = '';
this.$modal.msgSuccess("设备操作成功!")
// ========== ==========
if (commandValue === 1) this.$modal.msgSuccess("设备操作成功!");
console.log(`指令[${commandField}=${commandValue}]执行${isSuccess ? "成功" : "失败"}`);
},
// 使
sendAutoStopCommand(snapInfo) {
// 1.
if (!snapInfo || !snapInfo.imei || !snapInfo.publishTopic || !snapInfo.deviceType) {
this.addMessage(`【自动停止失败】快照数据缺失`);
return;
}
// 2.
let needStop = true;
if (this.imei === snapInfo.imei) {
needStop = this.status[snapInfo.deviceType] === 1;
}
if (needStop) {
// 3. 使
const stopMessage = JSON.stringify({[snapInfo.deviceType]: 0});
// 4. 使Topic
const publishSuccess = mqttUtil.publishMqtt(snapInfo.publishTopic, stopMessage);
if (publishSuccess) {
this.addMessage(`【自动停止-旧大棚${snapInfo.imei}】设备${snapInfo.deviceType},指令: ${stopMessage}`);
// 5.
if (this.imei === snapInfo.imei) {
this.$set(this.status, snapInfo.deviceType, 0);
this.$set(this.show, snapInfo.deviceType, "暂停");
}
} else {
this.addMessage(`【自动停止失败-旧大棚${snapInfo.imei}】设备${snapInfo.deviceType}`);
}
} else {
this.addMessage(`【自动停止跳过】旧大棚${snapInfo.imei}设备${snapInfo.deviceType}已非运行状态`);
}
},
handleOtherContent(msgData,payload) {
//
//
@ -572,9 +661,13 @@ export default {
},
onHide() {
mqttUtil.removeOnMessageCallback();
//
this.clearAllTimers();
},
beforeDestroy() {
mqttUtil.removeOnMessageCallback();
//
this.clearAllTimers();
},
};
</script>
@ -781,5 +874,4 @@ export default {
.uni-stat-tooltip {
width: 300rpx;
}
</style>