合并代码
This commit is contained in:
@ -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({
|
||||
|
||||
Reference in New Issue
Block a user