From fd7f186cccb67cfe10707167c0948423192ae26a Mon Sep 17 00:00:00 2001 From: kerwincui <164770707@qq.com> Date: Fri, 29 Jul 2022 18:34:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81=E3=80=81?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E3=80=81=E5=B1=9E=E6=80=A7=E3=80=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=9E=E6=97=B6=E8=AE=A2=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vue/src/views/index.vue | 2 - vue/src/views/iot/device/index.vue | 71 ++++++++++++++++++- vue/src/views/iot/device/running-status.vue | 77 +++++++++++++++++++-- 3 files changed, 140 insertions(+), 10 deletions(-) diff --git a/vue/src/views/index.vue b/vue/src/views/index.vue index 92b1b739..f3e3ee98 100644 --- a/vue/src/views/index.vue +++ b/vue/src/views/index.vue @@ -250,7 +250,6 @@ -
@@ -262,7 +261,6 @@
- diff --git a/vue/src/views/iot/device/index.vue b/vue/src/views/iot/device/index.vue index 9d3183e8..0304a623 100644 --- a/vue/src/views/iot/device/index.vue +++ b/vue/src/views/iot/device/index.vue @@ -405,14 +405,18 @@ export default { if (this.deviceList[i].serialNumber == deviceNum) { this.deviceList[i].status = data.message.status; this.deviceList[i].isShadow = data.message.isShadow; + this.deviceList[i].rssi = data.message.rssi; + return; } } // 更新实时监测模型的状态 if (this.monitorDevice.serialNumber == deviceNum) { this.monitorDevice.status = data.message.status; this.monitorDevice.isShadow = data.message.isShadow; + this.monitorDevice.rssi = data.message.rssi; } - } else if (topics[3] == "monitor") { + } + if (topics[3] == "monitor") { // 实时监测 this.chartLoading = false; for (let k = 0; k < data.message.length; k++) { @@ -432,21 +436,84 @@ export default { data: this.dataList[i].data }] }); + return; } } } } + if (topics[3] == 'property' || topics[3] == 'function') { + // 更新列表中设备的属性 + for (let i = 0; i < this.deviceList.length; i++) { + if (this.deviceList[i].serialNumber == deviceNum) { + for (let j = 0; j < data.message.length; j++) { + let isComplete = false; + // 布尔类型 + for (let k = 0; k < this.deviceList[i].boolList.length && !isComplete; k++) { + if (this.deviceList[i].boolList[k].id == data.message[j].id) { + this.deviceList[i].boolList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 枚举类型 + for (let k = 0; k < this.deviceList[i].enumList.length && !isComplete; k++) { + if (this.deviceList[i].enumList[k].id == data.message[j].id) { + this.deviceList[i].enumList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 字符串类型 + for (let k = 0; k < this.deviceList[i].stringList.length && !isComplete; k++) { + if (this.deviceList[i].stringList[k].id == data.message[j].id) { + this.deviceList[i].stringList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 数组类型 + for (let k = 0; k < this.deviceList[i].arrayList.length && !isComplete; k++) { + if (this.deviceList[i].arrayList[k].id == data.message[j].id) { + this.deviceList[i].arrayList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 整数类型 + for (let k = 0; k < this.deviceList[i].integerList.length && !isComplete; k++) { + if (this.deviceList[i].integerList[k].id == data.message[j].id) { + this.deviceList[i].integerList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 小数类型 + for (let k = 0; k < this.deviceList[i].decimalList.length && !isComplete; k++) { + if (this.deviceList[i].decimalList[k].id == data.message[j].id) { + this.deviceList[i].decimalList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + } + return; + } + } + } }, /** Mqtt订阅主题 */ mqttSubscribe(list) { // 订阅当前页面设备状态和实时监测 let topics = []; - // 订阅数太多,会导致emqx连接中断或者订阅缓慢 for (let i = 0; i < list.length; i++) { let topicStatus = "/" + list[i].productId + "/" + list[i].serialNumber + "/status/post"; let topicMonitor = "/" + list[i].productId + "/" + list[i].serialNumber + "/monitor/post"; + let topicProperty = '/' + list[i].productId + '/' + list[i].serialNumber + '/property/post'; + let topicFunction = '/' + list[i].productId + '/' + list[i].serialNumber + '/function/post'; topics.push(topicStatus); topics.push(topicMonitor); + topics.push(topicProperty); + topics.push(topicFunction); } this.subscribes = topics; }, diff --git a/vue/src/views/iot/device/running-status.vue b/vue/src/views/iot/device/running-status.vue index 95e7005a..44d03c26 100644 --- a/vue/src/views/iot/device/running-status.vue +++ b/vue/src/views/iot/device/running-status.vue @@ -128,7 +128,7 @@ {{item.name}} - {{item.value}} {{item.unit?item.unit:""}} + {{item.value}} {{item.unit?item.unit:""}} @@ -146,7 +146,7 @@ {{item.name}} - {{item.value}} {{item.unit?item.unit:""}} + {{item.value}} {{item.unit?item.unit:""}} @@ -170,7 +170,7 @@
已经是最新版本,不需要升级
{{firmware.firmwareName}} {{firmware.productName}} @@ -344,14 +344,79 @@ export default { // 更新列表中设备的状态 this.deviceInfo.status = data.message.status; this.deviceInfo.isShadow = data.message.isShadow; + this.deviceInfo.rssi = data.message.rssi; this.updateDeviceStatus(this.deviceInfo); + return; + } + if (topics[3] == 'property' || topics[3] == 'function') { + // 更新列表中设备的属性 + if (this.deviceInfo.serialNumber == deviceNum) { + for (let j = 0; j < data.message.length; j++) { + let isComplete = false; + // 布尔类型 + for (let k = 0; k < this.deviceInfo.boolList.length && !isComplete; k++) { + if (this.deviceInfo.boolList[k].id == data.message[j].id) { + this.deviceInfo.boolList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 枚举类型 + for (let k = 0; k < this.deviceInfo.enumList.length && !isComplete; k++) { + if (this.deviceInfo.enumList[k].id == data.message[j].id) { + this.deviceInfo.enumList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 字符串类型 + for (let k = 0; k < this.deviceInfo.stringList.length && !isComplete; k++) { + if (this.deviceInfo.stringList[k].id == data.message[j].id) { + this.deviceInfo.stringList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 数组类型 + for (let k = 0; k < this.deviceInfo.arrayList.length && !isComplete; k++) { + if (this.deviceInfo.arrayList[k].id == data.message[j].id) { + this.deviceInfo.arrayList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 整数类型 + for (let k = 0; k < this.deviceInfo.integerList.length && !isComplete; k++) { + if (this.deviceInfo.integerList[k].id == data.message[j].id) { + this.deviceInfo.integerList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + // 小数类型 + for (let k = 0; k < this.deviceInfo.decimalList.length && !isComplete; k++) { + if (this.deviceInfo.decimalList[k].id == data.message[j].id) { + this.deviceInfo.decimalList[k].shadow = data.message[j].value; + isComplete = true; + break; + } + } + } + return; + } } }, /** Mqtt订阅主题 */ mqttSubscribe(device) { - // 订阅当前设备状态 - let topic = "/" + device.productId + "/" + device.serialNumber + "/status/post"; - this.subscribes = [topic]; + // 订阅当前设备状态和无模型 + let topicStatus = '/' + device.productId + '/' + device.serialNumber + '/status/post'; + let topicProperty = '/' + device.productId + '/' + device.serialNumber + '/property/post'; + let topicFunction = '/' + device.productId + '/' + device.serialNumber + '/function/post'; + let topics = []; + topics.push(topicStatus); + topics.push(topicProperty); + topics.push(topicFunction); + this.subscribes = topics; }, /** 更新设备状态 */ updateDeviceStatus(device) {