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

@ -95,7 +95,7 @@
<view style="padding-bottom: 20rpx;">
<view style="padding-bottom: 20rpx;">
<view class="proinfo lamp">
@ -355,6 +355,15 @@
},
onShow() {
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: {
@ -363,14 +372,14 @@
methods: {
LighSetting(item, index) {
let val=item.key;
let val = item.key;
if (item.key === this.formData.sta_LedType) {
val='led_off';
val = 'led_off';
}
let f = this.getDevice();
// #ifdef APP-PLUS
if (!f) {
this.showBleUnConnect();
@ -382,7 +391,7 @@
deviceId: '12345'
}
// #endif
let json = {
ins_LedType: val
}
@ -390,10 +399,10 @@
ble.sendString(f.deviceId, json, f.writeServiceId, f.wirteCharactId, 30).then(res => {
this.formData.sta_LedType = val;
these.setBleFormData();
}).catch(ex => {
this.showMsg(ex.msg);
});
},
@ -501,13 +510,13 @@
},
deviceDispose(res) {
if (this.Status.pageHide) {
return;
}
// if (this.Status.pageHide) {
// return;
// }
if (res.deviceId == these.formData.deviceId) {
if(res.device){
if (res.device) {
these.formData.bleStatu = 'connecting';
}else{
} else {
this.formData.bleStatu = false;
}
setTimeout(() => {