1
0
forked from dyf/APP

加入6107设备页面、蓝牙配对模式修复首次进入找不到设备的问题

This commit is contained in:
liub
2026-01-12 16:18:27 +08:00
parent 78adc0bfed
commit 98162ca214
11 changed files with 1804 additions and 73 deletions

View File

@ -120,6 +120,7 @@
var ble = null;
var these = null;
var eventChannel = null;
var searchTime=null;
export default {
data() {
return {
@ -334,7 +335,7 @@
//搜索到新设备的回调 (Always active)
ble.addDeviceFound((arr) => {
console.log("--- 收到原始扫描数据 ---", JSON.stringify(arr));
// console.log("--- 收到原始扫描数据 ---", JSON.stringify(arr));
if (these.Status.isPageHidden) {
return;
}
@ -343,7 +344,7 @@
}
arr = arr.devices;
console.log(`本次扫描批次发现 ${arr.length} 个设备`);
// console.log(`本次扫描批次发现 ${arr.length} 个设备`);
for (var i = 0; i < arr.length; i++) {
let device = arr[i];
@ -351,9 +352,9 @@
let f = these.EquipMents.find((v, index) => {
if (v.deviceId == device.deviceId) {
console.log(
`更新设备信号: ${device.name || device.deviceId}, RSSI: ${device.RSSI}`
);
// console.log(
// `更新设备信号: ${device.name || device.deviceId}, RSSI: ${device.RSSI}`
// );
these.$set(these.EquipMents[index], 'RSSI', device.RSSI);
return true;
}
@ -361,7 +362,7 @@
});
if (!f) {
console.log("+++ 发现新设备,准备添加到列表:", JSON.stringify(device));
// console.log("+++ 发现新设备,准备添加到列表:", JSON.stringify(device));
if (these.device && these.device.bluetoothName && device.name) {
if (these.device.bluetoothName === device.name || (device.name && device.name
@ -417,27 +418,29 @@
//收到设备的消息回调
ble.addReceiveCallback((receivData, f, path, arr) => {
console.log("000000");
console.log("000000",receivData);
if (these.Status.isPageHidden) {
return;
}
console.log("1111111");
if (f.macAddress && these.device) {
console.log("222222");
clearInterval(this.Status.intval);
this.Status.intval = null;
this.Status.time = null;
if(receivData.str.indexOf('mac address:')>-1 || receivData.str.indexOf('sta_address')>-1
|| (receivData.hexs[0]===0xFC && receivData.hexs.length>=7))
{
console.log("1111111");
if (f.macAddress && these.device) {
console.log("222222");
clearInterval(this.Status.intval);
this.Status.intval = null;
this.Status.time = null;
showLoading(these, {
text: '正在验证设备'
});
showLoading(these, {
text: '正在验证设备'
});
setTimeout(() => {
these.DeviceVerdict(f.deviceId);
}, 0);
setTimeout(() => {
these.DeviceVerdict(f.deviceId);
}, 0);
}
}
}, pagePath);
}
}
@ -452,7 +455,7 @@
}
startValidDevice();
these.refreshBleList();
});
},
@ -502,6 +505,8 @@
});
},
async refreshBleList() {
const systemInfo = uni.getSystemInfoSync();
if (systemInfo.uniPlatform == 'web') {
return;
@ -520,37 +525,42 @@
return;
}
}
ble.StopSearch().finally(() => {
let disconnectPromises = [];
if (ble.data && ble.data.LinkedList) {
ble.data.LinkedList.forEach(device => {
console.log(`Requesting disconnect for ${device.deviceId}`);
disconnectPromises.push(ble.disconnectDevice(device.deviceId));
});
}
Promise.allSettled(disconnectPromises).finally(() => {
these.EquipMents = [];
these.PairEquip = [];
ble.StartSearch().then(result => {
console.log("Fresh scan started successfully.");
}).catch(err => {
console.error("Failed to start fresh scan:", err);
if (err.code === 10001) {
these.showOpenSetting();
} else {
uni.showModal({
title: '提示',
content: '开始搜索失败:' + err.msg
});
}
clearTimeout(searchTime);
searchTime=setTimeout(()=>{
ble.StopSearch().finally(() => {
let disconnectPromises = [];
if (ble.data && ble.data.LinkedList) {
ble.data.LinkedList.forEach(device => {
console.log(`Requesting disconnect for ${device.deviceId}`);
disconnectPromises.push(ble.disconnectDevice(device.deviceId));
});
}
Promise.allSettled(disconnectPromises).finally(() => {
these.EquipMents = [];
these.PairEquip = [];
ble.StartSearch().then(result => {
console.log("Fresh scan started successfully.");
}).catch(err => {
console.error("Failed to start fresh scan:", err);
if (err.code === 10001) {
these.showOpenSetting();
} else {
uni.showModal({
title: '提示',
content: '开始搜索失败:' + err.msg
});
}
});
});
});
});
},800);
},
isItemLink: function(item, index) {
let src = '/static/images/BLEAdd/noLink.png';
@ -599,8 +609,6 @@
if (index > -1) {
this.PairEquip.splice(index, 1);
}
}
console.log("f=", f);