1
0
forked from dyf/APP

670增加去连接蓝牙,其它体验问题小调整

This commit is contained in:
liub
2025-09-25 09:59:37 +08:00
parent 497cce1e45
commit 17e76f9fa8
10 changed files with 340 additions and 160 deletions

View File

@ -102,6 +102,8 @@
data() {
return {
Status: {
intval: null,
time: null,
BottomMenu: {
show: false,
showHeader: false,
@ -152,7 +154,7 @@
these = this;
this.EquipMents = [];
ble = bleTool.getBleTool();
ble.addDeviceFound((arr) => {
arr = arr.devices;
@ -173,11 +175,15 @@
}
}
// console.log("equip=", these.EquipMents)
// console.log("equip=", these.EquipMents)
}, pagePath);
// console.log("addEquip")
ble.addReceiveCallback((receivData, f, path, arr) => {
if (f.macAddress && these.device) {
clearInterval(this.Status.intval);
this.Status.intval = null;
this.Status.time = null;
showLoading(these, {
text: '正在验证设备'
});
@ -202,10 +208,10 @@
// this.EquipMents = [];
this.PairEquip = [];
ble && ble.StartSearch().then(res=>{
console.log("开始搜索成功",res);
ble && ble.StartSearch().then(res => {
console.log("开始搜索成功", res);
}).catch((ex) => {
console.log("开始搜索出现异常",ex);
console.log("开始搜索出现异常", ex);
if (ex.code == 10001) {
these.showOpenSetting();
}
@ -244,6 +250,8 @@
ble.showBlueSetting(false);
},
DeviceVerdict(deviceId) { //判断是否是目标设备
console.log("deviceid=", deviceId);
console.log("these.device=", these.device)
if (these.device) { //从设备详情过来的,回设备详情去
let f = ble.data.LinkedList.find(v => {
if (v.deviceId == deviceId) {
@ -252,15 +260,32 @@
}
return false;
});
let removeLink=()=>{
ble.subScribe(deviceId,false);//取消订阅消息
ble.DropDevice(deviceId);//从缓存中删除该设备
ble.disconnectDevice(deviceId);//断开与该设备的连接
let index=this.PairEquip.findIndex(function(v) {
return v.deviceId == deviceId;
});
if(index>-1){
this.PairEquip.splice(index,1);
}
}
console.log("f=", f);
if (f.macAddress) {
if (f.macAddress != these.device.deviceMac) {
ble.disconnectDevice(deviceId);
removeLink();
updateLoading(these, {
text: "设备Mac地址错误,请重选设备连接"
})
});
setTimeout(() => {
hideLoading(these);
}, 1000)
return;
}
@ -270,9 +295,44 @@
uni.navigateBack();
return true;
} else {
updateLoading(these, {
text: "等待设备上报Mac地址"
})
this.Status.time = 30;
this.Status.intval = null;
this.Status.intval = setInterval(() => {
this.Status.time = this.Status.time-1;
if (this.Status.time < 0) {
clearInterval(this.Status.intval)
this.Status.intval = null;
this.Status.time = null;
f = ble.data.LinkedList.find(v => {
if (v.deviceId == deviceId) {
v.device = these.device;
return true;
}
return false;
});
if(!f.macAddress){
removeLink();
updateLoading(these, {
text: "出现错误,未收到设备Mac地址"
});
setTimeout(()=>{
hideLoading(these)
},1000);
}
return;
}
updateLoading(these, {
text: "等待设备上报Mac地址," + these.Status.time + 's'
});
}, 1000);
return undefined;
}
}