diff --git a/components/kk-printer/index.vue b/components/kk-printer/index.vue index 2d357d0..a6b3cf8 100644 --- a/components/kk-printer/index.vue +++ b/components/kk-printer/index.vue @@ -6,14 +6,6 @@ - 搜索设备 @@ -143,7 +135,8 @@ console.log('初始化蓝牙模块', res2) that.sousuo() }, - fail: (res) => { + fail: (res) => { + console.log('初始化蓝牙模块', res) that.tui.toast('初始化失败', res) this.isShowSearch = true uni.hideLoading(); @@ -160,8 +153,17 @@ that.jiantingshebei() }, fail(err) { + console.log('获取设备失败', err) that.tui.toast('获取设备失败', err) + wx.closeBLEConnection({ + deviceId:uni.getStorageSync('deviceId'), + success (res) { + console.log(res) + } + }) + uni.removeStorageSync('deviceId'); this.isShowSearch = true + this.sousuo() uni.hideLoading(); } }) @@ -179,6 +181,7 @@ let that = this; if(uni.getStorageSync('deviceId')){ console.log("111") + // that.huoqufuwu(uni.getStorageSync('deviceId')) that.lianejieshebei(uni.getStorageSync('deviceId')) }else{ console.log("222") @@ -203,12 +206,27 @@ wx.createBLEConnection({//555 deviceId: deviceId, // 搜索到设备的 deviceId success: () => { + this.isShowSearch = false console.log('连接设备成功') that.huoqufuwu(deviceId) }, fail: (res) => { + console.log('连接设备失败',res) that.tui.toast('连接设备失败', res) - this.isShowSearch = true + if(uni.getStorageSync('deviceId')){ + this.huoqufuwu(uni.getStorageSync('deviceId')) + }else{ + wx.closeBLEConnection({ + deviceId:uni.getStorageSync('deviceId'), + success (res) { + console.log(res) + } + }) + uni.removeStorageSync('deviceId') + this.sousuo() + this.isShowSearch = true + } + uni.hideLoading(); } }) @@ -223,7 +241,14 @@ that.duxietezhengzhi(deviceId,res5) }, fail: (res) => { + console.log(res) that.tui.toast('获取服务失败', res) + wx.closeBLEConnection({ + deviceId:uni.getStorageSync('deviceId'), + success (res1) { + console.log(res1) + } + }) this.isShowSearch = true uni.hideLoading(); } @@ -251,6 +276,12 @@ }, fail: (res) => { that.tui.toast('读写特征值失败', res) + wx.closeBLEConnection({ + deviceId:uni.getStorageSync('deviceId'), + success (res) { + console.log(res) + } + }) this.isShowSearch = true uni.hideLoading(); } @@ -297,6 +328,12 @@ }, fail(res) { console.log('writeBLECharacteristicValue fail', res) + wx.closeBLEConnection({ + deviceId:uni.getStorageSync('deviceId'), + success (res) { + console.log(res) + } + }) if(uni.getStorageSync('deviceId')){ console.log("111") that.xierushuju() @@ -305,6 +342,10 @@ } } }) + uni.hideLoading(); + }, + handleSearchClose(){ + this.isShowSearch = false } } } @@ -334,7 +375,7 @@ .kk-modal { width: 680upx; - height: 80%; + height: 60%; padding: 24upx; box-sizing: border-box; overflow-y: auto;