1. 修改重连逻辑
2. 修改重置判断
This commit is contained in:
parent
d4c216b635
commit
329f9bb594
@ -3,7 +3,7 @@
|
||||
"appid" : "__UNI__933D519",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "7",
|
||||
"versionCode" : "9",
|
||||
"transformPx" : false,
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin" : {
|
||||
|
||||
@ -36,7 +36,7 @@ export default {
|
||||
...mapActions(useBluetoothStore, ['addLockUser', 'closeBluetoothConnection', 'updateBindedDeviceName',
|
||||
'closeAllBluetooth', 'initAndListenBluetooth']),
|
||||
...mapActions(useLockStore, ['getLockList', 'updateLockSearch']),
|
||||
...mapActions(useBasicStore, ['backAndToast']),
|
||||
...mapActions(useBasicStore, ['backAndToast', 'getNetworkType']),
|
||||
uopdateName(data) {
|
||||
this.name = data.detail.value
|
||||
},
|
||||
@ -48,10 +48,15 @@ export default {
|
||||
})
|
||||
return
|
||||
}
|
||||
const netWork = await this.getNetworkType()
|
||||
if(!netWork) {
|
||||
return
|
||||
}
|
||||
uni.showLoading({
|
||||
title: '添加中',
|
||||
mask: true
|
||||
})
|
||||
this.updateBindedDeviceName(this.currentLockInfo.name)
|
||||
const timestamp = parseInt(new Date().getTime() / 1000)
|
||||
const password = (Math.floor(Math.random() * 900000) + 100000).toString()
|
||||
const { code: addUserCode } = await this.addLockUser({
|
||||
@ -75,12 +80,14 @@ export default {
|
||||
})
|
||||
if(addUserCode === 0) {
|
||||
this.closeBluetoothConnection()
|
||||
this.updateBindedDeviceName(this.currentLockInfo.name)
|
||||
this.closeAllBluetooth()
|
||||
this.initAndListenBluetooth()
|
||||
} else if(addUserCode === -1) {
|
||||
uni.hideLoading()
|
||||
this.backAndToast('添加失败,请重试')
|
||||
uni.showToast({
|
||||
title: '添加失败,请靠近设备并保持设备处于唤醒状态',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
} else {
|
||||
uni.hideLoading()
|
||||
|
||||
@ -67,14 +67,14 @@ export default {
|
||||
deviceId: device.deviceId
|
||||
})
|
||||
const result = await this.connectBluetoothDevice()
|
||||
this.stopGetBluetoothDevices()
|
||||
if(result) {
|
||||
this.stopGetBluetoothDevices()
|
||||
const { code: getPublicKeyCode } = await this.getPublicKey(this.currentLockInfo.name)
|
||||
console.log('获取公钥返回', getPublicKeyCode, [...this.currentLockInfo.publicKey])
|
||||
if(getPublicKeyCode !== 0) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '连接失败,请重试',
|
||||
title: '连接失败,请靠近设备并保持设备处于唤醒状态',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
@ -85,7 +85,7 @@ export default {
|
||||
if(getCommKeyCode !== 0) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '连接失败,请重试',
|
||||
title: '连接失败,请靠近设备并保持设备处于唤醒状态',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
@ -101,7 +101,7 @@ export default {
|
||||
if (code !== 0) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '连接失败,请重试',
|
||||
title: '连接失败,请靠近设备并保持设备处于唤醒状态',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
@ -111,12 +111,11 @@ export default {
|
||||
name: 'selectAddress'
|
||||
})
|
||||
} else {
|
||||
this.getBluetoothDevices()
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '连接失败,请重试',
|
||||
title: '连接失败,请靠近设备并保持设备处于唤醒状态',
|
||||
icon: 'none'
|
||||
})
|
||||
uni.hideLoading()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,17 +73,15 @@ export const useBluetoothStore = defineStore('ble', {
|
||||
// 设备keyID
|
||||
keyId: '0',
|
||||
// 刚绑定的设备名称
|
||||
bindedDeviceName: ''
|
||||
bindedDeviceNameList: []
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// 保存刚绑定的设备名称
|
||||
updateBindedDeviceName(name) {
|
||||
this.bindedDeviceName = name
|
||||
setTimeout(() => {
|
||||
this.bindedDeviceName = ''
|
||||
console.log('清空设备名称')
|
||||
}, 15000)
|
||||
if(!this.bindedDeviceNameList.includes(name)) {
|
||||
this.bindedDeviceNameList.push(name)
|
||||
}
|
||||
},
|
||||
// 更新keyId
|
||||
updateKeyId(keyId) {
|
||||
@ -682,20 +680,21 @@ export const useBluetoothStore = defineStore('ble', {
|
||||
})
|
||||
},
|
||||
async fail(res) {
|
||||
console.log('连接失败', res)
|
||||
if(res.errno === 1509007) {
|
||||
resolve(true)
|
||||
return
|
||||
}
|
||||
if(res.errno === 1509001 && number < 1) {
|
||||
// 超时直接返回
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
|
||||
if(number < 1) {
|
||||
// 重新连接
|
||||
resolve(await that.connectBluetoothDevice(number + 1))
|
||||
}
|
||||
uni.showToast({
|
||||
title: '连接失败,请靠近设备并保持设备处于唤醒状态',
|
||||
icon: 'none'
|
||||
})
|
||||
console.log('连接失败', res)
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -770,7 +769,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' || that.bindedDeviceName === that.currentLockInfo.name)) {
|
||||
if(uuid && uuid.slice(2,8)==='758824' && (uuid.slice(30,32)==='01' || that.bindedDeviceNameList.includes(that.currentLockInfo.name))) {
|
||||
uni.stopBluetoothDevicesDiscovery()
|
||||
clearTimeout(timer2)
|
||||
clearInterval(timer1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user