wangming vor 1 Monat
Ursprung
Commit
84803fb7f7

+ 44 - 1
src/components/component/alarModel.vue

@@ -594,8 +594,51 @@ export default {
             this.$emit("sendChange", this.targetPoints);
         },
     },
+    // mounted() {
+    //     this.connectMQTTwo();
+    // },
     mounted() {
-        this.connectMQTTwo();
+        console.log("开始接受消息", "8870");
+        // 通过全局 MQTT 客户端订阅主题或监听消息
+        this.$mqttClient.on("message", (topic, message) => {
+            console.log("接收到消息CMD:", 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);
+        });
     },
 
     beforeDestroy() {

+ 0 - 3
src/components/component/tenMinutes.vue

@@ -505,9 +505,6 @@ export default {
     mounted() {
         this.getFallingEventsQuery();
     },
-    onHide() {
-        uni.hideLoading();
-    },
 };
 </script>
 

+ 2 - 2
src/components/js_sdk/index.js

@@ -5,9 +5,9 @@ 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/";
+            // config.baseUrl = "https://api.radar-power.asia:4443/portal-service-server/";
         }
-        // config.baseUrl = "https://radar-power.cn/portal-service-server/";
+        config.baseUrl = "https://radar-power.cn/portal-service-server/";
     }
     if (__wxConfig.envVersion == 'trial') {
         let selectedService = uni.getStorageSync("sercviceChoice")

+ 10 - 0
src/main.js

@@ -1,6 +1,12 @@
 import Vue from 'vue'
 import App from './App'
 import './uni.promisify.adaptor'
+// import {
+//     createMqttClient
+// } from "./utils/globalMqtt";
+
+import { createMqttClient } from './utils/globalMqtt';
+
 
 import {
     http
@@ -14,6 +20,10 @@ Vue.component('tenMinutes', tenMinutes);
 
 Vue.prototype.$http = http;
 
+// 挂载mqtt
+const mqttClient = createMqttClient();
+Vue.prototype.$mqttClient = mqttClient;
+
 // 挂载处理时间的方法
 function timestampToTime(value, type = 0) {
     var time = new Date(value);

+ 1 - 5
src/pages/home/home.vue

@@ -138,7 +138,7 @@
             <image src="../../static/arrFour.png" class="warmImage"></image>
         </view>
         <tenMinutes v-if="isIniTenMinutes" />
-        <alarModel v-if="isInitAlarm" />
+        <alarModel />
     </view>
 </template>
 <script>
@@ -157,7 +157,6 @@ export default {
             warmDetail: [],
             alarmRetentionLists: [],
             warmTypeList: [],
-            isInitAlarm: false,
             isIniTenMinutes: false,
         };
     },
@@ -317,7 +316,6 @@ export default {
             this.getShareNum();
             this.getwarmType();
             this.getWarnList();
-            this.isInitAlarm = true;
             this.isIniTenMinutes = true;
         }
         // 配置服务器
@@ -327,11 +325,9 @@ export default {
         }
     },
     onHide() {
-        this.isInitAlarm = false;
         this.isIniTenMinutes = false;
     },
     onUnload() {
-        this.isInitAlarm = false;
         this.isIniTenMinutes = false;
     },
 

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

@@ -360,19 +360,7 @@
                 @click="breathShow = false"
             ></l-echart>
         </view>
-
-        <!-- <alarModel
-            v-if="isInitAlarm"
-            :clientIdProp="clientIdProp"
-            @sendChange="receptionChange"
-            @sendHealth="receptHealth"
-        /> -->
-
-        <!-- <alarModel
-            v-if="isInitAlarm"
-            @sendChange="receptionChange"
-            @sendHealth="receptHealth"
-        /> -->
+        <alarModel />
     </view>
 </template>
 <script>
@@ -418,8 +406,6 @@ export default {
             messageFlag: true,
             serviceNumberFlag: true,
             voipFlag: true,
-            isInitAlarm: "",
-
             // mqtt模块
             targetPoints: {},
             inactivityTimer: null,
@@ -917,8 +903,6 @@ export default {
                         });
                     },
                 },
-                reconnectPeriod: 0,
-                rejectUnauthorized: false,
             };
             let clientTwo = "";
             let selectedService = uni.getStorageSync("sercviceChoice");
@@ -936,6 +920,7 @@ export default {
                     );
                 }
             }
+            clientTwo = mqtt.connect("wxs://data.radar-power.cn/mqtt/", params);
             console.log("主题开始订阅5555");
             // 存储client引用以便后续操作
             this.mqttClientOne = clientTwo;
@@ -1112,7 +1097,6 @@ export default {
     },
     onShow() {
         this.clientIdProp = uni.getStorageSync("clientIDetail");
-        this.isInitAlarm = true;
         this.todayDate = this.$time(new Date(), 2);
     },
     onLoad(options) {
@@ -1125,12 +1109,13 @@ export default {
             this.autoSwipe();
         }, 3000);
         this.getCurrentDate();
+        this.connectMqtt();
     },
-    onReady() {
+    onShow() {
         this.connectMqtt();
     },
+    onSh() {},
     onUnload() {
-        this.isInitAlarm = false;
         this.inactivityTimer = null;
         this.autoPlayinterval = null;
         this.closemqtTwo();
@@ -1138,7 +1123,6 @@ export default {
     onHide() {
         this.inactivityTimer = null;
         this.autoPlayinterval = null;
-        this.isInitAlarm = false;
         this.closemqtTwo();
     },
 };

+ 3 - 26
src/pagesA/devices/devices.vue

@@ -69,7 +69,7 @@
             </view>
         </view>
 
-        <alarModel v-if="isInitAlarm" />
+        <alarModel />
     </view>
 </template>
 
@@ -145,24 +145,6 @@ export default {
                             } else {
                                 devs[i].wcTimes = 0;
                             }
-                            // if (devs[i].lastTargetTime) {
-                            //     const signalTimeStr = devs[
-                            //         i
-                            //     ].lastTargetTime.replace(/-/g, "/");
-                            //     const signalTime = new Date(
-                            //         signalTimeStr
-                            //     ).getTime();
-
-                            //     if (isNaN(signalTime)) {
-                            //         devs[i].judge = false;
-                            //     } else {
-                            //         const currentTime = Date.now();
-                            //         const diff = Math.abs(
-                            //             currentTime - signalTime
-                            //         );
-                            //         devs[i].judge = diff <= 5000; // 10秒内为 true
-                            //     }
-                            // }
                         }
                         this.devs = devs;
                     }
@@ -189,15 +171,10 @@ export default {
     },
     onLoad() {},
     onShow() {
-        this.isInitAlarm = true;
         this.queryList();
     },
-    onHide() {
-        this.isInitAlarm = false;
-    },
-    onUnload() {
-        this.isInitAlarm = false;
-    },
+    onHide() {},
+    onUnload() {},
 
     onPullDownRefresh() {
         uni.showNavigationBarLoading();

+ 3 - 9
src/pagesA/healthAlarm/healthAlarm.vue

@@ -42,7 +42,7 @@
             </picker>
         </view>
 
-        <alarModel v-if="isInitAlarm" />
+        <alarModel />
     </view>
 </template>
 <script>
@@ -56,7 +56,6 @@ export default {
             // 已经新增的守护计划
             selectedPlan: [],
             changFlage: false,
-            isInitAlarm: false,
         };
     },
     computed: {},
@@ -233,14 +232,9 @@ export default {
     onShow() {
         this.getPlanList();
         this.getSelectPlan();
-        this.isInitAlarm = true;
-    },
-    onHide() {
-        this.isInitAlarm = false;
-    },
-    onUnload() {
-        this.isInitAlarm = false;
     },
+    onHide() {},
+    onUnload() {},
 };
 </script>
 <style lang="less" scoped>

+ 75 - 0
src/utils/globalMqtt.js

@@ -0,0 +1,75 @@
+import mqtt from './mqtt';
+
+export function createMqttClient() {
+    const params = {
+        keepalive: 6000,
+        clean: true,
+        connectTimeout: 30 * 1000,
+        clientId:
+            "xcx_mqtt_cmd1" +
+            uni.getStorageSync("userId") +
+            Math.random().toString(16).substring(2, 8),
+        username: "lnradar",
+        password: "lnradar",
+        wsOptions: {
+            WebSocket: function (url) {
+                return wx.connectSocket({
+                    url: url,
+                    header: {
+                        "content-type": "application/json",
+                    },
+                    protocols: ["mqtt"],
+                });
+            },
+        },
+    };
+
+    let client = "";
+    // const selectedService = uni.getStorageSync("sercviceChoice");
+    // if (!selectedService || selectedService == "aloneServe") {
+    //     if (__wxConfig.envVersion == "develop") {
+    //         client = mqtt.connect("wxs://cmd.radar-power.cn/mqtt/", params);
+    //     }
+    //     if (__wxConfig.envVersion == "trial") {
+    //         client = mqtt.connect("wxs://cmd.radar-power.cn/mqtt/", params);
+    //     }
+    //     client = mqtt.connect("wxs://cmd.radar-power.cn/mqtt/", params);
+    // }
+    client = mqtt.connect("wxs://cmd.radar-power.cn/mqtt/", params);
+
+    client.on("connect", () => {
+        console.log("MQTTCMD连接成功");
+        const userId = uni.getStorageSync("userId");
+        client.subscribe(`/mps/wx_${userId}/notice`, (err) => {
+            if (err) {
+                console.error("订阅失败", err);
+            } else {
+                console.log(`成功订阅设备主题: /mps/wx_${userId}/notice`);
+            }
+        });
+    });
+
+    client.on("message", (topic, message) => {
+        console.log("topic", topic, message);
+        console.log("接收到消息:", JSON.parse(message.toString()));
+        const userId = uni.getStorageSync("userId");
+        const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
+        const match = topic.match(noticeMatch);
+        if (!match) return;
+        // 处理消息
+    });
+
+    client.on("error", (err) => {
+        console.error("MQTT连接错误:", err);
+        // 连接失败时重新尝试连接
+        setTimeout(() => {
+            createMqttClient();  // 重新连接
+        }, 1000);
+    });
+
+    client.on("disconnect", () => {
+        console.log("MQTT断开连接");
+    });
+
+    return client;
+}