设备控制
parent
65281bbce2
commit
2a34df477f
|
|
@ -251,7 +251,6 @@ export default {
|
|||
jm3kLimit: 0,
|
||||
jm3gLimit: 0
|
||||
},
|
||||
deviceType: '',
|
||||
status: {
|
||||
jbk: 0,
|
||||
jbg: 0,
|
||||
|
|
@ -417,7 +416,6 @@ export default {
|
|||
// 控制设备
|
||||
this.publishMessage();
|
||||
// 设备回执
|
||||
this.deviceType = type;
|
||||
//todo
|
||||
// this.testAuto(type);
|
||||
|
||||
|
|
@ -479,7 +477,6 @@ export default {
|
|||
jm3kLimit: 0,
|
||||
jm3gLimit: 0
|
||||
};
|
||||
this.deviceType = '';
|
||||
this.control = '正在加载中...';
|
||||
this.message = {};
|
||||
this.temp = '';
|
||||
|
|
@ -531,8 +528,6 @@ export default {
|
|||
this.message = JSON.stringify({[`${type}1`]: status})
|
||||
// 控制设备
|
||||
this.publishMessage();
|
||||
// 设备回执
|
||||
this.deviceType = type;
|
||||
//todo
|
||||
// this.testAuto(type);
|
||||
|
||||
|
|
@ -580,7 +575,7 @@ export default {
|
|||
|
||||
// 3. 区分“回执”和“其他内容”
|
||||
if (msgData.prop && "suc" in msgData) {
|
||||
this.handleCommandAck(msgData, this.deviceType);
|
||||
this.handleCommandAck(msgData);
|
||||
} else if ("msg" in msgData && "clientId" in msgData) {
|
||||
if (mqttUtil.getMqttState().clientId === msgData.clientId) {
|
||||
this.$modal.msg(
|
||||
|
|
@ -597,21 +592,24 @@ export default {
|
|||
},
|
||||
|
||||
// 处理指令回执的函数(核心修改:添加定时器+快照)
|
||||
handleCommandAck(ackData, type) {
|
||||
handleCommandAck(ackData) {
|
||||
// 拿到指令字段(如jm2k)和执行状态(suc)
|
||||
const commandField = Object.keys(ackData.prop)[0]; // 这里是"jm2k"
|
||||
const commandValue = ackData.prop[commandField]; // 这里是0/1
|
||||
const isSuccess = ackData.suc; // 这里是true
|
||||
|
||||
const type = commandField.substring(0,commandField.length -1);
|
||||
if (isSuccess) {
|
||||
// 优化:使用$set确保响应式更新
|
||||
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, commandValue);
|
||||
this.$set(this.show, type, commandValue === 0 ? "暂停" : "运行");
|
||||
console.info(`收到回执,更新功能码成功:{"${type}":${commandValue}}`)
|
||||
}
|
||||
|
||||
this.deviceType = '';
|
||||
|
||||
// ========== 修改:自动停止指令不弹窗 ==========
|
||||
if (ackData.clientId && (ackData.clientId===mqttUtil.getMqttState().clientId)) {
|
||||
console.info("用户提示成功!")
|
||||
this.$modal[isSuccess ? 'msgSuccess' : 'msgError'](
|
||||
`设备操作${isSuccess ? "成功" : "失败"}!`
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue