wangming 1 месяц назад
Родитель
Сommit
54b0818290
4 измененных файлов с 88 добавлено и 308 удалено
  1. 40 253
      src/components/component/alarModel.vue
  2. 15 12
      src/components/js_sdk/index.js
  3. 12 12
      src/main.js
  4. 21 31
      src/pagesA/deviceDetail/deviceDetail.vue

+ 40 - 253
src/components/component/alarModel.vue

@@ -637,265 +637,52 @@ export default {
         },
     },
     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 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() {
-        if (this.unsubscribeCmd) {
-            this.unsubscribeCmd();
-            this.unsubscribeCmd = null;
-            console.log("CMD 订阅已取消");
+        if (this.unsubscribeFnNotice) {
+            this.unsubscribeFnNotice();
+            this.unsubscribeFnNotice = null;
         }
     },
 };

+ 15 - 12
src/components/js_sdk/index.js

@@ -3,23 +3,26 @@ const http = new Request();
 http.setConfig(config => {
     /* 设置全局配置 */
     if (__wxConfig.envVersion == 'develop') {
-        let selectedService = uni.getStorageSync("sercviceChoice")
-        if (!selectedService || selectedService == 'aloneServe') {
-            // config.baseUrl = "https://api.radar-power.asia:4443/portal-service-server/";
-        }
+        // let selectedService = uni.getStorageSync("sercviceChoice")
+        // if (!selectedService || selectedService == 'aloneServe') {
+        //     config.baseUrl = "https://api.radar-power.asia:4443/portal-service-server/";
+        // }
         config.baseUrl = "https://radar-power.cn/portal-service-server/";
+        // config.baseUrl = "https://api.radar-power.asia:4443/portal-service-server/";
     }
     if (__wxConfig.envVersion == 'trial') {
-        let selectedService = uni.getStorageSync("sercviceChoice")
-        if (!selectedService || selectedService == 'aloneServe') {
-            config.baseUrl = "https://radar-power.cn/portal-service-server/";
-        }
+        // let selectedService = uni.getStorageSync("sercviceChoice")
+        // if (!selectedService || selectedService == 'aloneServe') {
+        //     config.baseUrl = "https://radar-power.cn/portal-service-server/";
+        // }
+        config.baseUrl = "https://radar-power.cn/portal-service-server/";
     }
     if (__wxConfig.envVersion == 'release') {
-        let selectedService = uni.getStorageSync("sercviceChoice")
-        if (!selectedService || selectedService == 'aloneServe') {
-            config.baseUrl = "https://radar-power.cn/portal-service-server/";
-        }
+        // let selectedService = uni.getStorageSync("sercviceChoice")
+        // if (!selectedService || selectedService == 'aloneServe') {
+        //     config.baseUrl = "https://radar-power.cn/portal-service-server/";
+        // }
+        config.baseUrl = "https://radar-power.cn/portal-service-server/";
     }
     config.header = {
         // a: 1,

+ 12 - 12
src/main.js

@@ -24,22 +24,22 @@ Vue.prototype.$initMqtt = function () {
     }
 
     // 连接 CMD
-    MqttService.connectCmd(userId)
-        .then(client => {
-            console.log("CMD MQTT 初始化完成", client);
-        })
-        .catch(err => {
-            console.error("CMD MQTT 初始化失败", err);
-        });
-
-    // 连接 DATA
-    // MqttService.connectData(userId)
+    // MqttService.connectCmd(userId)
     //     .then(client => {
-    //         console.log("DATA MQTT 初始化完成", client);
+    //         console.log("CMD MQTT 初始化完成", client);
     //     })
     //     .catch(err => {
-    //         console.error("DATA MQTT 初始化失败", err);
+    //         console.error("CMD MQTT 初始化失败", err);
     //     });
+
+    // 连接 DATA
+    MqttService.connectData(userId)
+        .then(client => {
+            console.log("DATA MQTT 初始化完成", client);
+        })
+        .catch(err => {
+            console.error("DATA MQTT 初始化失败", err);
+        });
 }
 
 

+ 21 - 31
src/pagesA/deviceDetail/deviceDetail.vue

@@ -937,11 +937,6 @@ export default {
             }
         },
         createNewTargetPoint(x, y, z, id) {
-            console.log(
-                this.devInfo.xxStart,
-                this.devInfo.yyEnd,
-                " this.devInfo.yyEnd"
-            );
             return {
                 x,
                 y,
@@ -993,33 +988,28 @@ export default {
         this.clientId = clientId;
         let userId = uni.getStorageSync("userId");
 
-        MqttService.connectData(userId).then((client) => {
-            const topic = `/dev/${this.clientId}/tracker_targets`;
-            // 使用 MqttService.subscribe 管理订阅
-            this.unsubscribeFn = MqttService.subscribe(
-                "DATA",
-                topic,
-                (message, msgTopic) => {
-                    console.log(`接收到 ${msgTopic} 消息:`, message);
-                    // 处理消息
-                    const dataMatch = msgTopic.match(
-                        /^\/dev\/(.+)\/tracker_targets$/
-                    );
-                    const cmdMatch = msgTopic.match(/^\/mps\/wx_(.+)\/notice$/);
-                    if (dataMatch && dataMatch[1] === this.clientId) {
-                        this.handleMessage(msgTopic, message, this.clientId);
-                    } else if (cmdMatch) {
-                        this.$refs.alarmModel.hanOtherMessage(
-                            msgTopic,
-                            message
-                        );
-                    }
+        const topic = `/dev/${this.clientId}/tracker_targets`;
+        // 使用 MqttService.subscribe 管理订阅
+        this.unsubscribeFn = MqttService.subscribe(
+            "DATA",
+            topic,
+            (message, msgTopic) => {
+                console.log(`接收到 ${msgTopic} 消息:`, message);
+                // 处理消息
+                const dataMatch = msgTopic.match(
+                    /^\/dev\/(.+)\/tracker_targets$/
+                );
+                const cmdMatch = msgTopic.match(/^\/mps\/wx_(.+)\/notice$/);
+                if (dataMatch && dataMatch[1] === this.clientId) {
+                    this.handleMessage(msgTopic, message, this.clientId);
+                } else if (cmdMatch) {
+                    this.$refs.alarmModel.hanOtherMessage(msgTopic, message);
                 }
-            );
-            if (this.unsubscribeFn) {
-                console.log(`✅ 已成功订阅主题: ${topic}`);
             }
-        });
+        );
+        if (this.unsubscribeFn) {
+            console.log(`✅ 已成功订阅主题: ${topic}`);
+        }
     },
     onUnload() {
         this.inactivityTimer = null;
@@ -1029,7 +1019,7 @@ export default {
             this.unsubscribeFn = null;
         }
         // 关闭 DATA 连接
-        MqttService.disconnectData();
+        // MqttService.disconnectData();
     },
     onHide() {
         this.showModle = false;