mirror of
https://github.com/kerwincui/FastBee.git
synced 2025-10-19 14:35:06 +08:00
设备列表取消订阅
This commit is contained in:
@@ -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;
|
||||||
},
|
},
|
||||||
/** 更新实时监测参数*/
|
/** 更新实时监测参数*/
|
||||||
|
@@ -23,15 +23,14 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
// 获取到父组件传递的值
|
// 获取到父组件传递的值
|
||||||
publish: function (val, oldVal) {
|
publish: function (val, oldVal) {
|
||||||
this.mqttPublish(val.topic, val.message,val.name);
|
this.mqttPublish(val.topic, val.message, val.name);
|
||||||
},
|
},
|
||||||
subscribes: function (val, oldVal) {
|
subscribes: function (val, oldVal) {
|
||||||
this.connectMqtt(val);
|
this.connectMqtt(val);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {};
|
||||||
};
|
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|
||||||
@@ -55,16 +54,18 @@ export default {
|
|||||||
this.client.on("connect", (e) => {
|
this.client.on("connect", (e) => {
|
||||||
console.log("成功连接服务器:", e);
|
console.log("成功连接服务器:", e);
|
||||||
// 订阅主题
|
// 订阅主题
|
||||||
this.client.subscribe(subscribeTopics, {
|
if (subscribeTopics != '' && subscribeTopics.length > 0) {
|
||||||
qos: 1
|
this.client.subscribe(subscribeTopics, {
|
||||||
}, (err) => {
|
qos: 1
|
||||||
if (!err) {
|
}, (err) => {
|
||||||
console.log("订阅成功");
|
if (!err) {
|
||||||
console.log(subscribeTopics.join(", "));
|
console.log("订阅成功");
|
||||||
} else {
|
console.log(subscribeTopics.join(", "));
|
||||||
console.log('消息订阅失败!')
|
} else {
|
||||||
}
|
console.log('消息订阅失败!')
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// 重新连接
|
// 重新连接
|
||||||
this.reconnectMqtt()
|
this.reconnectMqtt()
|
||||||
|
Reference in New Issue
Block a user