设备列表取消订阅

This commit is contained in:
kerwincui
2022-05-12 14:25:42 +08:00
parent cd63e1eba4
commit bc694b8a6f
2 changed files with 21 additions and 19 deletions

View File

@@ -392,12 +392,13 @@ export default {
mqttSubscribe(list) { mqttSubscribe(list) {
// 订阅当前页面设备状态和实时监测 // 订阅当前页面设备状态和实时监测
let topics = []; let topics = [];
for (let i = 0; i < list.length; i++) { // 订阅数太多会导致emqx连接中断或者订阅缓慢
let topicStatus = "/" + list[i].productId + "/" + list[i].serialNumber + "/status/post"; // for (let i = 0; i < list.length; i++) {
let topicMonitor = "/" + list[i].productId + "/" + list[i].serialNumber + "/monitor/post"; // let topicStatus = "/" + list[i].productId + "/" + list[i].serialNumber + "/status/post";
topics.push(topicStatus); // let topicMonitor = "/" + list[i].productId + "/" + list[i].serialNumber + "/monitor/post";
topics.push(topicMonitor); // topics.push(topicStatus);
} // topics.push(topicMonitor);
// }
this.subscribes = topics; this.subscribes = topics;
}, },
/** 更新实时监测参数*/ /** 更新实时监测参数*/

View File

@@ -30,8 +30,7 @@ export default {
} }
}, },
data() { data() {
return { return {};
};
}, },
created() { created() {
@@ -55,6 +54,7 @@ export default {
this.client.on("connect", (e) => { this.client.on("connect", (e) => {
console.log("成功连接服务器:", e); console.log("成功连接服务器:", e);
// 订阅主题 // 订阅主题
if (subscribeTopics != '' && subscribeTopics.length > 0) {
this.client.subscribe(subscribeTopics, { this.client.subscribe(subscribeTopics, {
qos: 1 qos: 1
}, (err) => { }, (err) => {
@@ -65,6 +65,7 @@ export default {
console.log('消息订阅失败!') console.log('消息订阅失败!')
} }
}); });
}
}); });
// 重新连接 // 重新连接
this.reconnectMqtt() this.reconnectMqtt()