diff --git a/pages/bindLock/bindLock.vue b/pages/bindLock/bindLock.vue index 70e07f6..df25b3a 100644 --- a/pages/bindLock/bindLock.vue +++ b/pages/bindLock/bindLock.vue @@ -72,10 +72,14 @@ export default { role: 0xff, password }) - if(addUserCode !== 0) { + if(addUserCode === 0) { + } else if(addUserCode === -1) { uni.hideLoading() this.backAndToast('添加失败,请重试') return + } else { + uni.hideLoading() + return } const params = { lockAlias: this.name, diff --git a/pages/lockDetail/lockDetail.vue b/pages/lockDetail/lockDetail.vue index 5556695..110e7d3 100644 --- a/pages/lockDetail/lockDetail.vue +++ b/pages/lockDetail/lockDetail.vue @@ -173,7 +173,7 @@ export default { title: `只能在循环时间内操作门锁`, icon: 'none' }) - } else { + } else if(code === -1) { uni.showToast({ title: `${type === 'close' ? '关' : '开'}锁失败,请保证在锁附近`, icon: 'none' diff --git a/pages/passwordDetail/passwordDetail.vue b/pages/passwordDetail/passwordDetail.vue index ce8fa5a..be596f9 100644 --- a/pages/passwordDetail/passwordDetail.vue +++ b/pages/passwordDetail/passwordDetail.vue @@ -99,12 +99,14 @@ export default { icon: 'none' }) } - } else { + } else if(code === -1) { uni.hideLoading() uni.showToast({ title: '删除失败,请保持在锁附近', icon: 'none' }) + } else { + uni.hideLoading() } } } diff --git a/pages/passwordList/passwordList.vue b/pages/passwordList/passwordList.vue index d398ea6..55d0fe8 100644 --- a/pages/passwordList/passwordList.vue +++ b/pages/passwordList/passwordList.vue @@ -144,12 +144,14 @@ export default { icon: 'none' }) } - } else { + } else if(code === -1) { uni.hideLoading() uni.showToast({ title: '删除失败,请保持在锁附近', icon: 'none' }) + } else { + uni.hideLoading() } } } @@ -188,7 +190,7 @@ export default { icon: 'none' }) } - } else { + } else if(code === -1) { uni.showToast({ title: '重置密码失败,请保持在锁附近', icon: 'none' diff --git a/pages/setting/setting.vue b/pages/setting/setting.vue index 261f398..f4e9b99 100644 --- a/pages/setting/setting.vue +++ b/pages/setting/setting.vue @@ -219,12 +219,14 @@ export default { icon: 'none' }) } - } else { + } else if(code === -1) { uni.hideLoading() uni.showToast({ title: '删除失败,请保持在锁附近', icon: 'none' }) + } else { + uni.hideLoading() } } else { const { code } = await deleteKeyRequest({ diff --git a/stores/bluetooth.js b/stores/bluetooth.js index 89ae20d..3b111ff 100644 --- a/stores/bluetooth.js +++ b/stores/bluetooth.js @@ -737,7 +737,7 @@ export const useBluetoothStore = defineStore('ble', { timer2 = setTimeout(() => { uni.stopBluetoothDevicesDiscovery() clearInterval(timer1) - resolve(false) + resolve({ code: -1 }) }, 10500) timer1 = setInterval(() => { uni.getBluetoothDevices({ @@ -750,7 +750,24 @@ export const useBluetoothStore = defineStore('ble', { uni.stopBluetoothDevicesDiscovery() clearTimeout(timer2) clearInterval(timer1) - resolve(deviceList[i].deviceId) + resolve({ + code: 0, + data: { + deviceId: deviceList[i].deviceId + } + }) + break + } else if(uuid && uuid.slice(2,8)==='758824' && uuid.slice(30,32)==='00') { + uni.stopBluetoothDevicesDiscovery() + clearTimeout(timer2) + clearInterval(timer1) + uni.showToast({ + title: '锁已被重置,请重新绑定', + icon: 'none' + }) + resolve({ + code: -2 + }) break } } @@ -787,9 +804,13 @@ export const useBluetoothStore = defineStore('ble', { } } }) - resolve(false) + resolve({ + code: -1 + }) } else { - resolve(false) + resolve({ + code: -1 + }) } } }) @@ -963,16 +984,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) { @@ -1011,16 +1030,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) { @@ -1093,16 +1110,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) { @@ -1164,16 +1179,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) { @@ -1283,16 +1296,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) { @@ -1366,16 +1377,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) { @@ -1447,16 +1456,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) { @@ -1517,16 +1524,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) { @@ -1595,16 +1600,14 @@ export const useBluetoothStore = defineStore('ble', { // 确认设备连接正常 if(!this.currentLockInfo.connected) { const srerchResult = await this.searchAndConnectDevice() + if(srerchResult.code !== 0) { + return srerchResult + } this.updateCurrentLockInfo({ ...this.currentLockInfo, - deviceId: srerchResult + deviceId: srerchResult.data.deviceId }) console.log('设备ID:', this.currentLockInfo.deviceId) - if(!srerchResult) { - return { - code: -1 - } - } const result = await this.connectBluetoothDevice() console.log('连接结果', result) if(!result) {