1
0
forked from dyf/APP

修复蓝牙连接锁未释放的问题

This commit is contained in:
liub
2026-04-30 11:23:28 +08:00
parent 677586e51c
commit 6d9df4c945
24 changed files with 1225 additions and 759 deletions

View File

@ -56,19 +56,19 @@
{{ deviceInfo.onlineStatus === 0 ? '离线' : deviceInfo.onlineStatus === 2 ? '故障' : '在线' }}
</text>
</view>
<view class="info-row" >
<view class="info-row">
<text class="info-label">蓝牙名称</text>
<text class="info-value status-running" >
<text class="info-value status-running">
{{deviceInfo.bluetoothName}}
</text>
</view>
<view class="info-row" @click="bleStatuToggle">
<view class="info-row" @click="bleStatuToggle">
<text class="info-label">蓝牙状态</text>
<text class="info-value status-running" :class="getbleStatu.cls">
{{getbleStatu.txt}}
</text>
</view>
<view class="info-row" @click="bleStatuToggle">
<view class="info-row" @click="bleStatuToggle">
<text class="info-label">充电状态</text>
<text class="info-value status-running">
{{deviceInfo.chargeState != 0?'充电中':'未充电'}}
@ -356,6 +356,7 @@
var rec = null;
var pagePath = "/pages/6170/deviceControl/index";
import api from '@/api/670/HBY670.js';
export default {
components: {
@ -443,28 +444,31 @@
return this.modeType === 'main' ? '灯光模式' : '激光模式';
},
getbleStatu() {
let txt="未连接"
let cls="";
let txt = "未连接"
let cls = "";
if (this.formData.bleStatu === true) {
txt= '已连接';
cls="green";
txt = '已连接';
cls = "green";
}
if (this.formData.bleStatu === 'connecting') {
txt= '连接中';
txt = '连接中';
}
if (this.formData.bleStatu === 'dicconnect') {
txt= '正在断开';
txt = '正在断开';
}
if (this.formData.bleStatu === 'err') {
txt= '连接异常';
cls="red"
txt = '连接异常';
cls = "red"
}
return {
txt: txt,
cls: cls
}
return {txt:txt,cls:cls}
}
},
methods: {
initWatch(){
this.$watch("deviceInfo.batteryPercentage",(newVal,oldVal)=>{
initWatch() {
this.$watch("deviceInfo.batteryPercentage", (newVal, oldVal) => {
if (this.deviceInfo.batteryPercentage < 20 &&
this.deviceInfo.chargeState == 0) {
this.popupType = 'bettery';
@ -483,8 +487,8 @@
this.sliderValue = deviceState[2];
this.deviceInfo.batteryRemainingTime = deviceState[3];
break;
case 6:
if(deviceState[1]==50){
case 6:
if (deviceState[1] == 50) {
this.popupType = 'person';
this.showPopupFlag = true;
this.popupMessage = '信息发送成功';
@ -496,15 +500,15 @@
this.currentMainMode = this.getMainLightModeLabel(deviceState[1]);
this.isLaserOn = deviceState[2] === 1; //第3位表示当时激光灯档位
this.currentlaserMode = this.isLaserOn ? "开启" : "关闭";
this.deviceInfo.alarmStatus= deviceState[6];//报警状态
this.itemInfo.alarmStatus= deviceState[6];
this.deviceInfo.alarmStatus = deviceState[6]; //报警状态
this.itemInfo.alarmStatus = deviceState[6];
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.apiType === 'listA') {
this.fetchDeviceDetail(data.data.id)
} else {
@ -539,7 +543,7 @@
if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') {
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
these.formData.bleStatu = true;
// these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
@ -597,9 +601,11 @@
uni.navigateTo({
url: "/pages/common/addBLE/addEquip",
events: {
BindOver: function(data) {
console.log(data)
BindOver(data) {
console.log("蓝牙配对成功:", data);
these.formData.deviceId = data.bleId;
these.formData.bleStatu = true;
console.log("蓝牙配对成功:", these.formData);
}
},
success: function(res) {
@ -627,9 +633,7 @@
},
bleStateBreak() {
if (this.Status.pageHide) {
return;
}
//蓝牙适配器不可用
this.formData.bleStatu = false;
uni.showToast({
@ -640,9 +644,7 @@
},
bleStateRecovry() {
console.log("蓝牙可用");
if (this.Status.pageHide) {
return;
}
console.log("蓝牙可用");
//蓝牙适配器再次可用,尝试恢复连接
showLoading(this, {
@ -650,7 +652,7 @@
});
this.formData.bleStatu = 'connecting';
ble.LinkBlue(these.formData.deviceId).then(() => {
these.formData.bleStatu = true;
// these.formData.bleStatu = true;
updateLoading(these, {
text: '连接成功'
});
@ -688,18 +690,9 @@
},
deviceRecovry(res) {
if (this.Status.pageHide) {
return;
}
if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true;
setTimeout(() => {
hideLoading(these, 1000);
});
uni.showToast({
icon: 'success',
title: '蓝牙连接成功'
});
console.log('蓝牙连接成功');
if (res.deviceId == this.formData.deviceId) {
this.formData.bleStatu = true;
}
},
@ -1127,7 +1120,7 @@
return;
}
this.lightModeB = true;
this.selectedImage=null;
this.selectedImage = null;
},
// 上传开机画面
checkImgUpload() {
@ -1609,6 +1602,18 @@
if (combinedData.length === curr - 1) {
holdHand('transmit complete', 200).then(res => {
let json = {
deviceId: this.itemInfo.id,
name: these.personnelInfo.name,
position: these.personnelInfo.position,
unitName: these.personnelInfo.unitName,
code: these.personnelInfo.code
};
api.sendUsr(json);
MsgSuccess("人员信息发送成功", "确定", these);
hideLoading(these);
this.setBleFormData();
@ -1791,7 +1796,7 @@
// title: registerRes.msg,
// icon: 'none'
// })
return
}
@ -1891,6 +1896,14 @@
})
return
}
Common.saveDeviceLog({
deviceId: this.itemInfo.id,
name: '发送紧急通知',
sendMsg: this.messageToSend
}).catch(ex => {
});
// 4. 获取设备状态
let deviceImei = this.itemInfo.deviceImei
//let typeName = this.itemInfo.typeName
@ -2064,15 +2077,14 @@
payload) : payload;
let keys = Object.keys(parsedMessage);
if("sta_BreakNews" in parsedMessage){
if ("sta_BreakNews" in parsedMessage) {
console.error("收到确认消息")
if(parsedMessage.sta_BreakNews=='I get it'){
MsgSuccess("用户已确认收到紧急通知","",this);
if (parsedMessage.sta_BreakNews == 'I get it') {
MsgSuccess("用户已确认收到紧急通知", "", this);
}
}
else if (keys.length && "state" in parsedMessage) {
} else if (keys.length && "state" in parsedMessage) {
const deviceState = parsedMessage.state; // 直接取 state 数组
// 切换主灯光模式,亮度值设备同步
if (!deviceState || !deviceState instanceof Array) {
@ -2080,8 +2092,8 @@
}
this.onReceive(deviceState, parsedMessage);
}else{
console.error("丢弃的消息",payload)
} else {
console.error("丢弃的消息", payload)
}
} catch (error) {
console.log('解析MQTT消息失败:', error, '原始消息:', payload);
@ -2118,7 +2130,7 @@
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(
res => {
these.formData.bleStatu = true;
// these.formData.bleStatu = true;
}).catch(ex => {
these.formData.bleStatu = 'err';
MsgError("连接错误:" + ex.msg, "确定", these);
@ -2140,8 +2152,8 @@
if (f) {
this.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功")
this.formData.bleStatu = true;
console.log("连接成功", f)
// these.formData.bleStatu = true;
}).catch(ex => {
MsgError("连接错误:" + ex.msg, "确定", these);
});