matt订阅设备消息
This commit is contained in:
@ -18,7 +18,8 @@
|
||||
<image src="/static/images/common/more.png" mode="aspectFit" class="more"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="sendFlex" v-if="activeTab && activeTab.id !== ''&& activeTabInfo.communicationMode==0 && activeTabInfo.typeName=='BJQ6170'">
|
||||
<view class="sendFlex"
|
||||
v-if="activeTab && activeTab.id !== ''&& activeTabInfo.communicationMode==0 && activeTabInfo.typeName=='BJQ6170'">
|
||||
<view class="callpolice" @click="callpolice">报警</view>
|
||||
<view class="Sendmessage" @click="location">位置</view>
|
||||
<view class="Sendmessage" @click="handleSend">发送信息</view>
|
||||
@ -29,7 +30,8 @@
|
||||
<uni-swipe-action ref="swipeAction">
|
||||
<block v-for="(item, index) in deviceList" :key="index" :ref="'swipeItem_' + index">
|
||||
<uni-swipe-action-item :right-options="Options"
|
||||
@click="handleSwipeClick($event, item, index)" class="device-card" :style="{ border: item.communicationMode==0 && item.onlineStatus==1 ? '1px solid rgba(224, 52, 52, 1)' : 'none' }">
|
||||
@click="handleSwipeClick($event, item, index)" class="device-card"
|
||||
:style="{ border: item.communicationMode==0 && item.onlineStatus==1 ? '1px solid rgba(224, 52, 52, 1)' : 'none' }">
|
||||
<view @click.stop="handleFile(item)">
|
||||
<view class="device-header">
|
||||
<view class="deviceIMG">
|
||||
@ -51,7 +53,8 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="device-callpolice" v-if="item.communicationMode==0 && item.onlineStatus==1">报警中</view>
|
||||
<view class="device-callpolice"
|
||||
v-if="item.communicationMode==0 && item.onlineStatus==1">报警中</view>
|
||||
<view v-if="item.communicationMode==1">
|
||||
<view class="device-status online">已连接</view>
|
||||
<view class="device-status unline">未连接</view>
|
||||
@ -254,7 +257,6 @@
|
||||
},
|
||||
// tab切换页
|
||||
switchTab(tab, index) {
|
||||
console.log(tab,'tab');
|
||||
this.deviceList = [];
|
||||
this.activeTab = index;
|
||||
this.activeTabInfo = tab
|
||||
@ -298,7 +300,7 @@
|
||||
onScrollToLower() {
|
||||
this.getData();
|
||||
},
|
||||
// 添加扫一三图标
|
||||
// 添加扫一扫图标
|
||||
scan() {
|
||||
this.showTooltip = !this.showTooltip;
|
||||
},
|
||||
@ -320,7 +322,6 @@
|
||||
},
|
||||
// 右滑点击事件处理
|
||||
handleSwipeClick(e, item, index) {
|
||||
|
||||
const {
|
||||
content
|
||||
} = e
|
||||
@ -405,7 +406,7 @@
|
||||
})
|
||||
},
|
||||
// 报警
|
||||
callpolice(){
|
||||
callpolice() {
|
||||
const currentTab = this.tabs[this.activeTab];
|
||||
const deviceType = currentTab.id || '';
|
||||
console.log(`跳转到发送信息页面\n当前设备类型: ${deviceType}\n设备类型名称: ${currentTab.typeName}`);
|
||||
@ -445,7 +446,6 @@
|
||||
})
|
||||
},
|
||||
handleFile(item) {
|
||||
console.log('item', item);
|
||||
// communicationMode 0是4G 1是蓝牙,考虑多个4g设备
|
||||
if (item.typeName == 'BJQ6170') {
|
||||
uni.navigateTo({
|
||||
@ -473,7 +473,7 @@
|
||||
// 页面跳转成功后的回调函数
|
||||
res.eventChannel.emit('deviceControl', {
|
||||
data: item,
|
||||
deviceType:deviceType
|
||||
deviceType: deviceType
|
||||
});
|
||||
}
|
||||
})
|
||||
@ -500,17 +500,25 @@
|
||||
updateDeviceStatus(data) {
|
||||
// 只更新 communicationMode == 0 的设备
|
||||
this.deviceList = this.deviceList.map(item => {
|
||||
console.log(item, 'item2222');
|
||||
if (item.communicationMode === 0) {
|
||||
// 这里根据消息内容更新设备状态
|
||||
// 示例:如果消息包含特定字段,则更新设备状态
|
||||
console.log(item,'item444');
|
||||
if (item.communicationMode == 0) {
|
||||
console.log(item, 'item2222');
|
||||
let messageData;
|
||||
try {
|
||||
messageData = data.message; // 双重解析(如果消息被转义)
|
||||
} catch (e) {
|
||||
return item; // 解析失败则不更新
|
||||
}
|
||||
const [deviceId, onlineStatus, batteryPercentage] = messageData.state || [];
|
||||
// 只更新电量 & 在线状态(避免覆盖其他字段)
|
||||
return {
|
||||
...item,
|
||||
status: data.message.status || item.status, // 假设消息中有status字段
|
||||
batteryPercentage: batteryPercentage ?? item.batteryPercentage, // 如果新电量有效则更新,否则保留旧值
|
||||
onlineStatus: onlineStatus ?? item.onlineStatus, // 如果新状态有效则更新,否则保留旧值
|
||||
lastUpdate: data.timestamp // 更新时间戳
|
||||
};
|
||||
return item;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
},
|
||||
@ -616,6 +624,7 @@
|
||||
width: 40rpx;
|
||||
height: 8rpx;
|
||||
}
|
||||
|
||||
.Sendmessage {
|
||||
margin-left: 50rpx;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
@ -662,19 +671,21 @@
|
||||
position: relative;
|
||||
|
||||
}
|
||||
.device-callpolice{
|
||||
width: 122rpx;
|
||||
height: 52rpx;
|
||||
font-size: 24rpx;
|
||||
border-radius: 0px 8px 0px 8px;
|
||||
background-color: rgba(224, 52, 52, 1);
|
||||
position: absolute;
|
||||
top: 0rpx;
|
||||
right: -4rpx;
|
||||
text-align: center;
|
||||
line-height: 52rpx;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.device-callpolice {
|
||||
width: 122rpx;
|
||||
height: 52rpx;
|
||||
font-size: 24rpx;
|
||||
border-radius: 0px 8px 0px 8px;
|
||||
background-color: rgba(224, 52, 52, 1);
|
||||
position: absolute;
|
||||
top: 0rpx;
|
||||
right: -4rpx;
|
||||
text-align: center;
|
||||
line-height: 52rpx;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.device-status {
|
||||
width: 122rpx;
|
||||
height: 52rpx;
|
||||
@ -747,9 +758,11 @@
|
||||
top: 20rpx;
|
||||
left: -20rpx
|
||||
}
|
||||
.offlines{
|
||||
|
||||
.offlines {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.offlines::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
|
Reference in New Issue
Block a user