|
@@ -639,85 +639,50 @@ export default {
|
|
mounted() {
|
|
mounted() {
|
|
const userId = uni.getStorageSync("userId");
|
|
const userId = uni.getStorageSync("userId");
|
|
const topic = `/mps/wx_${userId}/notice`;
|
|
const topic = `/mps/wx_${userId}/notice`;
|
|
- 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();
|
|
|
|
- }
|
|
|
|
- console.log("处理后的 CMD 数据:", data);
|
|
|
|
- },
|
|
|
|
- (err) => {
|
|
|
|
- if (!err) console.log(`✅ 页面组件 已订阅 ${topic}`);
|
|
|
|
|
|
+
|
|
|
|
+ // 抽取处理消息的方法
|
|
|
|
+ const handleMessage = (message, msgTopic) => {
|
|
|
|
+ console.log(`接收到 ${msgTopic} 消息:`, message);
|
|
|
|
+ const data = JSON.parse(message);
|
|
|
|
+ const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
|
|
|
|
+ if (!topic.match(noticeMatch)) 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();
|
|
}
|
|
}
|
|
- );
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- uni.$on("mqttDataReadyOnce", (client) => {
|
|
|
|
|
|
+ // 抽取订阅的方法
|
|
|
|
+ const subscribeNotice = () => {
|
|
this.unsubscribeFnNotice = MqttService.subscribe(
|
|
this.unsubscribeFnNotice = MqttService.subscribe(
|
|
"DATA",
|
|
"DATA",
|
|
topic,
|
|
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();
|
|
|
|
- }
|
|
|
|
- console.log("处理后的 CMD 数据:", data);
|
|
|
|
- },
|
|
|
|
|
|
+ handleMessage,
|
|
(err) => {
|
|
(err) => {
|
|
if (!err) console.log(`✅ 页面组件 已订阅 ${topic}`);
|
|
if (!err) console.log(`✅ 页面组件 已订阅 ${topic}`);
|
|
}
|
|
}
|
|
);
|
|
);
|
|
- });
|
|
|
|
|
|
+ };
|
|
|
|
+ // 初始订阅
|
|
|
|
+ subscribeNotice();
|
|
|
|
+ uni.$on("mqttDataReadyOnce", subscribeNotice);
|
|
},
|
|
},
|
|
|
|
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|