feat: 优化蓝牙连接和关闭逻辑,增加平台判断,提升代码可读性
This commit is contained in:
parent
e882aef71e
commit
5b12b5f198
@ -90,8 +90,10 @@
|
|||||||
})
|
})
|
||||||
if (addUserCode === 0) {
|
if (addUserCode === 0) {
|
||||||
this.closeBluetoothConnection()
|
this.closeBluetoothConnection()
|
||||||
|
// #ifdef MP
|
||||||
this.closeAllBluetooth()
|
this.closeAllBluetooth()
|
||||||
this.initAndListenBluetooth()
|
this.initAndListenBluetooth()
|
||||||
|
// #endif
|
||||||
} else if (addUserCode === -1) {
|
} else if (addUserCode === -1) {
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
|
|||||||
@ -116,15 +116,15 @@
|
|||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.button {
|
.button {
|
||||||
border-radius: 64rpx;
|
|
||||||
width: 686rpx;
|
width: 686rpx;
|
||||||
margin-left: 32rpx;
|
|
||||||
height: 100rpx;
|
height: 100rpx;
|
||||||
line-height: 100rpx;
|
margin-left: 32rpx;
|
||||||
text-align: center;
|
|
||||||
background-color: #63b8af;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 32rpx;
|
font-size: 32rpx;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
line-height: 100rpx;
|
||||||
|
color: #fff;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #63b8af;
|
||||||
|
border-radius: 64rpx;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -347,7 +347,9 @@
|
|||||||
lockId: $bluetooth.currentLockInfo.lockName.toString(),
|
lockId: $bluetooth.currentLockInfo.lockName.toString(),
|
||||||
uid: $user.userInfo.uid.toString()
|
uid: $user.userInfo.uid.toString()
|
||||||
})
|
})
|
||||||
|
// #ifdef MP
|
||||||
$bluetooth.closeBluetoothConnection()
|
$bluetooth.closeBluetoothConnection()
|
||||||
|
// #endif
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
const { code: resultCode } = await lockDataUploadRequest({
|
const { code: resultCode } = await lockDataUploadRequest({
|
||||||
lockId: $bluetooth.currentLockInfo.lockId,
|
lockId: $bluetooth.currentLockInfo.lockId,
|
||||||
|
|||||||
@ -249,7 +249,7 @@ export const useBluetoothStore = defineStore('ble', {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 蓝牙已经初始化
|
// 蓝牙已经初始化
|
||||||
if (err.errMsg === 'openBluetoothAdapter:fail already opened') {
|
if (err.errMsg === 'openBluetoothAdapter:fail already opened' || err.code === -1) {
|
||||||
resolve(true)
|
resolve(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user