|
@@ -119,7 +119,14 @@ export default {
|
|
|
startBluetooth(services = []) {
|
|
|
let that = this;
|
|
|
uni.onBluetoothDeviceFound(function ({ devices }) {
|
|
|
- that.devices = that.devices.concat(devices);
|
|
|
+ let index = that.devices.findIndex(
|
|
|
+ (v) => v.deviceId == devices[0].deviceId
|
|
|
+ );
|
|
|
+ if (index == -1) {
|
|
|
+ that.devices = that.devices.concat(devices);
|
|
|
+ } else {
|
|
|
+ that.devices[index] = devices[0];
|
|
|
+ }
|
|
|
that.empty = that.devices.length == 0;
|
|
|
});
|
|
|
uni.startBluetoothDevicesDiscovery({
|
|
@@ -166,6 +173,7 @@ export default {
|
|
|
showCancel: false,
|
|
|
confirmText: "确认",
|
|
|
});
|
|
|
+ that.connected = "";
|
|
|
that.closeBLEConnection();
|
|
|
} else {
|
|
|
let services = res.services.find(
|
|
@@ -219,6 +227,7 @@ export default {
|
|
|
that.$Http.setBluetooth(device);
|
|
|
} else {
|
|
|
that.closeBLEConnection();
|
|
|
+ that.connected = "";
|
|
|
}
|
|
|
},
|
|
|
});
|
|
@@ -229,6 +238,7 @@ export default {
|
|
|
confirmText: "确认",
|
|
|
});
|
|
|
that.closeBLEConnection();
|
|
|
+ that.connected = "";
|
|
|
}
|
|
|
},
|
|
|
});
|
|
@@ -238,22 +248,26 @@ export default {
|
|
|
showCancel: false,
|
|
|
confirmText: "确认",
|
|
|
});
|
|
|
+ that.connected = "";
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
fail(err) {
|
|
|
console.error("获取蓝牙服务失败", err);
|
|
|
that.handleFail(fail);
|
|
|
+ that.connected = "";
|
|
|
},
|
|
|
});
|
|
|
} else {
|
|
|
console.log("设备连接失败", that.codes[res.errCode]);
|
|
|
that.handleFail(res);
|
|
|
+ that.connected = "";
|
|
|
}
|
|
|
},
|
|
|
fail: (fail) => {
|
|
|
console.log("连接失败", fail);
|
|
|
that.handleFail(fail);
|
|
|
+ that.connected = "";
|
|
|
},
|
|
|
});
|
|
|
},
|