优化蓝牙订阅在首页的弹窗
This commit is contained in:
@ -58,6 +58,12 @@
|
||||
{{getbleStatu}}
|
||||
</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="itemInfo.deviceMac" @click="bleStatuToggle">
|
||||
<text class="info-label">充电状态</text>
|
||||
<text class="info-value status-running" >
|
||||
{{deviceInfo.chargeState != 0?'充电中':'未充电'}}
|
||||
</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label" style="display: flex; align-items: center;">定位信息</text>
|
||||
<view class="info-value status-running" @click="gpsPosition(deviceInfo)">
|
||||
@ -73,7 +79,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="callpolice" v-if="deviceInfo.onlineStatus == 1 && deviceInfo.alarmStatus == 1">
|
||||
<view class="callpolice" v-if="deviceInfo.alarmStatus == 1">
|
||||
<view class="">设备强制报警中</view>
|
||||
<view>
|
||||
<uni-icons type="closeempty" size="15" color="rgba(255, 255, 255, 0.9)"
|
||||
@ -436,6 +442,52 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onReceive(deviceState){//蓝牙/Mq通用消息处理
|
||||
switch (deviceState[0]) {
|
||||
// 1设备切换灯光实时返回
|
||||
case 1:
|
||||
this.currentMainMode = this.getMainLightModeLabel(
|
||||
deviceState[
|
||||
1]);
|
||||
this.sliderValue = deviceState[2];
|
||||
this.deviceInfo.batteryRemainingTime = deviceState[3];
|
||||
break;
|
||||
// 12为设备实时上报
|
||||
case 12:
|
||||
this.currentMainMode = this.getMainLightModeLabel(
|
||||
deviceState[
|
||||
1]);
|
||||
this.isLaserOn = deviceState[2] === 1; //第3位表示当时激光灯档位
|
||||
this.currentlaserMode = this.isLaserOn ? "开启" : "关闭";
|
||||
if (this.deviceInfo) {
|
||||
this.deviceInfo.batteryPercentage = deviceState[3]; //第4位电量百分比
|
||||
this.deviceInfo.chargeState = deviceState[4]; //第5位为充电状态(0没有充电,1正在充电,2为已充满)
|
||||
this.deviceInfo.batteryRemainingTime = deviceState[5]; //第6位200代表电池剩余续航时间200分钟
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (this.deviceInfo.batteryPercentage < 20 &&
|
||||
this.deviceInfo.chargeState == 0) {
|
||||
this.popupType = 'bettery';
|
||||
this.popupMessage = '请及时充电';
|
||||
this.showPopupFlag = true;
|
||||
}
|
||||
if (this.apiType === 'listA') {
|
||||
this.fetchDeviceDetail(data.data.id)
|
||||
} else {
|
||||
// 分享权限详情
|
||||
this.fetchSharedDeviceDetail(data.data.id)
|
||||
}
|
||||
}, 10000);
|
||||
// 上报电量,在列表里面同步
|
||||
uni.$emit('deviceStatusUpdate', {
|
||||
message: parsedMessage,
|
||||
timestamp: new Date().getTime()
|
||||
});
|
||||
break;
|
||||
default:
|
||||
console.log('未知的 deviceState 类型:', deviceState[0]);
|
||||
}
|
||||
},
|
||||
bleStatuToggle() {
|
||||
let f = this.getDevice();
|
||||
if (!f) {
|
||||
@ -532,11 +584,9 @@
|
||||
}
|
||||
let data = rec.ReceiveData(receive, device, pagePath, recArr);
|
||||
console.log("蓝牙收到消息", data)
|
||||
this.receivData(data);
|
||||
},
|
||||
receivData(data) {
|
||||
|
||||
this.onReceive(data.state);
|
||||
},
|
||||
|
||||
bleStateBreak() {
|
||||
if (this.Status.pageHide) {
|
||||
return;
|
||||
@ -1566,6 +1616,7 @@
|
||||
// this.popupConfirmText="";
|
||||
},
|
||||
OpenWarn(val){//开启/解除强制报警
|
||||
debugger;
|
||||
const topic = `B/${this.itemInfo.deviceImei}`;
|
||||
let message={"instruct":[7,val,0,0,0,0]};
|
||||
message=JSON.stringify(message);
|
||||
@ -1575,6 +1626,8 @@
|
||||
});
|
||||
if(flag){
|
||||
this.itemInfo.alarmStatus=val;
|
||||
}else{
|
||||
MsgError("操作没有成功",'确定',this);
|
||||
}
|
||||
|
||||
this.showPopupFlag = false;
|
||||
@ -1644,11 +1697,11 @@
|
||||
// 3.解除告警状态
|
||||
const registerRes = await deviceSendAlarmMessage(data);
|
||||
if (registerRes.code !== 200) {
|
||||
uni.showToast({
|
||||
title: registerRes.msg,
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
// uni.showToast({
|
||||
// title: registerRes.msg,
|
||||
// icon: 'none'
|
||||
// })
|
||||
this.OpenWarn(0);
|
||||
return
|
||||
}
|
||||
this.itemInfo.alarmStatus=0;
|
||||
@ -1908,53 +1961,8 @@
|
||||
const deviceState = parsedMessage.state; // 直接取 state 数组
|
||||
// 切换主灯光模式,亮度值设备同步
|
||||
if (!deviceState) return;
|
||||
// 1设备切换灯光实时返回
|
||||
switch (deviceState[0]) {
|
||||
case 1:
|
||||
this.currentMainMode = this.getMainLightModeLabel(
|
||||
deviceState[
|
||||
1]);
|
||||
this.sliderValue = deviceState[2];
|
||||
this.deviceInfo.batteryRemainingTime = deviceState[3];
|
||||
break;
|
||||
// 12为设备实时上报
|
||||
case 12:
|
||||
this.currentMainMode = this.getMainLightModeLabel(
|
||||
deviceState[
|
||||
1]);
|
||||
this.isLaserOn = deviceState[2] === 1; //第3位表示当时激光灯档位
|
||||
this.currentlaserMode = this.isLaserOn ? "开启" : "关闭";
|
||||
if (this.deviceInfo) {
|
||||
this.deviceInfo.batteryPercentage = deviceState[
|
||||
3]; //第4位电量百分比
|
||||
this.deviceInfo.chargeState = deviceState[
|
||||
4]; //第5位为充电状态(0没有充电,1正在充电,2为已充满)
|
||||
this.deviceInfo.batteryRemainingTime = deviceState[
|
||||
5]; //第6位200代表电池剩余续航时间200分钟
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (this.deviceInfo.batteryPercentage < 20 &&
|
||||
this.deviceInfo.chargeState == 0) {
|
||||
this.popupType = 'bettery';
|
||||
this.popupMessage = '请及时充电';
|
||||
this.showPopupFlag = true;
|
||||
}
|
||||
if (this.apiType === 'listA') {
|
||||
this.fetchDeviceDetail(data.data.id)
|
||||
} else {
|
||||
// 分享权限详情
|
||||
this.fetchSharedDeviceDetail(data.data.id)
|
||||
}
|
||||
}, 10000);
|
||||
// 上报电量,在列表里面同步
|
||||
uni.$emit('deviceStatusUpdate', {
|
||||
message: parsedMessage,
|
||||
timestamp: new Date().getTime()
|
||||
});
|
||||
break;
|
||||
default:
|
||||
console.log('未知的 deviceState 类型:', deviceState[0]);
|
||||
}
|
||||
|
||||
this.onReceive(deviceState);
|
||||
} catch (error) {
|
||||
console.log('解析MQTT消息失败:', error, '原始消息:', payload);
|
||||
}
|
||||
|
||||
@ -482,20 +482,20 @@
|
||||
|
||||
|
||||
ble.addStateBreakCallback(() => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '蓝牙不可用'
|
||||
});
|
||||
|
||||
|
||||
MsgError('蓝牙不可用','',these);
|
||||
|
||||
these.EquipMents.filter((v, i) => {
|
||||
these.$set(these.EquipMents[i], 'link', false);
|
||||
});
|
||||
}, pagePath);
|
||||
ble.addStateRecoveryCallback(() => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '蓝牙恢复可用'
|
||||
});
|
||||
|
||||
|
||||
MsgSuccess('蓝牙恢复可用','',these,()=>{
|
||||
MsgClear(these);
|
||||
})
|
||||
},
|
||||
pagePath);
|
||||
|
||||
@ -568,7 +568,7 @@
|
||||
|
||||
|
||||
plus.runtime.openURL('weixin://', (err) => {
|
||||
MsgError("打开微信失败,请手动打开微信粘贴");
|
||||
MsgError("打开微信失败,请手动打开微信,发送至'文件传输助手'");
|
||||
});
|
||||
},
|
||||
fail(ex){
|
||||
@ -805,10 +805,8 @@
|
||||
|
||||
let json = getUrlParams(res.result);
|
||||
if (!json.key) {
|
||||
uni.showModal({
|
||||
title: '错误',
|
||||
content: "无效的二维码"
|
||||
})
|
||||
|
||||
MsgError('无效的二维码','',these);
|
||||
return;
|
||||
}
|
||||
this.scanKey = json.key;
|
||||
@ -1050,9 +1048,8 @@
|
||||
these.sendEquipToMq();
|
||||
}).catch(ex => {
|
||||
console.log("ex=", ex)
|
||||
uni.showModal({
|
||||
content: "连接失败:" + ex.msg
|
||||
});
|
||||
|
||||
MsgError("连接失败:" + ex.msg,'',these);
|
||||
hideLoading(these);
|
||||
});
|
||||
}
|
||||
|
||||
@ -134,6 +134,9 @@
|
||||
</view>
|
||||
<!-- 蒙板、用于点击任意位置关闭悬浮的菜单 -->
|
||||
<view class="mask" v-show="showTooltip||showshare" @click.stop="closePopMenu"></view>
|
||||
|
||||
|
||||
<MsgBox ref="msgPop" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -772,7 +775,8 @@
|
||||
this.downCallback();
|
||||
});
|
||||
ble = bleTool.getBleTool();
|
||||
recei = BleReceive.getBleReceive();
|
||||
console.log("this=",this);
|
||||
recei = BleReceive.getBleReceive(this);
|
||||
//蓝牙连接成功的回调
|
||||
ble.addRecoveryCallback((res) => {
|
||||
// console.log("蓝牙连接成功的回调");
|
||||
@ -799,8 +803,9 @@
|
||||
|
||||
//接收到消息的回调
|
||||
ble.addReceiveCallback((receive, device, path, recArr) => {
|
||||
// console.error("首页收到消息了");
|
||||
recei.ReceiveData(receive, device, path, recArr);
|
||||
console.error("首页收到消息了");
|
||||
let json=recei.ReceiveData(receive, device, path, recArr);
|
||||
console.error("消息内容",json);
|
||||
this.updateBleStatu();
|
||||
}, pagePath);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user