|
@@ -203,7 +203,7 @@ Page({
|
|
|
let that = this;
|
|
|
constant.lexinScan.compareList2(that.data.deviceList, function (device) {
|
|
|
if (device) {
|
|
|
- console.log("找到蓝牙了");
|
|
|
+ console.log("找到蓝牙了", JSON.stringify(device));
|
|
|
that.data._willConnectBle = device;
|
|
|
getApp().getBluetoothStatus();
|
|
|
}
|
|
@@ -232,21 +232,28 @@ Page({
|
|
|
BtHelper.getInstance().connect(device, function (isConnected, d) {
|
|
|
console.log("自动连接成功", isConnected)
|
|
|
if (isConnected) {
|
|
|
- device.state = 'online';
|
|
|
- let hasDev = that.data.deviceList.find(item => {
|
|
|
- return item.deviceId === device.deviceId;
|
|
|
- })
|
|
|
-
|
|
|
- let hasOnline = that.data.deviceList.find(item => {
|
|
|
- return item.state === 'online';
|
|
|
+ let hasMyOnline = false;
|
|
|
+ let hasOtherOnline = false;
|
|
|
+ that.data.deviceList.forEach(item => {
|
|
|
+ if (item.state === 'online') {
|
|
|
+ if (item.deviceId == device.deviceId) {
|
|
|
+ hasMyOnline = true;
|
|
|
+ } else {
|
|
|
+ hasOtherOnline = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
- if (hasDev && hasOnline) {
|
|
|
- // 有设备&&有在线的设备, 直接更新
|
|
|
- hasDev.state = 'online';
|
|
|
- that.updateDeviceList(that.data.deviceList, false, false);
|
|
|
- } else {
|
|
|
+ if (hasMyOnline && !hasOtherOnline) {
|
|
|
+ // 自己已经在线,没有其他设备在线, 直接更新
|
|
|
+ console.log("自己已经在线,没有其他设备在线, 直接更新");
|
|
|
that.addBlueDevice(device);
|
|
|
+ } else {
|
|
|
+ let bleDev = that.data.deviceList.find(item => {
|
|
|
+ return item.deviceId === device.deviceId;
|
|
|
+ });
|
|
|
+ bleDev.state = 'online';
|
|
|
+ that.updateDeviceList(that.data.deviceList, false, false);
|
|
|
}
|
|
|
that.stopIntervalId1();
|
|
|
} else {
|
|
@@ -854,7 +861,7 @@ Page({
|
|
|
// });
|
|
|
if (!disDevice) {
|
|
|
// console.log("")
|
|
|
- console.log("没有找到在线的对应的蓝牙设备", JSON.stringify(deviceList))
|
|
|
+ console.log("没有找到在线的对应的蓝牙设备", deviceList.length)
|
|
|
return;
|
|
|
}
|
|
|
|