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 @@ + + + + +

connected:{{mqtt.connected}}

+ +