wangming 1 сар өмнө
parent
commit
2a0644921b

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

@@ -1,6 +1,6 @@
 <template>
     <!-- 告警弹窗 -->
-    <view>
+    <view style="z-index: 999">
         <view class="mask" v-if="alarmModel"></view>
         <view class="alarm-modal" v-if="alarmModel">
             <view class="alarm">
@@ -57,6 +57,7 @@ import {
     isWmpf,
 } from "../../const.js";
 import { AsyncValue } from "../../utils";
+import { onShow } from "@dcloudio/uni-app";
 const wmpfVoip = requirePlugin("wmpf-voip").default;
 const envVersion = wx.getAccountInfoSync().miniProgram.envVersion;
 const apiTypes = ["校园模式", "硬件模式", "呼叫安卓", "校园+硬件模式"];
@@ -497,6 +498,9 @@ export default {
                 console.log(JSON.parse(message.toString()), "8870");
                 // 处理点位消息
                 let userId = uni.getStorageSync("userId");
+
+                console.log("topic777777", userId);
+
                 const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
                 const match = topic.match(noticeMatch);
                 if (!match) return;
@@ -597,6 +601,10 @@ export default {
     // mounted() {
     //     this.connectMQTTwo();
     // },
+
+    // onShow() {
+    //     console.log("开始接受消息", "99999");
+    // },
     mounted() {
         console.log("开始接受消息", "8870");
         // 通过全局 MQTT 客户端订阅主题或监听消息

+ 1 - 1
src/components/component/tenMinutes.vue

@@ -81,7 +81,7 @@ const getEnvVersionForVoip = (function () {
 
 export default {
     comments: {
-        name: "alarModel",
+        name: "tenMinutes",
     },
     data() {
         return {

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

@@ -138,7 +138,7 @@
             <image src="../../static/arrFour.png" class="warmImage"></image>
         </view>
         <tenMinutes v-if="isIniTenMinutes" />
-        <alarModel />
+        <alarModel v-if="showModle" />
     </view>
 </template>
 <script>
@@ -158,6 +158,7 @@ export default {
             alarmRetentionLists: [],
             warmTypeList: [],
             isIniTenMinutes: false,
+            showModle: false,
         };
     },
     computed: {},
@@ -311,6 +312,7 @@ export default {
     },
     onLoad() {},
     onShow() {
+        this.showModle = true;
         if (uni.getStorageSync("userId")) {
             this.getperSonInfo();
             this.getShareNum();
@@ -326,9 +328,11 @@ export default {
     },
     onHide() {
         this.isIniTenMinutes = false;
+        this.showModle = false;
     },
     onUnload() {
         this.isIniTenMinutes = false;
+        this.showModle = false;
     },
 
     onShareAppMessage() {

+ 30 - 10
src/pagesA/deviceDetail/deviceDetail.vue

@@ -360,13 +360,14 @@
                 @click="breathShow = false"
             ></l-echart>
         </view>
-        <alarModel />
+        <alarModel v-if="showModle" />
     </view>
 </template>
 <script>
 import * as echarts from "../../uni_modules/lime-echart/static/echarts.min";
-
 import mqtt from "../../utils/mqtt";
+// import { createMqttData } from "../../utils/globalMqtt";
+import { createMqttData } from "../../utils/globalMqtt";
 
 export default {
     data() {
@@ -469,6 +470,8 @@ export default {
             loopTimer: null,
             mqttClienTwoFlag: false,
             mqttClientOne: false,
+            mqttData: null,
+            showModle: false,
         };
     },
     computed: {},
@@ -1098,6 +1101,8 @@ export default {
     onShow() {
         this.clientIdProp = uni.getStorageSync("clientIDetail");
         this.todayDate = this.$time(new Date(), 2);
+        this.showModle = true;
+        console.log(this.showModle, "showModle");
     },
     onLoad(options) {
         const devItem = this.parseDeviceItem(options.devItem);
@@ -1109,21 +1114,36 @@ export default {
             this.autoSwipe();
         }, 3000);
         this.getCurrentDate();
-        this.connectMqtt();
-    },
-    onShow() {
-        this.connectMqtt();
+        // this.connectMqtt();
+
+        console.log(clientId, "clientId88888");
+        this.mqttData = createMqttData(clientId);
+
+        if (this.mqttData) {
+            this.mqttData.on("message", (topic, message) => {
+                this.handleMessage(topic, message, clientId);
+            });
+        }
     },
-    onSh() {},
     onUnload() {
         this.inactivityTimer = null;
         this.autoPlayinterval = null;
-        this.closemqtTwo();
+        this.showModle = false;
+        if (this.mqttData) {
+            this.mqttData.end();
+            this.mqttData = null;
+            console.log("页面 DATA MQTT 已断开");
+        }
     },
     onHide() {
         this.inactivityTimer = null;
         this.autoPlayinterval = null;
-        this.closemqtTwo();
+        this.showModle = false;
+        if (this.mqttData) {
+            this.mqttData.end();
+            this.mqttData = null;
+            console.log("页面 DATA MQTT 已断开");
+        }
     },
 };
 </script>
@@ -1582,7 +1602,7 @@ export default {
             position: fixed;
             top: 10rpx;
             right: 10rpx;
-            z-index: 999;
+            z-index: 333;
         }
     }
 }

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

@@ -69,7 +69,7 @@
             </view>
         </view>
 
-        <alarModel />
+        <alarModel v-if="showModle" />
     </view>
 </template>
 
@@ -82,6 +82,7 @@ export default {
             selectValue: 0,
             devs: [],
             isInitAlarm: false,
+            showModle: false,
         };
     },
     methods: {
@@ -172,9 +173,14 @@ export default {
     onLoad() {},
     onShow() {
         this.queryList();
+        this.showModle = true;
+    },
+    onHide() {
+        this.showModle = false;
+    },
+    onUnload() {
+        this.showModle = false;
     },
-    onHide() {},
-    onUnload() {},
 
     onPullDownRefresh() {
         uni.showNavigationBarLoading();

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

@@ -42,7 +42,7 @@
             </picker>
         </view>
 
-        <alarModel />
+        <alarModel v-if="showModle" />
     </view>
 </template>
 <script>
@@ -56,6 +56,7 @@ export default {
             // 已经新增的守护计划
             selectedPlan: [],
             changFlage: false,
+            showModle: false,
         };
     },
     computed: {},
@@ -230,11 +231,16 @@ export default {
         this.devInfo = JSON.parse(options.devInfo);
     },
     onShow() {
+        this.showModle = true;
         this.getPlanList();
         this.getSelectPlan();
     },
-    onHide() {},
-    onUnload() {},
+    onHide() {
+        this.showModle = false;
+    },
+    onUnload() {
+        this.showModle = false;
+    },
 };
 </script>
 <style lang="less" scoped>

+ 8 - 7
src/pagesA/my/my.vue

@@ -49,7 +49,8 @@
 
         <view class="logoutBtn" @click="goLogout">退出登录</view>
 
-        <tenMinutes v-if="isIniTenMinutes" />
+        <!-- <tenMinutes v-if="isIniTenMinutes" /> -->
+        <alarModel v-if="showModle" />
     </view>
 </template>
 
@@ -57,8 +58,9 @@
 export default {
     data() {
         return {
-            headerImg: "../../static/headerInfo.png",
+            headerImg: "../../static/headerInfo.jpg",
             phone: uni.getStorageSync("phone"),
+            showModle: false,
         };
     },
     methods: {
@@ -135,16 +137,15 @@ export default {
     },
     onShow() {
         this.isIniTenMinutes = true;
+        this.showModle = true;
     },
-    onLoad() {
-        this.isIniTenMinutes = true;
-    },
+    onLoad() {},
     onHide() {
-        this.isIniTenMinutes = false;
+        this.showModle = false;
     },
 
     onUnload() {
-        this.isIniTenMinutes = false;
+        this.showModle = false;
     },
 };
 </script>

+ 64 - 7
src/utils/globalMqtt.js

@@ -1,6 +1,16 @@
 import mqtt from './mqtt';
 
+let mqttClientCmd = null;   // 全局 CMD MQTT
+let mqttClientData = null;  // 全局 DATA MQTT
+
+let mqttCmdConnected = false;
+let mqttDataConnected = false;
+
 export function createMqttClient() {
+    if (mqttCmdConnected) {
+        console.log("CMD MQTT 已连接");
+        return mqttClientCmd;
+    }
     const params = {
         keepalive: 6000,
         clean: true,
@@ -23,7 +33,6 @@ export function createMqttClient() {
             },
         },
     };
-
     let client = "";
     // const selectedService = uni.getStorageSync("sercviceChoice");
     // if (!selectedService || selectedService == "aloneServe") {
@@ -36,8 +45,8 @@ export function createMqttClient() {
     //     client = mqtt.connect("wxs://cmd.radar-power.cn/mqtt/", params);
     // }
     client = mqtt.connect("wxs://cmd.radar-power.cn/mqtt/", params);
-
     client.on("connect", () => {
+        mqttCmdConnected = true;
         console.log("MQTTCMD连接成功");
         const userId = uni.getStorageSync("userId");
         client.subscribe(`/mps/wx_${userId}/notice`, (err) => {
@@ -48,7 +57,6 @@ export function createMqttClient() {
             }
         });
     });
-
     client.on("message", (topic, message) => {
         console.log("topic", topic, message);
         console.log("接收到消息:", JSON.parse(message.toString()));
@@ -56,10 +64,9 @@ export function createMqttClient() {
         const noticeMatch = /^\/mps\/wx_(.+)\/notice$/;
         const match = topic.match(noticeMatch);
         if (!match) return;
-        // 处理消息
     });
-
     client.on("error", (err) => {
+        mqttCmdConnected = false;
         console.error("MQTT连接错误:", err);
         // 连接失败时重新尝试连接
         setTimeout(() => {
@@ -68,8 +75,58 @@ export function createMqttClient() {
     });
 
     client.on("disconnect", () => {
+        mqttCmdConnected = false;
         console.log("MQTT断开连接");
     });
-
     return client;
-}
+}
+
+// 创建data连接
+export function createMqttData(clientIdProp) {
+    if (!clientIdProp) {
+        console.warn("DATA MQTT 创建失败:缺少 clientIdProp");
+        return null;
+    }
+
+    if (mqttDataConnected) return mqttClientData;
+
+    const params = {
+        keepalive: 6000,
+        clean: true,
+        connectTimeout: 10000,
+        clientId: "xcx_mqtt_data1_" + clientIdProp + "_" + Date.now(),
+        username: "lnradar",
+        password: "lnradar",
+        WebSocket: function (url) {
+            return wx.connectSocket({
+                url: url,
+                header: {
+                    "content-type": "application/json",
+                },
+                protocols: ["mqtt"],
+            });
+        },
+        reconnectPeriod: 2000
+    };
+
+    mqttClientData = mqtt.connect("wxs://data.radar-power.cn/mqtt/", params);
+
+    mqttClientData.on("connect", () => {
+        console.log("DATA MQTT 连接成功");
+        mqttDataConnected = true;
+        mqttClientData.subscribe(`/dev/${clientIdProp}/tracker_targets`, (err) => {
+            if (err) console.error("DATA MQTT 订阅失败", err);
+            else console.log(`DATA MQTT 订阅成功: /dev/${clientIdProp}/tracker_targets`);
+        });
+    });
+
+    mqttClientData.on("message", (topic, message) => {
+        console.log("DATA MQTT 消息:", topic, message.toString());
+        // handleDataMessage(topic, message, clientIdProp);
+    });
+
+    mqttClientData.on("error", (err) => { mqttDataConnected = false; console.error(err); });
+    mqttClientData.on("disconnect", () => { mqttDataConnected = false; console.log("DATA MQTT 断开"); });
+
+    return mqttClientData;
+}