1
0
forked from dyf/APP

蓝牙小优化,App隐藏时断开设备连接

This commit is contained in:
liub
2026-03-16 15:20:18 +08:00
parent 7512b7211c
commit ede41f68fd
21 changed files with 417 additions and 227 deletions

View File

@ -243,7 +243,7 @@
],
activeIndex: -1,
bgColor: '#2a2a2a',
itemBgColor: '#00000000',
itemBgColor: '#3a3a3a',
textColor: '#ffffffde',
textAlign: 'flex-start',
title: '主灯模式',
@ -376,6 +376,15 @@
},
onShow: function() {
this.Status.pageHide = false;
let f=this.getDevice();
if(f){
these.formData.bleStatu = 'connecting';
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => {
console.log("连接成功")
these.formData.bleStatu = true;
});
}
},
computed: {
getbleStatu() {
@ -399,22 +408,20 @@
return txt;
}
switch (this.formData.mode) {
case 0:
case 1:
txt = "强光模式";
break;
case 1:
case 2:
txt = "弱光模式";
break;
case 2:
case 3:
txt = "爆闪模式";
break;
case 3:
txt = "关闭";
break;
default:
txt = "关闭";
break;
@ -481,9 +488,9 @@
})
},
deviceRecovry(res) {
if (this.Status.pageHide) {
return;
}
// if (this.Status.pageHide) {
// return;
// }
if (res.deviceId == these.formData.deviceId) {
this.formData.bleStatu = true;
// 重新连接后状态以设备上报为准
@ -498,9 +505,9 @@
},
deviceDispose(res) {
if (this.Status.pageHide) {
return;
}
// if (this.Status.pageHide) {
// return;
// }
if (res.deviceId == these.formData.deviceId) {
if (res.device) {
these.formData.bleStatu = 'connecting';
@ -587,7 +594,7 @@
}
let json = recei.ReceiveData(receive, device, path, recArr);
console.log("收到消息:", receive.hexs);
console.log("收到消息:", receive);
if (!json) {
return;
}
@ -597,6 +604,8 @@
these.formData[key] = json[key];
}
});
these.formData.mode=parseInt(receive.hexs[2],16);
console.error("mode="+these.formData.mode);
if ('statu' in json) {
const chargingVal = json.statu;
const isCharging = chargingVal === 1 || chargingVal === '1' || chargingVal === true ||
@ -783,7 +792,7 @@
sourceType: ['album'],
success: function(res) {
uni.navigateTo({
url: "/pages/ImgCrop/ImgCrop",
url: "/pages/common/ImgCrop/ImgCrop",
events: {
ImgCutOver: function(data) {
//将8位的二进制数组转换成16进制数据
@ -1023,21 +1032,16 @@
case 0:
if (type == 'main') {
dataValue = 0x01;
} else if (type == 'fu') {
dataValue = 0x04;
}
break;
case 1:
dataValue = 0x02;
break;
// case 2:
// dataValue = 0x02;
// break;
case 2:
dataValue = 0x03;
break;
@ -1071,7 +1075,7 @@
});
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 100).then(() => {
this.formData.mode = mode;
this.formData.mode = mode+1;
this.setBleFormData();
}).catch((ex) => {
these.showPop({
@ -1088,7 +1092,7 @@
},
handleItemClick(item, index) {
debugger;
this.Status.BottomMenu.activeIndex = index;