From 0a9ec18bc0b721592afc80dbc95dc4ef58feb7fc Mon Sep 17 00:00:00 2001 From: Iruka <1017819588@qq.com> Date: Fri, 27 Sep 2024 18:48:24 +0800 Subject: [PATCH] . --- App.vue | 73 ++++--------- pages/index.vue | 254 ++++++++++++++++++++++------------------------ utils/mqttUtil.js | 248 +++++++++++++++++++++++++++++++++----------- 3 files changed, 333 insertions(+), 242 deletions(-) diff --git a/App.vue b/App.vue index 8190690..3012b6a 100644 --- a/App.vue +++ b/App.vue @@ -7,11 +7,8 @@ data() { return { indexData: new indexUtil(this.indexDataHandler), //全局地块列表管理 - dc: new dc(), - mqtt: new mqttUtil(), - mqttObj: { - topics: [] - }, + dc: new dc(), // 设备控制类 + mqtt: new mqttUtil(this.mqttMsgHandler), //Mqtt } }, globalData: {}, @@ -22,8 +19,8 @@ // #endif // 监听mqtt连接命令 - uni.$on("mqtt-link", () => { - this.mqttLink(); + uni.$on("mqtt-link", (userId) => { + this.mqttLink(userId); }); // 监听mqtt连接订阅命令 uni.$on("mqtt-subscribes", topics => { @@ -56,56 +53,26 @@ this.dc.setValves(this.indexData.selectItem.id, this.indexData.device.waterOutlets); } uni.hideLoading(); - // console.error("indexDataHandler_2:", { - // indexData: this.indexData, - // dc: this.dc, - // }) + console.error("indexDataHandler_2:", { + indexData: this.indexData, + dc: this.dc, + }) }, - setTime: function() { - console.error(this.globalData.num); - // setTimeout(() => { - // this.globalData.num++ - // console.error(this.globalData.num); - // this.setTime(); - // }, 1000) - }, - mqttLink() { - // 处理 wx.connectSocket promisify 兼容问题,强制返回 SocketTask - uni.connectSocket = (function(connectSocket) { - return function(options) { - console.log(options) - options.success = options.success || function() {} - return connectSocket.call(this, options) - } - })(uni.connectSocket) - + //Mqtt连接 + mqttLink(userId) { console.error("mqttLink"); - // #ifdef H5 - this.mqtt.link(); - this.mqtt.client.on("connect", error => { - console.log("连接成功") - console.error("client:", this.mqtt.client); - }) - this.mqtt.client.on("error", error => { - console.log("连接异常") - }) - this.mqtt.client.on("reconnect", error => { - console.log("重新连接") - }) - this.mqtt.client.on("message", (topic, message) => { - console.log("接受消息") - console.log("message:", message.toString()) - this.mqttSendMsg(message); - }) - // #endif - + this.mqtt.link(userId); }, - mqttSubscribes(topics) { - this.mqttObj.topics = topics; - console.error("mqttSubscribes:", topics); + //Mqtt断开连接 + mqttEnd() { + this.mqtt.over(); }, - mqttSendMsg(msg) { - uni.$emit("mqtt-msg", msg); + //Mqtt消息回调 + mqttMsgHandler(topic, data) { + console.error("mqttMsgHandler:", { + topic: topic, + data: data, + }); }, } } diff --git a/pages/index.vue b/pages/index.vue index db0dc5f..449aa5e 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -97,7 +97,9 @@ 基站 - + + @@ -166,15 +168,16 @@ - ● - {{ item.rowKey }} + ● + {{ item.rowKey }} - 60 - - + {{ item.device.custom.battery.value }} + @@ -188,7 +191,11 @@ - ●{{ item2.rowKey }} + + ● + {{ item2.rowKey }} + @@ -212,15 +219,23 @@ + - + ① - (999) - + (999) + + {{ item2.device.custom.ct.endS > 0 ? `(${item2.device.custom.ct.endS})` : "超时" }} + + + - + 全开 + {{ item2.device.custom.p1 }} 离线 + v-show="!item2.device.custom.online"> + {{ item2.device.custom.showMask.text }} + {{ item2.device.custom.p2 }} - + 全关 + (超时) + + - - ④ - (超时) - + + ② + (超时) + + + - + ① - 0.00 - + (超时) + + - - + ② + (超时) + + @@ -286,7 +322,9 @@ {{ item2.device.custom.p[0] }} {{ item2.device.custom.p[1] }} 离线 + v-show="!item2.device.custom.online"> + {{ item2.device.custom.showMask.text }} + {{ item2.device.custom.p[2] }} {{ item2.device.custom.p[3] }} @@ -295,24 +333,32 @@ - + ④ + (超时) + + - + ③ - 0.00 - + (超时) + + - - 角度4故障 + + + {{item2.device.custom.showMask.text}} + @@ -320,84 +366,7 @@ {{ item2.rowKey }} - - - - - ●1-2 - - - - - 60 - - - - - 26.2 - - - - - - - - - - - - - - - - ① - 0.00 - - - - - - - - - - 全开 - - - - - -99.63 - -99.63 - 离线 - -99.63 - -99.63 - - - - - - 全关 - - - - - - - - ④ - 0.00 - - - - - - - - @@ -412,6 +381,14 @@ + mqttLink + mqttEnd + 获取信息 + + connected:{{mqtt.connected}} + +
connected:{{mqtt.connected}}