From cca9df8e8191252d92da1412ede426b3ab23fc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Tue, 18 Feb 2025 09:27:34 +0800 Subject: [PATCH 1/7] v1.2.0+31 --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 4228f74..20de3bb 100644 --- a/manifest.json +++ b/manifest.json @@ -2,8 +2,8 @@ "name" : "wx-starlock", "appid" : "__UNI__933D519", "description" : "", - "versionName" : "1.1.3", - "versionCode" : "30", + "versionName" : "1.2.0", + "versionCode" : "31", "transformPx" : false, /* 小程序特有相关 */ "mp-weixin" : { From b1d7eca43521851dc1078f879e48969b6e82c404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Tue, 18 Feb 2025 09:31:54 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E9=99=90=E6=97=B6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BD=93=E5=89=8D=E6=97=B6=E9=97=B4=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/temporaryDate/temporaryDate.vue | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pages/temporaryDate/temporaryDate.vue b/pages/temporaryDate/temporaryDate.vue index 3474f30..508e8f6 100644 --- a/pages/temporaryDate/temporaryDate.vue +++ b/pages/temporaryDate/temporaryDate.vue @@ -133,6 +133,14 @@ return } + if (endDate.value <= new Date().getTime()) { + uni.showToast({ + title: '失效时间需晚于当前时间', + icon: 'none' + }) + return + } + if (pending.value) { return } 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 3/7] =?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) } } }) From 3840971b9c7cb42042b309e7d990eb0437e23d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Thu, 20 Feb 2025 15:50:28 +0800 Subject: [PATCH 4/7] =?UTF-8?q?1.=20=E5=AE=8C=E6=88=90=E9=99=A4=E9=94=81?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=92=8C=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=A4=96=E7=9A=84=E5=85=A8=E9=83=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/lockSetting.js | 12 - api/setting.js | 18 ++ pages.json | 42 +++ pages/LockDate/LockDate.vue | 112 ++++++++ pages/autoLock/autoLock.vue | 192 +++++++++++++ pages/faceSetting/faceSetting.vue | 200 +++++++++++++ pages/lockSound/lockSound.vue | 138 +++++++++ pages/setting/setting.vue | 111 +++++-- pages/syncElec/syncElec.vue | 7 + pages/updateSetting/updateSetting.vue | 66 +++++ pages/uploadLockData/uploadLockData.vue | 116 ++++++++ stores/basic.js | 30 ++ stores/bluetooth.js | 368 +++++++++++++++++++++++- 13 files changed, 1380 insertions(+), 32 deletions(-) delete mode 100644 api/lockSetting.js create mode 100644 pages/LockDate/LockDate.vue create mode 100644 pages/autoLock/autoLock.vue create mode 100644 pages/faceSetting/faceSetting.vue create mode 100644 pages/lockSound/lockSound.vue create mode 100644 pages/updateSetting/updateSetting.vue create mode 100644 pages/uploadLockData/uploadLockData.vue diff --git a/api/lockSetting.js b/api/lockSetting.js deleted file mode 100644 index 3a04683..0000000 --- a/api/lockSetting.js +++ /dev/null @@ -1,12 +0,0 @@ -import request from '../utils/request' - -// lockSetting 锁设置模块 - -// 更新锁设置 -export function updateLockSettingRequest(data) { - return request({ - url: '/lockSetting/updateLockSetting', - method: 'POST', - data - }) -} diff --git a/api/setting.js b/api/setting.js index 2eeb2c3..f8c8a62 100644 --- a/api/setting.js +++ b/api/setting.js @@ -11,6 +11,15 @@ export function getLockSettingRequest(data) { }) } +// 更新锁设置 +export function updateLockSettingRequest(data) { + return request({ + url: '/lockSetting/updateLockSetting', + method: 'POST', + data + }) +} + // 更新锁名称 export function updateLockNameRequest(data) { return request({ @@ -55,3 +64,12 @@ export function setGroupRequest(data) { data }) } + +// 上传锁数据 +export function lockDataUploadRequest(data) { + return request({ + url: '/lockRecords/lockDataUpload', + method: 'POST', + data + }) +} diff --git a/pages.json b/pages.json index 4dbaf30..b5b8379 100644 --- a/pages.json +++ b/pages.json @@ -358,6 +358,48 @@ "navigationBarTitleText": "选择分组", "disableScroll": true } + }, + { + "path": "pages/updateSetting/updateSetting", + "style": { + "navigationBarTitleText": "设置", + "disableScroll": true + } + }, + { + "path": "pages/lockSound/lockSound", + "style": { + "navigationBarTitleText": "锁声音", + "disableScroll": true + } + }, + { + "path": "pages/autoLock/autoLock", + "style": { + "navigationBarTitleText": "自动闭锁", + "disableScroll": true + } + }, + { + "path": "pages/faceSetting/faceSetting", + "style": { + "navigationBarTitleText": "面容开锁设置", + "disableScroll": true + } + }, + { + "path": "pages/lockDate/lockDate", + "style": { + "navigationBarTitleText": "锁时间", + "disableScroll": true + } + }, + { + "path": "pages/uploadLockData/uploadLockData", + "style": { + "navigationBarTitleText": "上传数据", + "disableScroll": true + } } ], "globalStyle": { diff --git a/pages/LockDate/LockDate.vue b/pages/LockDate/LockDate.vue new file mode 100644 index 0000000..c427167 --- /dev/null +++ b/pages/LockDate/LockDate.vue @@ -0,0 +1,112 @@ + + + + + diff --git a/pages/autoLock/autoLock.vue b/pages/autoLock/autoLock.vue new file mode 100644 index 0000000..76a7655 --- /dev/null +++ b/pages/autoLock/autoLock.vue @@ -0,0 +1,192 @@ + + + + + diff --git a/pages/faceSetting/faceSetting.vue b/pages/faceSetting/faceSetting.vue new file mode 100644 index 0000000..3a5d219 --- /dev/null +++ b/pages/faceSetting/faceSetting.vue @@ -0,0 +1,200 @@ + + + + + diff --git a/pages/lockSound/lockSound.vue b/pages/lockSound/lockSound.vue new file mode 100644 index 0000000..50419a6 --- /dev/null +++ b/pages/lockSound/lockSound.vue @@ -0,0 +1,138 @@ + + + + + diff --git a/pages/setting/setting.vue b/pages/setting/setting.vue index 1b8d259..9b8ec55 100644 --- a/pages/setting/setting.vue +++ b/pages/setting/setting.vue @@ -9,7 +9,7 @@ 自动闭锁 @@ -25,7 +25,7 @@ 锁声音 @@ -41,7 +41,7 @@ 防撬报警 @@ -55,7 +55,7 @@ 远程开锁 @@ -69,7 +69,7 @@ 重置键 @@ -83,7 +83,7 @@ 面容开锁 @@ -96,17 +96,9 @@ - 考勤 - - - 开锁提醒 开锁时是否需联网 锁时间 上传数据 @@ -174,7 +167,7 @@ import { useLockStore } from '@/stores/lock' import { deleteKeyRequest } from '@/api/key' import { useBasicStore } from '@/stores/basic' - import { getLockSettingRequest } from '@/api/setting' + import { getLockSettingRequest, updateLockSettingRequest } from '@/api/setting' const $user = useUserStore() const $bluetooth = useBluetoothStore() @@ -185,6 +178,8 @@ const checked = ref(false) const requestFinished = ref(false) + const pending = ref(false) + const volumeList = ['低', '较低', '中', '较高', '高'] onMounted(async () => { @@ -206,6 +201,86 @@ } }) + const toUpdateSetting = key => { + $basic.routeJump({ + name: 'updateSetting', + params: { + key + }, + events: { + changeSetting() { + changeSetting(key) + } + } + }) + } + + const changeSetting = async key => { + if (pending.value) return + pending.value = true + uni.showLoading({ + title: '更新中' + }) + let featureBit + if (key === 'unlockReminder') { + featureBit = 47 + } else if (key === 'appUnlockOnline') { + featureBit = 55 + } else if (key === 'remoteUnlock') { + featureBit = 28 + } else if (key === 'resetSwitch') { + featureBit = 31 + } else if (key === 'antiPrySwitch') { + featureBit = 30 + } + const { code } = await $bluetooth.updateSetting({ + keyId: $bluetooth.keyId.toString(), + uid: $user.userInfo.uid.toString(), + featureBit, + featureEnable: $bluetooth.currentLockSetting.lockSettingInfo[key] === 1 ? 0 : 1, + withParams: false + }) + $bluetooth.closeBluetoothConnection() + if (code === 0) { + const { code, message } = await updateLockSettingRequest({ + lockId: $bluetooth.currentLockInfo.lockId, + [key]: $bluetooth.currentLockSetting.lockSettingInfo[key] === 1 ? 0 : 1 + }) + pending.value = false + uni.hideLoading() + if (code === 0) { + $bluetooth.updateCurrentLockSetting({ + ...$bluetooth.currentLockSetting, + lockSettingInfo: { + ...$bluetooth.currentLockSetting.lockSettingInfo, + [key]: $bluetooth.currentLockSetting.lockSettingInfo[key] === 1 ? 0 : 1 + } + }) + $lock.updateLockSearch({ + ...$lock.lockSearch, + pageNo: 1 + }) + $lock.getLockList($lock.lockSearch) + uni.showToast({ + title: '更新成功', + icon: 'none' + }) + } else { + uni.showToast({ + title: message, + icon: 'none' + }) + } + } else { + pending.value = false + uni.hideLoading() + uni.showToast({ + title: '更新失败,请保持在锁附近', + icon: 'none' + }) + } + } + const toJump = name => { $basic.routeJump({ name diff --git a/pages/syncElec/syncElec.vue b/pages/syncElec/syncElec.vue index 64b44ca..3260f22 100644 --- a/pages/syncElec/syncElec.vue +++ b/pages/syncElec/syncElec.vue @@ -31,9 +31,11 @@ import { useBluetoothStore } from '@/stores/bluetooth' import { useUserStore } from '@/stores/user' import { updateElectricQuantityRequest } from '@/api/room' + import { useLockStore } from '@/stores/lock' const $bluetooth = useBluetoothStore() const $user = useUserStore() + const $lock = useLockStore() const pending = ref(false) @@ -78,6 +80,11 @@ electricQuantityDate: resultData.electricQuantityDate } }) + $lock.updateLockSearch({ + ...$lock.lockSearch, + pageNo: 1 + }) + $lock.getLockList($lock.lockSearch) uni.showToast({ title: '更新成功', icon: 'none' diff --git a/pages/updateSetting/updateSetting.vue b/pages/updateSetting/updateSetting.vue new file mode 100644 index 0000000..36c3de8 --- /dev/null +++ b/pages/updateSetting/updateSetting.vue @@ -0,0 +1,66 @@ + + + + + diff --git a/pages/uploadLockData/uploadLockData.vue b/pages/uploadLockData/uploadLockData.vue new file mode 100644 index 0000000..4f70b59 --- /dev/null +++ b/pages/uploadLockData/uploadLockData.vue @@ -0,0 +1,116 @@ + + + + + diff --git a/stores/basic.js b/stores/basic.js index 1f4e064..eddeaac 100644 --- a/stores/basic.js +++ b/stores/basic.js @@ -266,6 +266,36 @@ const pages = [ name: 'selectGroup', path: '/pages/selectGroup/selectGroup', tabBar: false + }, + { + name: 'updateSetting', + path: '/pages/updateSetting/updateSetting', + tabBar: false + }, + { + name: 'lockSound', + path: '/pages/lockSound/lockSound', + tabBar: false + }, + { + name: 'autoLock', + path: '/pages/autoLock/autoLock', + tabBar: false + }, + { + name: 'faceSetting', + path: '/pages/faceSetting/faceSetting', + tabBar: false + }, + { + name: 'lockDate', + path: '/pages/lockDate/lockDate', + tabBar: false + }, + { + name: 'uploadLockData', + path: '/pages/uploadLockData/uploadLockData', + tabBar: false } ] diff --git a/stores/bluetooth.js b/stores/bluetooth.js index a4dc7e0..6b2572a 100644 --- a/stores/bluetooth.js +++ b/stores/bluetooth.js @@ -40,7 +40,23 @@ const cmdIds = { // 清理用户 cleanUser: 0x300c, // 扩展命令 - expandCmd: 0x3030 + expandCmd: 0x3030, + // 校准时间 + calibrationTime: 0x30f0, + // 锁密码列表 + lockPasswordList: 0x3021, + // 锁卡片列表 + lockCardList: 0x3022, + // 锁指纹列表 + lockFingerprintList: 0x3023, + // 锁人脸列表 + lockFaceList: 0x3024, + // 锁掌静脉列表 + lockPalmVeinList: 0x3025, + // 锁遥控列表 + lockRemoteList: 0x3026, + // 锁设置列表 + lockSettingList: 0x302a } // 子命令ID @@ -86,7 +102,11 @@ const subCmdIds = { // 同步操作记录 syncRecord: 41, // 更新管理员密码 - updateAdminPassword: 2 + updateAdminPassword: 2, + // 修改设置 + updateSetting: 70, + // 修改设置带参数 + updateSettingWithParams: 72 } export const useBluetoothStore = defineStore('ble', { @@ -319,6 +339,7 @@ export const useBluetoothStore = defineStore('ble', { mode: 'ecb', output: 'array' }) + const length = binaryData[10] * 256 + binaryData[11] console.log('ecb解密后的数据', decrypted) const cmdId = decrypted[0] * 256 + decrypted[1] @@ -523,6 +544,24 @@ export const useBluetoothStore = defineStore('ble', { code: decrypted[2] }) break + case subCmdIds.updateSetting: + that.updateCurrentLockInfo({ + ...that.currentLockInfo, + token: decrypted.slice(5, 9) + }) + characteristicValueCallback({ + code: decrypted[2] + }) + break + case subCmdIds.updateSettingWithParams: + that.updateCurrentLockInfo({ + ...that.currentLockInfo, + token: decrypted.slice(5, 9) + }) + characteristicValueCallback({ + code: decrypted[2] + }) + break default: break } @@ -588,6 +627,40 @@ export const useBluetoothStore = defineStore('ble', { }) } break + case cmdIds.calibrationTime: + characteristicValueCallback({ + code: decrypted[2] + }) + break + case cmdIds.lockPasswordList: + case cmdIds.lockCardList: + case cmdIds.lockFingerprintList: + case cmdIds.lockFaceList: + case cmdIds.lockPalmVeinList: + case cmdIds.lockRemoteList: + case cmdIds.lockSettingList: + that.updateCurrentLockInfo({ + ...that.currentLockInfo, + token: decrypted.slice(3, 7) + }) + let data + if (cmdId === cmdIds.lockSettingList) { + data = { + list: decrypted.slice(7, length) + } + } else { + data = { + page: decrypted[7], + size: decrypted[8], + list: decrypted.slice(9, length) + } + } + console.log(1234, cmdId, data) + characteristicValueCallback({ + code: decrypted[2], + data + }) + break default: that.updateCurrentLockInfo({ ...that.currentLockInfo, @@ -2733,6 +2806,297 @@ export const useBluetoothStore = defineStore('ble', { await this.writeBLECharacteristicValue(packageArray) return this.getWriteResult(this.updateAdminPassword, data) + }, + // 更新设置 + async updateSetting(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, featureBit, featureEnable, withParams, params } = data + + let length = 2 + 1 + 1 + 40 + 20 + 4 + 1 + 16 + if (withParams) { + length += 2 + params.length + } else { + length += 2 + } + const headArray = this.createPackageHeader(3, length) + const contentArray = new Uint8Array(length) + + contentArray[0] = cmdIds.expandCmd / 256 + contentArray[1] = cmdIds.expandCmd % 256 + + contentArray[2] = withParams ? subCmdIds.updateSettingWithParams : subCmdIds.updateSetting + + 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] = featureBit + + if (withParams) { + contentArray[65] = params.length + contentArray.set(new Uint8Array(params), 66) + } else { + contentArray[65] = featureEnable + } + + contentArray.set( + this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), + withParams ? 66 + params.length : 66 + ) + + contentArray[withParams ? 70 + params.length : 70] = 16 + + const md5Array = this.md5Encrypte( + keyId + uid, + this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), + this.currentLockInfo.signKey + ) + + contentArray.set(md5Array, withParams ? 71 + params.length : 71) + + 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.updateSetting, data) + }, + // 校准时间 + async calibrationTime(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 { lockId, uid, nowTime } = data + const length = 2 + 40 + 20 + 4 + 4 + 1 + 16 + const headArray = this.createPackageHeader(3, length) + const contentArray = new Uint8Array(length) + + contentArray[0] = cmdIds.calibrationTime / 256 + contentArray[1] = cmdIds.calibrationTime % 256 + + for (let i = 0; i < lockId.length; i++) { + contentArray[i + 2] = lockId.charCodeAt(i) + } + + for (let i = 0; i < uid.length; i++) { + contentArray[i + 42] = uid.charCodeAt(i) + } + + contentArray.set(this.timestampToArray(nowTime), 62) + + contentArray.set(this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), 66) + contentArray[70] = 16 + + const md5Array = this.md5Encrypte( + lockId + uid, + this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), + this.currentLockInfo.signKey + ) + + contentArray.set(md5Array, 71) + + const cebArray = sm4.encrypt(contentArray, this.currentLockInfo.commKey, { + mode: 'ecb', + output: 'array' + }) + + const packageArray = this.createPackageEnd(headArray, cebArray) + this.writeBLECharacteristicValue(packageArray) + + return this.getWriteResult(this.calibrationTime, data) + }, + // 获取锁数据列表 + async getLockDataList(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 { lockId, uid, page, countReq, type } = data + let length = 2 + 40 + 20 + 4 + 1 + 16 + if (type !== 'setting') { + length += 2 + } + const headArray = this.createPackageHeader(3, length) + const contentArray = new Uint8Array(length) + + let id + + if (type === 'password') { + id = cmdIds.lockPasswordList + } else if (type === 'card') { + id = cmdIds.lockCardList + } else if (type === 'fingerprint') { + id = cmdIds.lockFingerprintList + } else if (type === 'face') { + id = cmdIds.lockFaceList + } else if (type === 'remote') { + id = cmdIds.lockRemoteList + } else if (type === 'palmVein') { + id = cmdIds.lockPalmVeinList + } else if (type === 'setting') { + id = cmdIds.lockSettingList + } + + contentArray[0] = id / 256 + contentArray[1] = id % 256 + + for (let i = 0; i < lockId.length; i++) { + contentArray[i + 2] = lockId.charCodeAt(i) + } + + for (let i = 0; i < uid.length; i++) { + contentArray[i + 42] = uid.charCodeAt(i) + } + + if (type !== 'setting') { + contentArray[62] = page + contentArray[63] = countReq + + contentArray.set(this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), 64) + contentArray[68] = 16 + + const md5Array = this.md5Encrypte( + lockId + uid, + this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), + this.currentLockInfo.signKey + ) + + contentArray.set(md5Array, 69) + } else { + contentArray.set(this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), 62) + contentArray[66] = 16 + + const md5Array = this.md5Encrypte( + lockId + uid, + this.currentLockInfo.token || new Uint8Array([0, 0, 0, 0]), + this.currentLockInfo.signKey + ) + + contentArray.set(md5Array, 67) + } + + const cebArray = sm4.encrypt(contentArray, this.currentLockInfo.commKey, { + mode: 'ecb', + output: 'array' + }) + + const packageArray = this.createPackageEnd(headArray, cebArray) + this.writeBLECharacteristicValue(packageArray) + + return this.getWriteResult(this.getLockDataList, data) } } }) From 2233dd2f6896ce8573aa13b64a8f3c4dcb61bb6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Fri, 21 Feb 2025 10:08:06 +0800 Subject: [PATCH 5/7] =?UTF-8?q?1.=20bug=E4=BF=AE=E5=A4=8D=202.=20=E9=94=81?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/adminDetail/adminDetail.vue | 2 +- pages/autoLock/autoLock.vue | 11 +++- pages/createKey/createKey.vue | 10 +++- pages/createPalmVein/createPalmVein.vue | 2 +- pages/cycleDate/cycleDate.vue | 6 +++ pages/keyDetail/keyDetail.vue | 4 +- pages/keyList/keyList.vue | 4 +- pages/lockDetail/lockDetail.vue | 14 ++--- pages/lockInfo/lockInfo.vue | 11 ++-- pages/passwordDetail/passwordDetail.vue | 22 +++++++- pages/setting/setting.vue | 72 ++++++++++++++++++------- pages/temporaryDate/temporaryDate.vue | 5 ++ 12 files changed, 121 insertions(+), 42 deletions(-) diff --git a/pages/adminDetail/adminDetail.vue b/pages/adminDetail/adminDetail.vue index 87506bf..86cdd16 100644 --- a/pages/adminDetail/adminDetail.vue +++ b/pages/adminDetail/adminDetail.vue @@ -88,7 +88,7 @@ {{ info.keyRight === 1 ? '取消授权会在用户APP连网后生效' - : '授权用户拥有管理员的大部分权限,比如发送要是、发送密码' + : '授权用户拥有管理员的大部分权限,比如发送钥匙、发送密码' }} diff --git a/pages/autoLock/autoLock.vue b/pages/autoLock/autoLock.vue index 76a7655..36c5590 100644 --- a/pages/autoLock/autoLock.vue +++ b/pages/autoLock/autoLock.vue @@ -7,13 +7,13 @@ :checked="check" class="transform-scale-90" :disabled="true" - color="#002ce5" + :color="$bluetooth.currentLockSetting.lockBasicInfo.keyRight === 1 ? '#002ce5' : '#71acff'" /> 延迟时间 @@ -35,6 +35,7 @@ 经过以上设定的时间,锁会自动关闭。开启或修改设置后,请先开一次锁,使时间生效。 { + if ($bluetooth.currentLockSetting.lockBasicInfo.keyRight !== 1) return + show.value = true + } + const changeDuration = data => { if (custom.value) { value.value = Number(data) @@ -176,6 +182,7 @@ } const changeCheck = () => { + if ($bluetooth.currentLockSetting.lockBasicInfo.keyRight !== 1) return check.value = !check.value if (!check.value) { value.value = 0 diff --git a/pages/createKey/createKey.vue b/pages/createKey/createKey.vue index 909fcac..54a19a6 100644 --- a/pages/createKey/createKey.vue +++ b/pages/createKey/createKey.vue @@ -89,7 +89,10 @@ placeholder="请输入姓名" @change-input="changeName('single', $event)" > - 单次钥匙有效期为1小时,只能使用一次 + 单次钥匙有效期为1小时,只能使用一次 + + 小程序暂不支持邮箱登录,若接收者账号为邮箱可先使用星星锁APP登录,绑定手机号后可使用小程序登录 + 发送 @@ -108,7 +111,10 @@ - 接收者可以在有效期内的固定时间段里,不限次数使用 + 接收者可以在有效期内的固定时间段里,不限次数使用 + 小程序暂不支持邮箱登录,若接收者账号为邮箱可先使用星星锁APP登录,绑定手机号后可使用小程序登录 发送 diff --git a/pages/createPalmVein/createPalmVein.vue b/pages/createPalmVein/createPalmVein.vue index fa7e295..8358dc5 100644 --- a/pages/createPalmVein/createPalmVein.vue +++ b/pages/createPalmVein/createPalmVein.vue @@ -123,11 +123,11 @@