1
0
forked from dyf/APP

合并代码

This commit is contained in:
liub
2026-03-19 14:37:58 +08:00
parent ac59e28281
commit 84feb9f1e8
7 changed files with 150 additions and 162 deletions

View File

@ -53,7 +53,9 @@
Statu: {
bound: null,
timeInteval: null,
isSearch: false
isSearch: false,
pageHide:false,
isBind:false
},
device: {
"deviceId": "",
@ -115,17 +117,32 @@
return "";
}
},
onShow() {
this.Statu.pageHide=false;
},
onHide() {
this.Statu.pageHide=true;
},
onUnload() {
console.log("返回取消订阅");
clearInterval(inteval);
ble.removeAllCallback(pagePath);
if(!this.Statu.isBind && these.device.deviceId){
ble.disconnectDevice(these.device.deviceId).catch(ex=>{
console.error("无法断开蓝牙连接");
});
}
},
onLoad(option) {
these = this;
ble = bleTool.getBleTool();
ble.addStateBreakCallback(res => {
if(this.Statu.pageHide){
return;
}
these.device.linkStatu = false;
hideLoading(these);
uni.showToast({
@ -135,6 +152,9 @@
},pagePath);
ble.addStateRecoveryCallback(res => {
if(this.Statu.pageHide){
return;
}
if (these.device.deviceId) {
showLoading(these, {
text: '蓝牙已恢复正在连接设备'
@ -144,6 +164,9 @@
}
},pagePath);
ble.addDisposeCallback(res => {
if(this.Statu.pageHide){
return;
}
console.log("处理蓝牙断开连接");
these.device.linkStatu = false;
if (these.device.deviceId == res.deviceId) {
@ -156,6 +179,9 @@
},pagePath);
ble.addReceiveCallback((receive, f, path) => {
if(this.Statu.pageHide){
return;
}
console.log("收到设备消息,", receive);
if (these.device.deviceId == receive.deviceId) {
console.log("11111:", receive);
@ -372,6 +398,7 @@
clearTimeout(this.Statu.timeInteval);
this.device.macAddress = null;
this.Statu.timeInteval = null;
this.Statu.isBind=true;
uni.$emit("refreshDeviceList");
setTimeout(() => {
uni.switchTab({