mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 16:36:03 +08:00
设备状态、信号、属性、功能实时订阅
This commit is contained in:
@@ -250,7 +250,6 @@
|
|||||||
</table>
|
</table>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6" style="padding:20px;">
|
<el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6" style="padding:20px;">
|
||||||
<div style="padding:20px;">
|
<div style="padding:20px;">
|
||||||
@@ -262,7 +261,6 @@
|
|||||||
<div style="padding:20px;">
|
<div style="padding:20px;">
|
||||||
<div ref="pieDisk" style="height:161px;margin-bottom:-20px;"></div>
|
<div ref="pieDisk" style="height:161px;margin-bottom:-20px;"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</el-col>
|
</el-col>
|
||||||
|
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|||||||
@@ -405,14 +405,18 @@ export default {
|
|||||||
if (this.deviceList[i].serialNumber == deviceNum) {
|
if (this.deviceList[i].serialNumber == deviceNum) {
|
||||||
this.deviceList[i].status = data.message.status;
|
this.deviceList[i].status = data.message.status;
|
||||||
this.deviceList[i].isShadow = data.message.isShadow;
|
this.deviceList[i].isShadow = data.message.isShadow;
|
||||||
|
this.deviceList[i].rssi = data.message.rssi;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 更新实时监测模型的状态
|
// 更新实时监测模型的状态
|
||||||
if (this.monitorDevice.serialNumber == deviceNum) {
|
if (this.monitorDevice.serialNumber == deviceNum) {
|
||||||
this.monitorDevice.status = data.message.status;
|
this.monitorDevice.status = data.message.status;
|
||||||
this.monitorDevice.isShadow = data.message.isShadow;
|
this.monitorDevice.isShadow = data.message.isShadow;
|
||||||
|
this.monitorDevice.rssi = data.message.rssi;
|
||||||
}
|
}
|
||||||
} else if (topics[3] == "monitor") {
|
}
|
||||||
|
if (topics[3] == "monitor") {
|
||||||
// 实时监测
|
// 实时监测
|
||||||
this.chartLoading = false;
|
this.chartLoading = false;
|
||||||
for (let k = 0; k < data.message.length; k++) {
|
for (let k = 0; k < data.message.length; k++) {
|
||||||
@@ -432,21 +436,84 @@ export default {
|
|||||||
data: this.dataList[i].data
|
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订阅主题 */
|
/** Mqtt订阅主题 */
|
||||||
mqttSubscribe(list) {
|
mqttSubscribe(list) {
|
||||||
// 订阅当前页面设备状态和实时监测
|
// 订阅当前页面设备状态和实时监测
|
||||||
let topics = [];
|
let topics = [];
|
||||||
// 订阅数太多,会导致emqx连接中断或者订阅缓慢
|
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
let topicStatus = "/" + list[i].productId + "/" + list[i].serialNumber + "/status/post";
|
let topicStatus = "/" + list[i].productId + "/" + list[i].serialNumber + "/status/post";
|
||||||
let topicMonitor = "/" + list[i].productId + "/" + list[i].serialNumber + "/monitor/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(topicStatus);
|
||||||
topics.push(topicMonitor);
|
topics.push(topicMonitor);
|
||||||
|
topics.push(topicProperty);
|
||||||
|
topics.push(topicFunction);
|
||||||
}
|
}
|
||||||
this.subscribes = topics;
|
this.subscribes = topics;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -128,7 +128,7 @@
|
|||||||
<i class="el-icon-tickets"></i>
|
<i class="el-icon-tickets"></i>
|
||||||
{{item.name}}
|
{{item.name}}
|
||||||
</template>
|
</template>
|
||||||
{{item.value}} {{item.unit?item.unit:""}}
|
{{item.value}} {{item.unit?item.unit:""}}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
|
|
||||||
<!-- decimal类型-->
|
<!-- decimal类型-->
|
||||||
@@ -146,7 +146,7 @@
|
|||||||
<i class="el-icon-paperclip"></i>
|
<i class="el-icon-paperclip"></i>
|
||||||
{{item.name}}
|
{{item.name}}
|
||||||
</template>
|
</template>
|
||||||
{{item.value}} {{item.unit?item.unit:""}}
|
{{item.value}} {{item.unit?item.unit:""}}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@
|
|||||||
<div v-if="firmware==null || deviceInfo.firmwareVersion>=firmware.version" style="text-align:center;font-size:16px;"><i class="el-icon-success" style="color:#67C23A;"></i> 已经是最新版本,不需要升级</div>
|
<div v-if="firmware==null || deviceInfo.firmwareVersion>=firmware.version" style="text-align:center;font-size:16px;"><i class="el-icon-success" style="color:#67C23A;"></i> 已经是最新版本,不需要升级</div>
|
||||||
<el-descriptions :column="1" border size="large" v-if="firmware!=null && deviceInfo.firmwareVersion<firmware.version" :labelStyle='{"width":"100px","font-weight":"bold"}'>
|
<el-descriptions :column="1" border size="large" v-if="firmware!=null && deviceInfo.firmwareVersion<firmware.version" :labelStyle='{"width":"100px","font-weight":"bold"}'>
|
||||||
<template slot="title">
|
<template slot="title">
|
||||||
<el-link icon="el-icon-success" type="success" :underline="false"> 可以升级到以下版本</el-link>
|
<el-link icon="el-icon-success" type="success" :underline="false"> 可以升级到以下版本</el-link>
|
||||||
</template>
|
</template>
|
||||||
<el-descriptions-item label="固件名称">{{firmware.firmwareName}}</el-descriptions-item>
|
<el-descriptions-item label="固件名称">{{firmware.firmwareName}}</el-descriptions-item>
|
||||||
<el-descriptions-item label="所属产品">{{firmware.productName}}</el-descriptions-item>
|
<el-descriptions-item label="所属产品">{{firmware.productName}}</el-descriptions-item>
|
||||||
@@ -344,14 +344,79 @@ export default {
|
|||||||
// 更新列表中设备的状态
|
// 更新列表中设备的状态
|
||||||
this.deviceInfo.status = data.message.status;
|
this.deviceInfo.status = data.message.status;
|
||||||
this.deviceInfo.isShadow = data.message.isShadow;
|
this.deviceInfo.isShadow = data.message.isShadow;
|
||||||
|
this.deviceInfo.rssi = data.message.rssi;
|
||||||
this.updateDeviceStatus(this.deviceInfo);
|
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订阅主题 */
|
/** Mqtt订阅主题 */
|
||||||
mqttSubscribe(device) {
|
mqttSubscribe(device) {
|
||||||
// 订阅当前设备状态
|
// 订阅当前设备状态和无模型
|
||||||
let topic = "/" + device.productId + "/" + device.serialNumber + "/status/post";
|
let topicStatus = '/' + device.productId + '/' + device.serialNumber + '/status/post';
|
||||||
this.subscribes = [topic];
|
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) {
|
updateDeviceStatus(device) {
|
||||||
|
|||||||
Reference in New Issue
Block a user