diff --git a/pages/bindLock/bindLock.vue b/pages/bindLock/bindLock.vue index 03f3160..ed1d3fe 100644 --- a/pages/bindLock/bindLock.vue +++ b/pages/bindLock/bindLock.vue @@ -33,7 +33,7 @@ export default { console.log(this.name) }, methods: { - ...mapActions(useBluetoothStore, ['addLockUser', 'closeBluetoothConnection']), + ...mapActions(useBluetoothStore, ['addLockUser', 'closeBluetoothConnection', 'updateBindedDeviceName']), ...mapActions(useLockStore, ['getLockList', 'updateLockSearch']), ...mapActions(useBasicStore, ['backAndToast']), uopdateName(data) { @@ -74,6 +74,7 @@ export default { }) if(addUserCode === 0) { this.closeBluetoothConnection() + this.updateBindedDeviceName(this.currentLockInfo.name) } else if(addUserCode === -1) { uni.hideLoading() this.backAndToast('添加失败,请重试') diff --git a/stores/bluetooth.js b/stores/bluetooth.js index a9e79b2..646990a 100644 --- a/stores/bluetooth.js +++ b/stores/bluetooth.js @@ -71,10 +71,20 @@ export const useBluetoothStore = defineStore('ble', { // 服务器时间 serverTimestamp: 0, // 设备keyID - keyId: '0' + keyId: '0', + // 刚绑定的设备名称 + bindedDeviceName: '' } }, actions: { + // 保存刚绑定的设备名称 + updateBindedDeviceName(name) { + this.bindedDeviceName = name + setTimeout(() => { + this.bindedDeviceName = '' + console.log('清空设备名称') + }, 15000) + }, // 更新keyId updateKeyId(keyId) { this.keyId = keyId @@ -733,7 +743,7 @@ export const useBluetoothStore = defineStore('ble', { let timer2 return new Promise((resolve) => { uni.startBluetoothDevicesDiscovery({ - success: function (res) { + success: function () { timer2 = setTimeout(() => { uni.stopBluetoothDevicesDiscovery() clearInterval(timer1) @@ -747,7 +757,7 @@ export const useBluetoothStore = defineStore('ble', { if(deviceList[i]?.name === that.currentLockInfo.name) { const uuid = deviceList[i]?.advertisServiceUUIDs[0] console.log('设备UUID', uuid, uuid.slice(2,8), uuid.slice(30,32)) - if(uuid && uuid.slice(2,8)==='758824' && uuid.slice(30,32)==='01') { + if(uuid && uuid.slice(2,8)==='758824' && (uuid.slice(30,32)==='01' || that.bindedDeviceName === that.currentLockInfo.name)) { uni.stopBluetoothDevicesDiscovery() clearTimeout(timer2) clearInterval(timer1)