wangming 2 mesiacov pred
rodič
commit
431f5a22ee

+ 77 - 6
src/components/component/alarModel.vue

@@ -158,7 +158,6 @@ export default {
         handleAlarm() {
             this.alarmModel = false;
         },
-
         // voip相关方法
         async getVoipDevices() {
             const { list } = await getDeviceVoIPList();
@@ -246,7 +245,6 @@ export default {
             };
             await this.call(voiceCan);
         },
-
         async getSelf(options = {}) {
             if (!this._caller.isPending()) {
                 return;
@@ -343,7 +341,6 @@ export default {
             }
             wx.hideLoading();
         },
-
         async call(e) {
             const { sn, idx, type: roomtype } = e;
             const target = this.contactList[idx];
@@ -376,15 +373,89 @@ export default {
                 console.error(`call error`, error);
             }
         },
+
+        connectMQTT(clientId, devId) {
+            const THRESHOLD = 2;
+            const params = {
+                keepalive: 60,
+                clean: true,
+                connectTimeout: 30 * 1000,
+                clientId:
+                    "wx_mqtt_" + Math.random().toString(16).substring(2, 8),
+                username: "admin",
+                password: "public",
+                // 微信小程序特定配置
+                wsOptions: {
+                    WebSocket: function (url) {
+                        return wx.connectSocket({
+                            url: url,
+                            header: {
+                                "content-type": "application/json",
+                            },
+                            protocols: ["mqtt"],
+                        });
+                    },
+                },
+                rejectUnauthorized: false, // 仅开发环境使用,生产环境应设为true或移除
+            };
+            let client = "";
+            let selectedService = uni.getStorageSync("sercviceChoice");
+            if (!selectedService || selectedService == "aloneServe") {
+                client = mqtt.connect("wxs://radar-power.cn:8084/mqtt", params);
+            }
+            // 存储client引用以便后续操作
+            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}`);
+                        }
+                    }
+                );
+            });
+            client.on("disconnect", () => {
+                console.log("MQTT不在连接");
+            });
+            client.on("error", (err) => {
+                setTimeout(() => {
+                    this.connectMQTT(clientId, devId);
+                }, 5000);
+            });
+
+            client.on("reconnect", () => {});
+
+            client.on("close", () => {});
+
+            client.on("message", (topic, message) => {
+                // clearTimeout(this.inactivityTimer);
+                // this.inactivityTimer = setTimeout(() => {
+                //     this.targetPoints = {};
+                // }, 1500);
+                // if (!match) return;
+                const data = JSON.parse(message.toString());
+                console.log("接收到消息:", topic, data);
+            });
+        },
     },
     onLoad(options) {
         if (!isWmpf) {
             this.getVoipDevices();
         }
+        this.connectMQTT();
+    },
+    onUnload() {
+        if (this.mqttClient) this.mqttClient.end(true);
+        clearInterval(this.autoPlayinterval);
+        clearInterval(this.inactivityTimer);
+    },
+    onHide() {
+        if (this.mqttClient) this.mqttClient.end(true);
     },
-    onUnload() {},
-    onHide() {},
-    onShow() {},
     onShareAppMessage() {},
 };
 </script>

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

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

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

@@ -23,7 +23,7 @@
                 </view>
                 <view
                     class="rightItem"
-                    @click="gotoPath('/pagesA/homeManage/homeManage')"
+                    @click="gotoPath('/pagesA/devices/devices')"
                 >
                     <view class="rightTitle">我的家庭</view>
                     <view class="rightContent"
@@ -82,7 +82,6 @@
             <button open-type="contact">联系客服</button>
         </view>
         <view class="bot_version"> v3.0.1 </view>
-
         <!-- <view class="headerInfo">111111</view> -->
 
         <alarmCom></alarmCom>

+ 1 - 1
src/pagesA/adDevice/adDevice.vue

@@ -381,7 +381,7 @@ export default {
                 return;
             }
 
-            if (200 > this.height || this.height > 270) {
+            if (200 > this.height || this.height > 370) {
                 uni.showModal({
                     content: "安装高度在200~270之间",
                     showCancel: false,

+ 10 - 2
src/pagesA/roomSetting/roomSetting.vue

@@ -621,13 +621,21 @@ export default {
                 )
                 .then((res) => {
                     if (res.data.code == 200) {
-                        uni.reLaunch({
-                            url: "/pages/home/home",
+                        uni.showToast({
+                            title: "保存成功",
+                            icon: "none",
+                            duration: 1500,
                         });
+                        setTimeout(() => {
+                            uni.reLaunch({
+                                url: "/pages/home/home",
+                            });
+                        }, 1500);
                     } else {
                         uni.showToast({
                             title: res.data.msg,
                             icon: "none",
+                            duration: 1500,
                         });
                     }
                 })