|
@@ -465,12 +465,7 @@ export default {
|
|
|
animationDuration: 100,
|
|
|
},
|
|
|
index: 0,
|
|
|
- loopTimer: null,
|
|
|
- mqttClienTwoFlag: false,
|
|
|
- mqttClientOne: false,
|
|
|
- mqttData: null,
|
|
|
showModle: false,
|
|
|
- mqttMessageBound: false,
|
|
|
};
|
|
|
},
|
|
|
computed: {},
|
|
@@ -991,34 +986,39 @@ export default {
|
|
|
console.log(this.clientId, "clientIDetail");
|
|
|
this.clientId = clientId;
|
|
|
const bindMqtt = (mqttClientData) => {
|
|
|
- mqttClientData.subscribe(
|
|
|
- `/dev/${this.clientId}/tracker_targets`,
|
|
|
- (err) => {
|
|
|
- if (err) console.error("DATA MQTT 订阅失败", err);
|
|
|
- else
|
|
|
- console.log(
|
|
|
- `DATA MQTT 订阅成功: /dev/${this.clientId}/tracker_targets`
|
|
|
- );
|
|
|
+ if (!mqttClientData) {
|
|
|
+ console.error("MQTT 客户端未初始化");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 进入设备详情,先取消之前的订阅,避免重复
|
|
|
+ const topic = `/dev/${this.clientId}/tracker_targets`;
|
|
|
+ mqttClientData.unsubscribe(topic, (err) => {
|
|
|
+ if (err) {
|
|
|
+ console.warn("取消订阅失败,可能之前没订阅过", err);
|
|
|
}
|
|
|
- );
|
|
|
- if (!this.mqttMessageBound) {
|
|
|
- mqttClientData.on("message", (topic, message) => {
|
|
|
- console.log("topicDeviceDetail", topic, message);
|
|
|
- const dataMatch = topic.match(
|
|
|
- /^\/dev\/(.+)\/tracker_targets$/
|
|
|
- );
|
|
|
- const cmdMatch = topic.match(/^\/mps\/wx_(.+)\/notice$/);
|
|
|
- if (dataMatch && dataMatch[1] === this.clientId) {
|
|
|
- this.handleMessage(topic, message, this.clientId);
|
|
|
- } else if (cmdMatch) {
|
|
|
- this.$refs.alarmModel?.hanOtherMessage?.(
|
|
|
- topic,
|
|
|
- message
|
|
|
- );
|
|
|
+ // 再订阅一次,确保立即生效
|
|
|
+ mqttClientData.subscribe(topic, (err) => {
|
|
|
+ if (err) {
|
|
|
+ console.error("DATA MQTT 订阅失败", err);
|
|
|
+ } else {
|
|
|
+ console.log(`DATA MQTT 订阅成功: ${topic}`);
|
|
|
}
|
|
|
});
|
|
|
- this.mqttMessageBound = true;
|
|
|
- }
|
|
|
+ });
|
|
|
+ mqttClientData.removeAllListeners("message");
|
|
|
+ mqttClientData.on("message", (topic, message) => {
|
|
|
+ console.log("打印的点位", message.toString());
|
|
|
+
|
|
|
+ const dataMatch = topic.match(/^\/dev\/(.+)\/tracker_targets$/);
|
|
|
+ const cmdMatch = topic.match(/^\/mps\/wx_(.+)\/notice$/);
|
|
|
+
|
|
|
+ if (dataMatch && dataMatch[1] === this.clientId) {
|
|
|
+ this.handleMessage(topic, message, this.clientId);
|
|
|
+ } else if (cmdMatch) {
|
|
|
+ this.$refs.alarmModel.hanOtherMessage(topic, message);
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
if (this.$mqttClientData) {
|