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