feat: 优化蓝牙连接和关闭逻辑,增加平台判断,提升代码可读性

This commit is contained in:
fanpeng 2025-07-14 15:00:18 +08:00
parent e882aef71e
commit 5b12b5f198
4 changed files with 11 additions and 7 deletions

View File

@ -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({

View File

@ -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>

View File

@ -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,

View File

@ -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
} }