|
@@ -181,7 +181,6 @@
|
|
|
uni.openBluetoothAdapter({
|
|
|
success(res) {
|
|
|
console.log(res, 'openBluetoothAdapter success')
|
|
|
- _this.onBluetoothAdapterStateChange()
|
|
|
_this.loading = true
|
|
|
setTimeout(()=>{
|
|
|
_this.toFindDev()
|
|
@@ -201,6 +200,7 @@
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
+ _this.onBluetoothAdapterStateChange()
|
|
|
},
|
|
|
toFindDev(){
|
|
|
let _this = this
|
|
@@ -229,7 +229,11 @@
|
|
|
if(!res.available){
|
|
|
// 关闭连接
|
|
|
_this.loading = false
|
|
|
- _this.closeBlue('蓝牙已关闭,请开启手机蓝牙')
|
|
|
+ if(_this.connectedDeviceId){
|
|
|
+ _this.closeBlue('蓝牙已关闭,请开启手机蓝牙')
|
|
|
+ }else{
|
|
|
+ _this.statusStr = '蓝牙已关闭,请开启手机蓝牙'
|
|
|
+ }
|
|
|
}else{
|
|
|
if(!res.discovering && !_this.loading){
|
|
|
_this.statusStr = _this.connectedDeviceId ? '蓝牙已启用,请连接设备':'蓝牙已启用,请绑定设备'
|
|
@@ -278,19 +282,18 @@
|
|
|
// 断开蓝牙设备
|
|
|
closeBlue(msg){
|
|
|
let _this = this
|
|
|
- if(_this.connectedDeviceId){
|
|
|
- uni.closeBLEConnection({
|
|
|
- deviceId: _this.connectedDeviceId,
|
|
|
- success: function(res) {
|
|
|
- console.log(res,msg)
|
|
|
- _this.connectedDeviceId = null
|
|
|
- _this.statusStr = msg
|
|
|
- },
|
|
|
- fail(res) {
|
|
|
- console.log(res)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ uni.closeBLEConnection({
|
|
|
+ deviceId: _this.connectedDeviceId,
|
|
|
+ success: function(res) {
|
|
|
+ console.log(res,msg)
|
|
|
+ _this.connectedDeviceId = null
|
|
|
+ _this.statusStr = msg
|
|
|
+ _this.connectStatus = false
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
// 开始连接指定设备
|
|
|
createBLEConnection(){
|