From 1d1adaab0c2e518ddde4253bcfb1e29515982dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Tue, 18 Feb 2025 18:35:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=AE=8C=E6=88=90=E9=94=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5UI=202.=20=E5=AE=8C=E6=88=90=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E4=BF=A1=E6=81=AF=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/setting.js | 47 ++- pages.json | 21 ++ pages/lockInfo/lockInfo.vue | 269 ++++++++++++++ pages/selectGroup/selectGroup.vue | 140 +++++++ pages/setting/setting.vue | 593 ++++++++++++++---------------- pages/syncElec/syncElec.vue | 108 ++++++ stores/basic.js | 15 + stores/bluetooth.js | 131 ++++++- 8 files changed, 1010 insertions(+), 314 deletions(-) create mode 100644 pages/lockInfo/lockInfo.vue create mode 100644 pages/selectGroup/selectGroup.vue create mode 100644 pages/syncElec/syncElec.vue diff --git a/api/setting.js b/api/setting.js index 4a6dfda..2eeb2c3 100644 --- a/api/setting.js +++ b/api/setting.js @@ -5,7 +5,52 @@ import request from '../utils/request' // 获取锁设置 export function getLockSettingRequest(data) { return request({ - url: '/lockSetting/getLockSetting', + url: '/lock/getLockSettingData', + method: 'POST', + data + }) +} + +// 更新锁名称 +export function updateLockNameRequest(data) { + return request({ + url: '/lock/updateLockName', + method: 'POST', + data + }) +} + +// 修改管理员密码 +export function updateAdminPasswordRequest(data) { + return request({ + url: '/room/modifyPwd', + method: 'POST', + data + }) +} + +// 获取分组列表 +export function getGroupListRequest(data) { + return request({ + url: '/authorizedAdmin/listGroup', + method: 'POST', + data + }) +} + +// 创建分组 +export function createGroupRequest(data) { + return request({ + url: '/keyGroup/add', + method: 'POST', + data + }) +} + +// 设置分组 +export function setGroupRequest(data) { + return request({ + url: '/keyGroup/setGroup', method: 'POST', data }) diff --git a/pages.json b/pages.json index 2232296..4dbaf30 100644 --- a/pages.json +++ b/pages.json @@ -337,6 +337,27 @@ "navigationBarTitleText": "修改有效期", "disableScroll": true } + }, + { + "path": "pages/lockInfo/lockInfo", + "style": { + "navigationBarTitleText": "基本信息", + "disableScroll": true + } + }, + { + "path": "pages/syncElec/syncElec", + "style": { + "navigationBarTitleText": "电量", + "disableScroll": true + } + }, + { + "path": "pages/selectGroup/selectGroup", + "style": { + "navigationBarTitleText": "选择分组", + "disableScroll": true + } } ], "globalStyle": { diff --git a/pages/lockInfo/lockInfo.vue b/pages/lockInfo/lockInfo.vue new file mode 100644 index 0000000..662ed1f --- /dev/null +++ b/pages/lockInfo/lockInfo.vue @@ -0,0 +1,269 @@ + + + + + diff --git a/pages/selectGroup/selectGroup.vue b/pages/selectGroup/selectGroup.vue new file mode 100644 index 0000000..71364b3 --- /dev/null +++ b/pages/selectGroup/selectGroup.vue @@ -0,0 +1,140 @@ + + + + + diff --git a/pages/setting/setting.vue b/pages/setting/setting.vue index a97ba60..1b8d259 100644 --- a/pages/setting/setting.vue +++ b/pages/setting/setting.vue @@ -1,98 +1,153 @@ - @@ -300,61 +335,3 @@ background-color: $uni-bg-color-grey; } - - diff --git a/pages/syncElec/syncElec.vue b/pages/syncElec/syncElec.vue new file mode 100644 index 0000000..64b44ca --- /dev/null +++ b/pages/syncElec/syncElec.vue @@ -0,0 +1,108 @@ + + + diff --git a/stores/basic.js b/stores/basic.js index c6b3f23..1f4e064 100644 --- a/stores/basic.js +++ b/stores/basic.js @@ -251,6 +251,21 @@ const pages = [ name: 'temporaryDate', path: '/pages/temporaryDate/temporaryDate', tabBar: false + }, + { + name: 'lockInfo', + path: '/pages/lockInfo/lockInfo', + tabBar: false + }, + { + name: 'syncElec', + path: '/pages/syncElec/syncElec', + tabBar: false + }, + { + name: 'selectGroup', + path: '/pages/selectGroup/selectGroup', + tabBar: false } ] diff --git a/stores/bluetooth.js b/stores/bluetooth.js index 1b1d313..a4dc7e0 100644 --- a/stores/bluetooth.js +++ b/stores/bluetooth.js @@ -84,7 +84,9 @@ const subCmdIds = { // 注册掌纹取消 registerPalmVeinCancel: 44, // 同步操作记录 - syncRecord: 41 + syncRecord: 41, + // 更新管理员密码 + updateAdminPassword: 2 } export const useBluetoothStore = defineStore('ble', { @@ -103,6 +105,8 @@ export const useBluetoothStore = defineStore('ble', { deviceList: [], // 当前锁信息 currentLockInfo: {}, + // 当前锁设置信息 + currentLockSetting: null, // 消息序号 messageCount: 1, // 是否初始化蓝牙 @@ -354,11 +358,16 @@ export const useBluetoothStore = defineStore('ble', { ), lockConfig }) + characteristicValueCallback({ + code: decrypted[2], + data: { lockConfig } + }) console.log('获取锁状态成功', that.currentLockInfo.lockConfig) + } else { + characteristicValueCallback({ + code: decrypted[2] + }) } - characteristicValueCallback({ - code: decrypted[2] - }) break case cmdIds.addUser: that.updateCurrentLockInfo({ @@ -505,6 +514,15 @@ export const useBluetoothStore = defineStore('ble', { characteristicValueCallback({ code: decrypted[2] }) } break + case subCmdIds.updateAdminPassword: + that.updateCurrentLockInfo({ + ...that.currentLockInfo, + token: decrypted.slice(5, 9) + }) + characteristicValueCallback({ + code: decrypted[2] + }) + break default: break } @@ -512,7 +530,9 @@ export const useBluetoothStore = defineStore('ble', { case cmdIds.openDoor: that.updateCurrentLockInfo({ ...that.currentLockInfo, - token: decrypted.slice(2, 6) + token: decrypted.slice(2, 6), + electricQuantity: decrypted[7], + electricQuantityStandby: decrypted[9] }) console.log('开门', decrypted[6], that.currentLockInfo.token) log.info({ @@ -884,6 +904,11 @@ export const useBluetoothStore = defineStore('ble', { console.log('更新当前锁信息', lockInfo) this.currentLockInfo = lockInfo }, + // 更新当前锁设置信息 + updateCurrentLockSetting(lockSetting) { + console.log('更新当前锁设置信息', lockSetting) + this.currentLockSetting = lockSetting + }, // 订阅设备特征值改变 notifyBluetoothCharacteristicValueChange() { const that = this @@ -2612,6 +2637,102 @@ export const useBluetoothStore = defineStore('ble', { await this.writeBLECharacteristicValue(packageArray) return this.getWriteResult(this.syncSingleRecord, data) + }, + // 更新管理员密码 + async updateAdminPassword(data) { + // 确认蓝牙状态正常 + if (this.bluetoothStatus !== 0) { + console.log('写入未执行', this.bluetoothStatus) + this.getBluetoothStatus() + return { + code: -1 + } + } + + // 确认设备连接正常 + if (!this.currentLockInfo.connected) { + const searchResult = await this.searchAndConnectDevice() + if (searchResult.code !== 0) { + return searchResult + } + this.updateCurrentLockInfo({ + ...this.currentLockInfo, + deviceId: searchResult.data.deviceId + }) + console.log('设备ID:', this.currentLockInfo.deviceId) + const result = await this.connectBluetoothDevice() + console.log('连接结果', result) + if (!result) { + return { + code: -1 + } + } + } + + // 检查是否已添加为用户 + const checkResult = await this.checkLockUser() + if (!checkResult) { + return { + code: -1 + } + } + + let { keyId, uid, adminPwd, userCountLimit, startDate, endDate } = data + + const length = 2 + 1 + 1 + 40 + 20 + 2 + 20 + 2 + 4 + 4 + 4 + 1 + 16 + const headArray = this.createPackageHeader(3, length) + const contentArray = new Uint8Array(length) + + contentArray[0] = cmdIds.expandCmd / 256 + contentArray[1] = cmdIds.expandCmd % 256 + + contentArray[2] = subCmdIds.updateAdminPassword + + contentArray[3] = length - 3 + + for (let i = 0; i < keyId.length; i++) { + contentArray[i + 4] = keyId.charCodeAt(i) + } + + for (let i = 0; i < uid.length; i++) { + contentArray[i + 44] = uid.charCodeAt(i) + } + + contentArray[64] = 1 / 256 + contentArray[65] = 1 % 256 + + for (let i = 0; i < adminPwd.length; i++) { + contentArray[i + 66] = adminPwd.charCodeAt(i) + } + + contentArray[86] = (userCountLimit || 0xffff) / 256 + contentArray[87] = (userCountLimit || 0xffff) % 256 + + contentArray.set(this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), 88) + + contentArray.set(this.timestampToArray(startDate), 92) + contentArray.set(this.timestampToArray(endDate), 96) + + contentArray[100] = 16 + + const md5Array = this.md5Encrypte( + keyId + uid, + this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), + this.currentLockInfo.signKey + ) + + contentArray.set(md5Array, 101) + + const cebArray = sm4.encrypt(contentArray, this.currentLockInfo.commKey, { + mode: 'ecb', + output: 'array' + }) + + const packageArray = this.createPackageEnd(headArray, cebArray) + + await this.writeBLECharacteristicValue(packageArray) + + return this.getWriteResult(this.updateAdminPassword, data) } } })