wangming 2 сар өмнө
parent
commit
2fce0767eb

+ 26 - 16
src/components/component/alarModel.vue

@@ -55,6 +55,7 @@ import {
     isWmpf,
 } from "../../const.js";
 import { AsyncValue } from "../../utils";
+import { onLoad } from "@dcloudio/uni-app";
 
 const wmpfVoip = requirePlugin("wmpf-voip").default;
 const envVersion = wx.getAccountInfoSync().miniProgram.envVersion;
@@ -74,9 +75,12 @@ const getEnvVersionForVoip = (function () {
 })();
 
 export default {
+    comments: {
+        name: "alarModel",
+    },
     data() {
         return {
-            alarmModel: false,
+            alarmModel: true,
             nowTime: "2025-06-20 10:30:00",
             devName: "我的第一台设备",
             localPhone: "13888888888",
@@ -374,7 +378,7 @@ export default {
             }
         },
 
-        connectMQTT(clientId, devId) {
+        connectMQTT() {
             const THRESHOLD = 2;
             const params = {
                 keepalive: 60,
@@ -407,16 +411,14 @@ export default {
             this.mqttClient = client;
             client.on("connect", () => {
                 console.log("MQTT连接成功");
-                client.subscribe(
-                    `/mps/wx_${uni.setStorageSync("userId")}/notice`,
-                    (err) => {
-                        if (err) {
-                            console.error("订阅失败", err);
-                        } else {
-                            console.log(`成功订阅设备主题: device/${clientId}`);
-                        }
+                let userId = uni.getStorageSync("userId");
+                client.subscribe(`/mps/wx_${userId}/notice`, (err) => {
+                    if (err) {
+                        console.error("订阅失败", err);
+                    } else {
+                        console.log(`成功订阅设备主题: device/${clientId}`);
                     }
-                );
+                });
             });
             client.on("disconnect", () => {
                 console.log("MQTT不在连接");
@@ -442,20 +444,28 @@ export default {
             });
         },
     },
-    onLoad(options) {
+    attached() {
+        console.log("子组件打印了");
         if (!isWmpf) {
             this.getVoipDevices();
         }
         this.connectMQTT();
     },
-    onUnload() {
-        if (this.mqttClient) this.mqttClient.end(true);
-        clearInterval(this.autoPlayinterval);
-        clearInterval(this.inactivityTimer);
+    onLoad() {
+        console.log("子组件打印了");
+        if (!isWmpf) {
+            this.getVoipDevices();
+        }
+        this.connectMQTT();
     },
     onHide() {
         if (this.mqttClient) this.mqttClient.end(true);
+        clearInterval(this.autoPlayinterval);
+        clearInterval(this.inactivityTimer);
     },
+    // onHide() {
+    //     if (this.mqttClient) this.mqttClient.end(true);
+    // },
     onShareAppMessage() {},
 };
 </script>

+ 2 - 2
src/main.js

@@ -10,8 +10,8 @@ import {
     http
 } from "./components/js_sdk/index";
 
-import alarmCom from "./components/component/alarModel.vue";
-Vue.component('alarmCom', alarmCom);
+import alarModel from "./components/component/alarModel.vue";
+Vue.component('alarModel', alarModel);
 
 Vue.prototype.$store = store;
 Vue.prototype.$http = http;

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

@@ -82,9 +82,7 @@
             <button open-type="contact">联系客服</button>
         </view>
         <view class="bot_version"> v3.0.1 </view>
-        <!-- <view class="headerInfo">111111</view> -->
-
-        <alarmCom></alarmCom>
+        <alarModel />
     </view>
 </template>
 <script>