From f11a642592fa6ff16304f2b0d668a67168283bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Thu, 5 Sep 2024 19:15:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E8=AE=BE=E5=A4=8715=E7=A7=92=E5=86=85=E4=B8=8D=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=98=AF=E5=90=A6=E7=BB=91=E5=AE=9A=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/bindLock/bindLock.vue | 3 ++- stores/bluetooth.js | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) 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)