matt订阅设备消息
This commit is contained in:
@ -248,9 +248,10 @@
|
||||
@confirm="onPopupConfirm" />
|
||||
<!--============= 电量低于提示弹框=========== -->
|
||||
<CustomPopup v-if="popupType === 'bettery'" :show="showPopupFlag"
|
||||
popupBorder="1rpx solid rgba(224, 52, 52, 0.3)" :message="popupMessage"
|
||||
icon="/static/images/common/path.png" :confirm-text="popupConfirmText" :show-cancel="true"
|
||||
@confirm="onPopupConfirm" confirmBtnBg="rgba(224, 52, 52, 1)" confirmBtnColor="#fff" />
|
||||
popupBorder="1rpx solid rgba(224, 52, 52, 0.3)" :message="popupMessage" title="设备电量低于20%"
|
||||
titleColor="rgba(224, 52, 52, 1)" icon="/static/images/common/path.png" :confirm-text="popupConfirmText"
|
||||
:show-cancel="true" @cancel="onPopupConfirm" @confirm="onPopupConfirm"
|
||||
confirmBtnBg="rgba(224, 52, 52, 1)" confirmBtnColor="#fff" />
|
||||
<!-- 解除报警 -->
|
||||
<CustomPopup v-if="popupType === 'cancel'" :show="showPopupFlag"
|
||||
popupBorder="1rpx solid rgba(224, 52, 52, 0.3)" :message="popupMessage"
|
||||
@ -310,7 +311,9 @@
|
||||
position: '',
|
||||
code: '',
|
||||
},
|
||||
deviceInfo: {},
|
||||
deviceInfo: {
|
||||
|
||||
},
|
||||
|
||||
activePermissions: [], // 存储当前设备的权限数组
|
||||
isSharedDevice: false, // 标记是否来自分享
|
||||
@ -882,15 +885,26 @@
|
||||
this.mqttClient.subscribe(statusTopic, (payload) => {
|
||||
console.log(`收到来自 ${statusTopic} 的消息:`, payload);
|
||||
//收到电量上报。延迟20s请求接口数据
|
||||
setTimeout(() => {
|
||||
this.fetchDeviceDetail(data.data.id)
|
||||
}, 20000);
|
||||
|
||||
const parsedMessage = typeof payload === 'string' ? JSON.parse(payload) : payload;
|
||||
const deviceState = parsedMessage.state; // 直接取 state 数组
|
||||
// ✅ 发送全局事件通知主页面更新
|
||||
uni.$emit('deviceStatusUpdate', {
|
||||
message: JSON.stringify(payload), // 消息内容
|
||||
message: parsedMessage, // 消息内容
|
||||
timestamp: new Date().getTime() // 时间戳
|
||||
});
|
||||
if (deviceState[0] === 12) {
|
||||
setTimeout(() => {
|
||||
this.fetchDeviceDetail(data.data.id);
|
||||
}, 20000);
|
||||
|
||||
// 这里判断电量低于20%,弹框提示
|
||||
if (this.deviceInfo.batteryPercentage < 20) {
|
||||
this.popupType = 'bettery'
|
||||
this.popupMessage = '请及时充电';
|
||||
this.showPopupFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
if (this.apiType === 'listA') {
|
||||
|
Reference in New Issue
Block a user