|
@@ -150,6 +150,11 @@
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+ uni.getBluetoothDevices({
|
|
|
+ success(res) {
|
|
|
+ console.log(res,'getBluetoothDevices')
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
// 初始化蓝牙
|
|
@@ -165,7 +170,7 @@
|
|
|
_this.loading = true
|
|
|
setTimeout(()=>{
|
|
|
_this.toFindDev()
|
|
|
- },600)
|
|
|
+ },500)
|
|
|
},
|
|
|
fail(err){
|
|
|
console.log(err,'openBluetoothAdapter error')
|
|
@@ -209,8 +214,9 @@
|
|
|
if(!res.available){
|
|
|
// 关闭连接
|
|
|
_this.statusStr = '蓝牙已关闭,请开启手机蓝牙'
|
|
|
- _this.connectedDeviceId = null
|
|
|
- _this.closeConnect()
|
|
|
+ _this.loading = false
|
|
|
+ // _this.connectedDeviceId = null
|
|
|
+ // _this.closeConnect()
|
|
|
}else{
|
|
|
if(!res.discovering && !_this.loading){
|
|
|
_this.statusStr = '蓝牙已启用,请绑定设备'
|
|
@@ -223,18 +229,23 @@
|
|
|
uni.startBluetoothDevicesDiscovery({
|
|
|
services: [],
|
|
|
success(res) {
|
|
|
- console.log(res)
|
|
|
- // 监听寻找到新设备的事件
|
|
|
- uni.onBluetoothDeviceFound(function (res) {
|
|
|
- let devices = res.devices.filter(item => item.name == 'FAYA')
|
|
|
- const hasDev = _this.deviceList.find(item => item.deviceId == res.devices[0].deviceId)
|
|
|
- console.log(devices,hasDev,'devices list')
|
|
|
- if(devices.length&&!hasDev){
|
|
|
- _this.statusStr = '已发现设备'
|
|
|
- _this.deviceList = _this.deviceList.concat(res.devices)
|
|
|
- _this.loading = false
|
|
|
- }
|
|
|
- })
|
|
|
+ console.log(res,'startBluetoothDevicesDiscovery')
|
|
|
+ },
|
|
|
+ fail(res){
|
|
|
+ console.log(res,'startBluetoothDevicesDiscovery error')
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 监听寻找到新设备的事件
|
|
|
+ uni.onBluetoothDeviceFound(function (res) {
|
|
|
+ console.log(res,'onBluetoothDeviceFound')
|
|
|
+ let devices = res.devices.filter(item => item.name == 'FAYA')
|
|
|
+ const hasDev = _this.deviceList.find(item => item.deviceId == res.devices[0].deviceId)
|
|
|
+ console.log(devices,hasDev,'devices list')
|
|
|
+ if(devices.length&&!hasDev){
|
|
|
+ _this.statusStr = '已发现设备'
|
|
|
+ _this.deviceList = _this.deviceList.concat(res.devices)
|
|
|
+ _this.loading = false
|
|
|
}
|
|
|
})
|
|
|
},
|