绑定新设备后重新初始化蓝牙模块

This commit is contained in:
范鹏 2024-09-05 19:48:02 +08:00
parent 4602f45dc6
commit 47cac685ab
3 changed files with 14 additions and 2 deletions

View File

@ -3,7 +3,7 @@
"appid" : "__UNI__933D519", "appid" : "__UNI__933D519",
"description" : "", "description" : "",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "5", "versionCode" : "6",
"transformPx" : false, "transformPx" : false,
/* */ /* */
"mp-weixin" : { "mp-weixin" : {

View File

@ -33,7 +33,8 @@ export default {
console.log(this.name) console.log(this.name)
}, },
methods: { methods: {
...mapActions(useBluetoothStore, ['addLockUser', 'closeBluetoothConnection', 'updateBindedDeviceName']), ...mapActions(useBluetoothStore, ['addLockUser', 'closeBluetoothConnection', 'updateBindedDeviceName',
'closeAllBluetooth', 'initAndListenBluetooth']),
...mapActions(useLockStore, ['getLockList', 'updateLockSearch']), ...mapActions(useLockStore, ['getLockList', 'updateLockSearch']),
...mapActions(useBasicStore, ['backAndToast']), ...mapActions(useBasicStore, ['backAndToast']),
uopdateName(data) { uopdateName(data) {
@ -75,6 +76,8 @@ export default {
if(addUserCode === 0) { if(addUserCode === 0) {
this.closeBluetoothConnection() this.closeBluetoothConnection()
this.updateBindedDeviceName(this.currentLockInfo.name) this.updateBindedDeviceName(this.currentLockInfo.name)
this.closeAllBluetooth()
this.initAndListenBluetooth()
} else if(addUserCode === -1) { } else if(addUserCode === -1) {
uni.hideLoading() uni.hideLoading()
this.backAndToast('添加失败,请重试') this.backAndToast('添加失败,请重试')

View File

@ -107,6 +107,15 @@ export const useBluetoothStore = defineStore('ble', {
} }
return { code, data, message } return { code, data, message }
}, },
// 关闭全部蓝牙监听并关闭蓝牙模拟
closeAllBluetooth() {
uni.offBluetoothAdapterStateChange()
uni.closeBluetoothAdapter({
success(res) {
console.log('关闭蓝牙模块', res)
}
})
},
// 初始化并监听 // 初始化并监听
async initAndListenBluetooth(tipFlag) { async initAndListenBluetooth(tipFlag) {
// 初始化蓝牙 // 初始化蓝牙