修复清理用户产生的bug

This commit is contained in:
范鹏 2024-09-02 14:22:19 +08:00
parent fbff1e5cef
commit b18c77bb2c

View File

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