feat: 完成修改管理员密码功能
This commit is contained in:
parent
1d00c0f535
commit
455687486a
9
api.js
9
api.js
@ -134,3 +134,12 @@ export function updateElectricQuantityRequest(data) {
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改管理员密码
|
||||
export function changeAdminKeyboardPwdRequest(data) {
|
||||
return request({
|
||||
url: '/v1/lock/changeAdminKeyboardPwd',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
121
starCloud.js
121
starCloud.js
@ -4,6 +4,7 @@ import { buildNumber, configs, version } from '@/starCloud/env'
|
||||
import {
|
||||
addCustomPasswordRequest,
|
||||
bindLockRequest,
|
||||
changeAdminKeyboardPwdRequest,
|
||||
deleteLockRequest,
|
||||
deletePasswordRequest,
|
||||
getLockDetailRequest,
|
||||
@ -158,6 +159,8 @@ const cmdIds = {
|
||||
|
||||
// 子命令ID
|
||||
const subCmdIds = {
|
||||
// 修改管理员密码
|
||||
updateAdminPassword: 2,
|
||||
// 设置开锁密码
|
||||
setLockPassword: 3,
|
||||
// 重置开锁密码
|
||||
@ -787,6 +790,110 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
|
||||
return this.getWriteResult(this.deleteLock, params)
|
||||
},
|
||||
/**
|
||||
* 修改管理员密码
|
||||
* @param params
|
||||
* @param {AccountInfo} params.accountInfo 账号信息
|
||||
* @param {String} params.adminPwd 管理员密码
|
||||
* @param {Boolean} params.disconnect 操作后是否断开连接
|
||||
* @returns {Promise<Result>}
|
||||
*/
|
||||
async updateAdminPassword(params) {
|
||||
const { adminPwd, accountInfo } = params
|
||||
|
||||
// 设置执行账号
|
||||
const result = await this.login(accountInfo)
|
||||
if (result.code !== Result.Success.code) {
|
||||
return result
|
||||
}
|
||||
|
||||
// 确认设备连接正常
|
||||
const searchResult = await searchAndConnectDevice(this.lockInfo.bluetooth.bluetoothDeviceName)
|
||||
if (searchResult.code !== Result.Success.code) {
|
||||
return searchResult
|
||||
}
|
||||
this.updateLockInfo(searchResult.data)
|
||||
|
||||
// 检查是否已添加为用户
|
||||
const checkResult = await this.checkLockUser()
|
||||
if (checkResult.code !== Result.Success.code) {
|
||||
return checkResult
|
||||
}
|
||||
|
||||
requestParams = params
|
||||
|
||||
const uid = this.lockInfo.uid.toString()
|
||||
const keyId = this.lockInfo.keyId.toString()
|
||||
const pwdNo = 1
|
||||
const userCountLimit = 0xff
|
||||
const startDate = Math.floor(this.lockInfo.startDate / 1000)
|
||||
const endDate = Math.floor(this.lockInfo.endDate / 1000)
|
||||
|
||||
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] = pwdNo / 256
|
||||
contentArray[65] = pwdNo % 256
|
||||
|
||||
for (let i = 0; i < adminPwd.length; i++) {
|
||||
contentArray[i + 66] = adminPwd.charCodeAt(i)
|
||||
}
|
||||
|
||||
contentArray[86] = userCountLimit / 256
|
||||
contentArray[87] = userCountLimit % 256
|
||||
|
||||
contentArray.set(this.lockInfo.token || new Uint8Array([0, 0, 0, 0]), 88)
|
||||
|
||||
contentArray.set(timestampToArray(startDate), 92)
|
||||
contentArray.set(timestampToArray(endDate), 96)
|
||||
|
||||
contentArray[100] = 16
|
||||
|
||||
const md5Array = md5Encrypt(
|
||||
keyId + uid,
|
||||
this.lockInfo.token || new Uint8Array([0, 0, 0, 0]),
|
||||
this.lockInfo.bluetooth.signKey
|
||||
)
|
||||
|
||||
contentArray.set(md5Array, 101)
|
||||
|
||||
const cebArray = sm4.encrypt(contentArray, this.lockInfo.bluetooth.privateKey, {
|
||||
mode: 'ecb',
|
||||
output: 'array'
|
||||
})
|
||||
|
||||
const packageArray = createPackageEnd(headArray, cebArray)
|
||||
|
||||
const writeResult = await writeBLECharacteristicValue(
|
||||
this.lockInfo.deviceId,
|
||||
this.lockInfo.serviceId,
|
||||
this.lockInfo.writeCharacteristicId,
|
||||
packageArray
|
||||
)
|
||||
|
||||
if (writeResult.code !== Result.Success.code) {
|
||||
return writeResult
|
||||
}
|
||||
|
||||
return this.getWriteResult(this.updateAdminPassword, params)
|
||||
},
|
||||
|
||||
/**
|
||||
* 清理用户
|
||||
@ -1428,6 +1535,20 @@ export const useStarCloudStore = defineStore('starCloud', {
|
||||
case cmdIds.expandCmd:
|
||||
const subCmdId = decrypted[3]
|
||||
switch (subCmdId) {
|
||||
case subCmdIds.updateAdminPassword:
|
||||
this.updateLockInfo({
|
||||
token: decrypted.slice(5, 9)
|
||||
})
|
||||
if (decrypted[2] === Result.Success.code) {
|
||||
const result = await changeAdminKeyboardPwdRequest({
|
||||
password: requestParams.adminPwd,
|
||||
lockId: this.lockInfo.lockId
|
||||
})
|
||||
return characteristicValueCallback(new Result(result.code))
|
||||
} else {
|
||||
characteristicValueCallback(new Result(decrypted[2]))
|
||||
}
|
||||
break
|
||||
case subCmdIds.resetLockPassword:
|
||||
this.updateLockInfo({
|
||||
token: decrypted.slice(5, 9)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user