From 66ab7927be3e3e0c78e1bbaf42b657c4944826f7 Mon Sep 17 00:00:00 2001 From: h7ml Date: Tue, 21 Jun 2022 23:43:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(other):=20=E4=BF=AE=E5=A4=8D=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=88=97=E8=A1=A8=E5=8F=82=E6=95=B0=E4=B8=8D=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/DeviceCloud/manage/devicelist.vue | 21 ++++++++++++--------- src/views/DeviceCloud/manage/home_index.vue | 21 ++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/views/DeviceCloud/manage/devicelist.vue b/src/views/DeviceCloud/manage/devicelist.vue index 64e34209d5..c581d4b61b 100644 --- a/src/views/DeviceCloud/manage/devicelist.vue +++ b/src/views/DeviceCloud/manage/devicelist.vue @@ -263,6 +263,7 @@ { - console.log('收到消息', Msg) + let _this = this + await _this.$subscribe('$dg/user/devicestate/#') + _this.$dgiotBus.$off(_this.$mqttInfo.topicKey) + _this.$dgiotBus.$on(_this.$mqttInfo.topicKey, (Msg) => { const parseString = JSON.parse(Msg.payloadString) console.log('收到消息', parseString) if (parseString) { const topicsKeys = Object.keys(parseString) - console.log(topicsKeys) - topicsKeys.forEach((t) => { - this.list.forEach((i) => { - if (i.objectId == t) { - const mergeInfo = _.merge(i, parseString[t]) - console.log(`更新设备${i.name}`, mergeInfo) + _this.list.forEach((t) => { + topicsKeys.forEach((j) => { + if (t.objectId == j) { + const mergeInfo = _.merge(t, parseString[j]) + console.log(`更新设备${t.name}`, mergeInfo, parseString[j]) + _this.upkey = moment(new Date()).valueOf() + '' } }) }) diff --git a/src/views/DeviceCloud/manage/home_index.vue b/src/views/DeviceCloud/manage/home_index.vue index 0d2d9e96fc..e27662153a 100644 --- a/src/views/DeviceCloud/manage/home_index.vue +++ b/src/views/DeviceCloud/manage/home_index.vue @@ -348,6 +348,7 @@ { - console.log('收到消息', Msg) + let _this = this + await _this.$subscribe('$dg/user/devicestate/#') + _this.$dgiotBus.$off(_this.$mqttInfo.topicKey) + _this.$dgiotBus.$on(_this.$mqttInfo.topicKey, (Msg) => { const parseString = JSON.parse(Msg.payloadString) console.log('收到消息', parseString) if (parseString) { const topicsKeys = Object.keys(parseString) - console.log(topicsKeys) - topicsKeys.forEach((t) => { - this.list.forEach((i) => { - if (i.objectId == t) { - const mergeInfo = _.merge(i, parseString[t]) - console.log(`更新设备${i.name}`, mergeInfo) + _this.list.forEach((t) => { + topicsKeys.forEach((j) => { + if (t.objectId == j) { + const mergeInfo = _.merge(t, parseString[j]) + console.log(`更新设备${t.name}`, mergeInfo, parseString[j]) + _this.upkey = moment(new Date()).valueOf() + '' } }) })