From b18c77bb2cee93e520f93ba6ce40f4cc1d47bbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Mon, 2 Sep 2024 14:22:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B8=85=E7=90=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BA=A7=E7=94=9F=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stores/bluetooth.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/stores/bluetooth.js b/stores/bluetooth.js index a7dc916..14bb798 100644 --- a/stores/bluetooth.js +++ b/stores/bluetooth.js @@ -347,7 +347,7 @@ export const useBluetoothStore = defineStore('ble', { ...that.currentLockInfo, token: decrypted.slice(2,6) }) - console.log('开门', decrypted[6], that.currentLockInfo.token) + console.log('开门', decrypted[6], that.currentLockInfo.token) characteristicValueCallback({ code: decrypted[6] }) @@ -376,6 +376,7 @@ export const useBluetoothStore = defineStore('ble', { console.log('上报时区结果', res) }) } + break default: that.updateCurrentLockInfo({ ...that.currentLockInfo, @@ -764,9 +765,9 @@ export const useBluetoothStore = defineStore('ble', { }) }, // 检查是否已添加为用户 - async checkLockUser() { + async checkLockUser(flag = false) { console.log('检查是否已添加为用户', this.currentLockInfo.lockUserNo) - if(this.currentLockInfo.lockUserNo === 0) { + if(this.currentLockInfo.lockUserNo === 0 || flag) { const timestamp = parseInt(new Date().getTime() / 1000) const password = (Math.floor(Math.random() * 900000) + 100000).toString() console.log('用户未添加,开始添加用户') @@ -1212,6 +1213,7 @@ export const useBluetoothStore = defineStore('ble', { }, // 获取写入结果 getWriteResult(request, params) { + const that = this return new Promise(resolve => { const getWriteResultTimer = setTimeout(() => { resolve({ code: -1 }) @@ -1219,9 +1221,15 @@ export const useBluetoothStore = defineStore('ble', { characteristicValueCallback = async (data) => { // code 6 token过期,重新获取 if(data.code === 6) { - console.log('token过期', request.toString()) - console.log('token过期', params) resolve(await request(params)) + } else if(data.code === 4) { + const checkResult = await that.checkLockUser(true) + if(checkResult) { + resolve(await request(params)) + } else { + clearTimeout(getWriteResultTimer) + resolve(data) + } } else { clearTimeout(getWriteResultTimer) resolve(data)