|
@@ -637,265 +637,52 @@ export default {
|
|
},
|
|
},
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
- // if (this.$mqttClient) {
|
|
|
|
- // console.log("开始接受mqtt消息111");
|
|
|
|
- // this.$mqttClient.on("message", (topic, message) => {
|
|
|
|
- // console.log(
|
|
|
|
- // "接收到消息CMD11111:",
|
|
|
|
- // JSON.parse(message.toString())
|
|
|
|
- // );
|
|
|
|
- // console.log(JSON.parse(message.toString()), "8870");
|
|
|
|
- // // 处理点位消息
|
|
|
|
- // let userId = uni.getStorageSync("userId");
|
|
|
|
- // const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
|
- // const match = topic.match(noticeMatch);
|
|
|
|
- // if (!match) return;
|
|
|
|
- // this.alarmModel = true;
|
|
|
|
- // const data = JSON.parse(message.toString());
|
|
|
|
- // this.clientId = data.clientId;
|
|
|
|
- // this.devName = data.devName;
|
|
|
|
- // this.sn = data.clientId;
|
|
|
|
- // this.eventListId = data.eventListId;
|
|
|
|
- // this.getVoipAuthor(this.clientId, userId);
|
|
|
|
- // console.log(data, topic, "接收到消息222:");
|
|
|
|
- // console.log(
|
|
|
|
- // "接收到消息:",
|
|
|
|
- // this.clientId,
|
|
|
|
- // this.devName,
|
|
|
|
- // this.sn,
|
|
|
|
- // this.eventListId,
|
|
|
|
- // data
|
|
|
|
- // );
|
|
|
|
- // const now = new Date();
|
|
|
|
- // const year = now.getFullYear();
|
|
|
|
- // const month = (now.getMonth() + 1).toString().padStart(2, "0");
|
|
|
|
- // const day = now.getDate().toString().padStart(2, "0");
|
|
|
|
- // const hours = now.getHours().toString().padStart(2, "0");
|
|
|
|
- // const minutes = now.getMinutes().toString().padStart(2, "0");
|
|
|
|
- // const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
|
- // this.nowTime = formattedTime;
|
|
|
|
- // console.log("isWmpf:", isWmpf);
|
|
|
|
- // if (!isWmpf) {
|
|
|
|
- // console.log("isWmpf:", isWmpf);
|
|
|
|
- // this.getVoipDevices();
|
|
|
|
- // }
|
|
|
|
- // console.log("接收到消息:", topic, data);
|
|
|
|
- // });
|
|
|
|
- // } else {
|
|
|
|
- // uni.$once("mqtt-ready", () => {
|
|
|
|
- // console.log("开始接受mqtt消息222");
|
|
|
|
- // this.$mqttClient.on("message", (topic, message) => {
|
|
|
|
- // console.log(
|
|
|
|
- // "接收到消息CMD222:",
|
|
|
|
- // JSON.parse(message.toString())
|
|
|
|
- // );
|
|
|
|
- // console.log(JSON.parse(message.toString()), "8870");
|
|
|
|
- // // 处理点位消息
|
|
|
|
- // let userId = uni.getStorageSync("userId");
|
|
|
|
- // const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
|
- // const match = topic.match(noticeMatch);
|
|
|
|
- // if (!match) return;
|
|
|
|
- // this.alarmModel = true;
|
|
|
|
- // const data = JSON.parse(message.toString());
|
|
|
|
- // this.clientId = data.clientId;
|
|
|
|
- // this.devName = data.devName;
|
|
|
|
- // this.sn = data.clientId;
|
|
|
|
- // this.eventListId = data.eventListId;
|
|
|
|
- // this.getVoipAuthor(this.clientId, userId);
|
|
|
|
- // console.log(data, topic, "接收到消息222:");
|
|
|
|
- // console.log(
|
|
|
|
- // "接收到消息:",
|
|
|
|
- // this.clientId,
|
|
|
|
- // this.devName,
|
|
|
|
- // this.sn,
|
|
|
|
- // this.eventListId,
|
|
|
|
- // data
|
|
|
|
- // );
|
|
|
|
- // const now = new Date();
|
|
|
|
- // const year = now.getFullYear();
|
|
|
|
- // const month = (now.getMonth() + 1)
|
|
|
|
- // .toString()
|
|
|
|
- // .padStart(2, "0");
|
|
|
|
- // const day = now.getDate().toString().padStart(2, "0");
|
|
|
|
- // const hours = now.getHours().toString().padStart(2, "0");
|
|
|
|
- // const minutes = now
|
|
|
|
- // .getMinutes()
|
|
|
|
- // .toString()
|
|
|
|
- // .padStart(2, "0");
|
|
|
|
- // const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
|
- // this.nowTime = formattedTime;
|
|
|
|
- // console.log("isWmpf:", isWmpf);
|
|
|
|
- // if (!isWmpf) {
|
|
|
|
- // console.log("isWmpf:", isWmpf);
|
|
|
|
- // this.getVoipDevices();
|
|
|
|
- // }
|
|
|
|
- // console.log("接收到消息:", topic, data);
|
|
|
|
- // });
|
|
|
|
- // });
|
|
|
|
- // }
|
|
|
|
- // 确保已经连接好再订阅
|
|
|
|
-
|
|
|
|
const userId = uni.getStorageSync("userId");
|
|
const userId = uni.getStorageSync("userId");
|
|
const topic = `/mps/wx_${userId}/notice`;
|
|
const topic = `/mps/wx_${userId}/notice`;
|
|
-
|
|
|
|
- if (MqttService.cmdConnected) {
|
|
|
|
- // 已连接 → 直接订阅
|
|
|
|
- this.unsubscribeOther = MqttService.subscribe(
|
|
|
|
- "CMD",
|
|
|
|
- topic,
|
|
|
|
- (message) => {
|
|
|
|
- const data = JSON.parse(message);
|
|
|
|
- let userId = uni.getStorageSync("userId");
|
|
|
|
- const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
|
- const match = topic.match(noticeMatch);
|
|
|
|
- if (!match) return;
|
|
|
|
- // 更新页面数据
|
|
|
|
- this.alarmModel = true;
|
|
|
|
- this.clientId = data.clientId;
|
|
|
|
- this.devName = data.devName;
|
|
|
|
- this.sn = data.clientId;
|
|
|
|
- this.eventListId = data.eventListId;
|
|
|
|
- // VOIP 相关逻辑
|
|
|
|
- this.getVoipAuthor(this.clientId, userId);
|
|
|
|
- // 格式化时间
|
|
|
|
- const now = new Date();
|
|
|
|
- this.nowTime = `${now.getFullYear()}-${String(
|
|
|
|
- now.getMonth() + 1
|
|
|
|
- ).padStart(2, "0")}-${String(now.getDate()).padStart(
|
|
|
|
- 2,
|
|
|
|
- "0"
|
|
|
|
- )} ${String(now.getHours()).padStart(2, "0")}:${String(
|
|
|
|
- now.getMinutes()
|
|
|
|
- ).padStart(2, "0")}`;
|
|
|
|
- if (!isWmpf) {
|
|
|
|
- this.getVoipDevices();
|
|
|
|
- }
|
|
|
|
- console.log("处理后的 CMD 数据:", data);
|
|
|
|
- },
|
|
|
|
- (err) => {
|
|
|
|
- if (!err) console.log(`✅ 页面B 已订阅 ${topic}`);
|
|
|
|
|
|
+ this.unsubscribeFnNotice = MqttService.subscribe(
|
|
|
|
+ "DATA",
|
|
|
|
+ topic,
|
|
|
|
+ (message, msgTopic) => {
|
|
|
|
+ console.log(`接收到 ${msgTopic} 消息:`, message);
|
|
|
|
+ // 处理消息
|
|
|
|
+ const data = JSON.parse(message);
|
|
|
|
+ let userId = uni.getStorageSync("userId");
|
|
|
|
+ const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
|
+ const match = topic.match(noticeMatch);
|
|
|
|
+ if (!match) return;
|
|
|
|
+ // 更新页面数据
|
|
|
|
+ this.alarmModel = true;
|
|
|
|
+ this.clientId = data.clientId;
|
|
|
|
+ this.devName = data.devName;
|
|
|
|
+ this.sn = data.clientId;
|
|
|
|
+ this.eventListId = data.eventListId;
|
|
|
|
+ // VOIP 相关逻辑
|
|
|
|
+ this.getVoipAuthor(this.clientId, userId);
|
|
|
|
+ // 格式化时间
|
|
|
|
+ const now = new Date();
|
|
|
|
+ this.nowTime = `${now.getFullYear()}-${String(
|
|
|
|
+ now.getMonth() + 1
|
|
|
|
+ ).padStart(2, "0")}-${String(now.getDate()).padStart(
|
|
|
|
+ 2,
|
|
|
|
+ "0"
|
|
|
|
+ )} ${String(now.getHours()).padStart(2, "0")}:${String(
|
|
|
|
+ now.getMinutes()
|
|
|
|
+ ).padStart(2, "0")}`;
|
|
|
|
+ if (!isWmpf) {
|
|
|
|
+ this.getVoipDevices();
|
|
}
|
|
}
|
|
- );
|
|
|
|
- } else {
|
|
|
|
- // 还没连上 → 等待 mqtt-ready
|
|
|
|
- uni.$once("mqtt-ready", () => {
|
|
|
|
- this.unsubscribeOther = MqttService.subscribe(
|
|
|
|
- "CMD",
|
|
|
|
- topic,
|
|
|
|
- (message) => {
|
|
|
|
- const data = JSON.parse(message);
|
|
|
|
- let userId = uni.getStorageSync("userId");
|
|
|
|
- const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
|
- const match = topic.match(noticeMatch);
|
|
|
|
- if (!match) return;
|
|
|
|
- // 更新页面数据
|
|
|
|
- this.alarmModel = true;
|
|
|
|
- this.clientId = data.clientId;
|
|
|
|
- this.devName = data.devName;
|
|
|
|
- this.sn = data.clientId;
|
|
|
|
- this.eventListId = data.eventListId;
|
|
|
|
- // VOIP 相关逻辑
|
|
|
|
- this.getVoipAuthor(this.clientId, userId);
|
|
|
|
- // 格式化时间
|
|
|
|
- const now = new Date();
|
|
|
|
- this.nowTime = `${now.getFullYear()}-${String(
|
|
|
|
- now.getMonth() + 1
|
|
|
|
- ).padStart(2, "0")}-${String(now.getDate()).padStart(
|
|
|
|
- 2,
|
|
|
|
- "0"
|
|
|
|
- )} ${String(now.getHours()).padStart(2, "0")}:${String(
|
|
|
|
- now.getMinutes()
|
|
|
|
- ).padStart(2, "0")}`;
|
|
|
|
- if (!isWmpf) {
|
|
|
|
- this.getVoipDevices();
|
|
|
|
- }
|
|
|
|
- console.log("处理后的 CMD 数据:", data);
|
|
|
|
- },
|
|
|
|
- (err) => {
|
|
|
|
- if (!err) console.log(`✅ 页面B 已订阅 ${topic}`);
|
|
|
|
- }
|
|
|
|
- );
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // if (MqttService.cmdConnected) {
|
|
|
|
- // this.unsubscribeFn = MqttService.subscribe(
|
|
|
|
- // "CMD",
|
|
|
|
- // topic,
|
|
|
|
- // (topic, message) => {
|
|
|
|
- // const data = JSON.parse(message);
|
|
|
|
- // let userId = uni.getStorageSync("userId");
|
|
|
|
- // const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
|
- // const match = topic.match(noticeMatch);
|
|
|
|
- // if (!match) return;
|
|
|
|
- // // 更新页面数据
|
|
|
|
- // this.alarmModel = true;
|
|
|
|
- // this.clientId = data.clientId;
|
|
|
|
- // this.devName = data.devName;
|
|
|
|
- // this.sn = data.clientId;
|
|
|
|
- // this.eventListId = data.eventListId;
|
|
|
|
- // // VOIP 相关逻辑
|
|
|
|
- // this.getVoipAuthor(this.clientId, userId);
|
|
|
|
- // // 格式化时间
|
|
|
|
- // const now = new Date();
|
|
|
|
- // this.nowTime = `${now.getFullYear()}-${String(
|
|
|
|
- // now.getMonth() + 1
|
|
|
|
- // ).padStart(2, "0")}-${String(now.getDate()).padStart(
|
|
|
|
- // 2,
|
|
|
|
- // "0"
|
|
|
|
- // )} ${String(now.getHours()).padStart(2, "0")}:${String(
|
|
|
|
- // now.getMinutes()
|
|
|
|
- // ).padStart(2, "0")}`;
|
|
|
|
- // if (!isWmpf) {
|
|
|
|
- // this.getVoipDevices();
|
|
|
|
- // }
|
|
|
|
- // console.log("处理后的 CMD 数据:", data);
|
|
|
|
- // }
|
|
|
|
- // );
|
|
|
|
- // } else {
|
|
|
|
- // uni.$once("mqtt-ready", () => {
|
|
|
|
- // this.unsubscribeFn = MqttService.subscribe(
|
|
|
|
- // "CMD",
|
|
|
|
- // topic,
|
|
|
|
- // (topic, message) => {
|
|
|
|
- // const data = JSON.parse(message);
|
|
|
|
- // let userId = uni.getStorageSync("userId");
|
|
|
|
- // const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
|
- // const match = topic.match(noticeMatch);
|
|
|
|
- // if (!match) return;
|
|
|
|
- // // 更新页面数据
|
|
|
|
- // this.alarmModel = true;
|
|
|
|
- // this.clientId = data.clientId;
|
|
|
|
- // this.devName = data.devName;
|
|
|
|
- // this.sn = data.clientId;
|
|
|
|
- // this.eventListId = data.eventListId;
|
|
|
|
- // // VOIP 相关逻辑
|
|
|
|
- // this.getVoipAuthor(this.clientId, userId);
|
|
|
|
- // // 格式化时间
|
|
|
|
- // const now = new Date();
|
|
|
|
- // this.nowTime = `${now.getFullYear()}-${String(
|
|
|
|
- // now.getMonth() + 1
|
|
|
|
- // ).padStart(2, "0")}-${String(now.getDate()).padStart(
|
|
|
|
- // 2,
|
|
|
|
- // "0"
|
|
|
|
- // )} ${String(now.getHours()).padStart(2, "0")}:${String(
|
|
|
|
- // now.getMinutes()
|
|
|
|
- // ).padStart(2, "0")}`;
|
|
|
|
- // if (!isWmpf) {
|
|
|
|
- // this.getVoipDevices();
|
|
|
|
- // }
|
|
|
|
- // console.log("处理后的 CMD 数据:", data);
|
|
|
|
- // }
|
|
|
|
- // );
|
|
|
|
- // });
|
|
|
|
- // }
|
|
|
|
|
|
+ console.log("处理后的 CMD 数据:", data);
|
|
|
|
+ },
|
|
|
|
+ (err) => {
|
|
|
|
+ if (!err) console.log(`✅ 页面B 已订阅 ${topic}`);
|
|
|
|
+ }
|
|
|
|
+ );
|
|
},
|
|
},
|
|
|
|
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
- if (this.unsubscribeCmd) {
|
|
|
|
- this.unsubscribeCmd();
|
|
|
|
- this.unsubscribeCmd = null;
|
|
|
|
- console.log("CMD 订阅已取消");
|
|
|
|
|
|
+ if (this.unsubscribeFnNotice) {
|
|
|
|
+ this.unsubscribeFnNotice();
|
|
|
|
+ this.unsubscribeFnNotice = null;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
};
|
|
};
|