feat:增加卡片蓝牙回调后的增删改查内容
This commit is contained in:
parent
b5605e8025
commit
de6b6e127c
123
common.js
123
common.js
@ -16,20 +16,27 @@ import {
|
|||||||
writeBLECharacteristicValue
|
writeBLECharacteristicValue
|
||||||
} from './uni/basic'
|
} from './uni/basic'
|
||||||
import {
|
import {
|
||||||
addCustomPasswordRequest,
|
addCustomPasswordRequest, addFingerprintRequest, addIcCardRequest,
|
||||||
changeAdminKeyboardPwdRequest,
|
changeAdminKeyboardPwdRequest, clearAllIcCard, deleteIcCardRequest,
|
||||||
deleteLockRequest,
|
deleteLockRequest,
|
||||||
deletePasswordRequest,
|
deletePasswordRequest,
|
||||||
getLastRecordTimeRequest,
|
getLastRecordTimeRequest,
|
||||||
getLockNetTokenRequest,
|
getLockNetTokenRequest,
|
||||||
getStarCloudToken,
|
getStarCloudToken,
|
||||||
getUserNoListRequest,
|
getUserNoListRequest,
|
||||||
updateElectricQuantityRequest,
|
updateElectricQuantityRequest, updateIcCardRequest,
|
||||||
updateLockUserNoRequest,
|
updateLockUserNoRequest,
|
||||||
updatePasswordRequest,
|
updatePasswordRequest,
|
||||||
uploadRecordRequest
|
uploadRecordRequest
|
||||||
} from './api'
|
} from './api'
|
||||||
import { buildNumber, getStorage, setStorage, version } from './export'
|
import {
|
||||||
|
buildNumber,
|
||||||
|
emitRegisterCardConfirmEvent,
|
||||||
|
emitRegisterFingerprintConfirmEvent, emitRegisterFingerprintProcessEvent,
|
||||||
|
getStorage,
|
||||||
|
setStorage,
|
||||||
|
version
|
||||||
|
} from './export'
|
||||||
import log from './log'
|
import log from './log'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -679,6 +686,7 @@ export function updateLockInfo(lockInfo) {
|
|||||||
export function listenCharacteristicValue(res) {
|
export function listenCharacteristicValue(res) {
|
||||||
if (res.deviceId === this.lockInfo.deviceId) {
|
if (res.deviceId === this.lockInfo.deviceId) {
|
||||||
let binaryData = new Uint8Array(res.value)
|
let binaryData = new Uint8Array(res.value)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
binaryData[0] === 0xef &&
|
binaryData[0] === 0xef &&
|
||||||
binaryData[1] === 0x01 &&
|
binaryData[1] === 0x01 &&
|
||||||
@ -689,7 +697,9 @@ export function listenCharacteristicValue(res) {
|
|||||||
if (this.length + 14 > binaryData.length) {
|
if (this.length + 14 > binaryData.length) {
|
||||||
this.completeArray = binaryData
|
this.completeArray = binaryData
|
||||||
} else {
|
} else {
|
||||||
this.parsingCharacteristicValue(binaryData).then(() => {})
|
this.parsingCharacteristicValue(binaryData).then(() => {
|
||||||
|
})
|
||||||
|
console.log('listenCharacteristicValue binaryData', binaryData)
|
||||||
}
|
}
|
||||||
} else if (this.completeArray) {
|
} else if (this.completeArray) {
|
||||||
const combinedArray = new Uint8Array(this.completeArray.length + binaryData.length)
|
const combinedArray = new Uint8Array(this.completeArray.length + binaryData.length)
|
||||||
@ -697,7 +707,8 @@ export function listenCharacteristicValue(res) {
|
|||||||
combinedArray.set(binaryData, this.completeArray.length)
|
combinedArray.set(binaryData, this.completeArray.length)
|
||||||
this.completeArray = combinedArray
|
this.completeArray = combinedArray
|
||||||
if (this.length + 14 === this.completeArray.length) {
|
if (this.length + 14 === this.completeArray.length) {
|
||||||
this.parsingCharacteristicValue(this.completeArray).then(() => {})
|
this.parsingCharacteristicValue(this.completeArray).then(() => {
|
||||||
|
})
|
||||||
this.completeArray = null
|
this.completeArray = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -750,7 +761,6 @@ export async function parsingCharacteristicValue(binaryData) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const cebBinaryData = binaryData.slice(12, binaryData.length - 2)
|
const cebBinaryData = binaryData.slice(12, binaryData.length - 2)
|
||||||
|
|
||||||
const decrypted = sm4.decrypt(cebBinaryData, this.lockInfo.bluetooth.privateKey, {
|
const decrypted = sm4.decrypt(cebBinaryData, this.lockInfo.bluetooth.privateKey, {
|
||||||
mode: 'ecb',
|
mode: 'ecb',
|
||||||
output: 'array'
|
output: 'array'
|
||||||
@ -923,6 +933,101 @@ export async function parsingCharacteristicValue(binaryData) {
|
|||||||
this.characteristicValueCallback(new Result(decrypted[2]))
|
this.characteristicValueCallback(new Result(decrypted[2]))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case subCmdIds.registerCard:
|
||||||
|
if (decrypted[2] === Result.Success.code) {
|
||||||
|
// 锁版应答成功
|
||||||
|
switch (this.requestParams.operate) {
|
||||||
|
case 1:
|
||||||
|
// 修改
|
||||||
|
const updateResult = await updateIcCardRequest({
|
||||||
|
...this.requestParams,
|
||||||
|
cardId: this.requestParams.cardId,
|
||||||
|
cardRight: this.requestParams.isAdmin,
|
||||||
|
lockId: this.lockInfo.lockId,
|
||||||
|
cardNumber: this.requestParams.cardNo,
|
||||||
|
cardType: this.requestParams.cardType,
|
||||||
|
cardUserNo: this.requestParams.cardUserNo
|
||||||
|
})
|
||||||
|
this.characteristicValueCallback(updateResult)
|
||||||
|
await this.disconnectDevice()
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// 删除
|
||||||
|
const deleteResult = await deleteIcCardRequest({
|
||||||
|
cardId: this.requestParams.cardId,
|
||||||
|
lockId: this.lockInfo.lockId,
|
||||||
|
})
|
||||||
|
this.characteristicValueCallback(deleteResult)
|
||||||
|
await this.disconnectDevice()
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// 删除全部
|
||||||
|
const deleteAllResult = await clearAllIcCard({
|
||||||
|
lockId: this.lockInfo.lockId,
|
||||||
|
})
|
||||||
|
this.characteristicValueCallback(deleteAllResult)
|
||||||
|
await this.disconnectDevice()
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.characteristicValueCallback(new Result(decrypted[2]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case subCmdIds.registerCardConfirm:
|
||||||
|
// 收到锁版回复判断操作类型进行对应api操作
|
||||||
|
if (decrypted[2] === Result.Success.code) {
|
||||||
|
switch (this.requestParams.operate) {
|
||||||
|
case 0:
|
||||||
|
// 注册
|
||||||
|
const addResult = await addIcCardRequest({
|
||||||
|
...this.requestParams,
|
||||||
|
isCoerced: this.requestParams.isForce,
|
||||||
|
cardRight: this.requestParams.isAdmin,
|
||||||
|
lockId: this.lockInfo.lockId,
|
||||||
|
cardNumber: this.requestParams.cardNo,
|
||||||
|
cardUserNo: this.requestParams.cardUserNo
|
||||||
|
})
|
||||||
|
if (addResult.code === Result.Success.code) {
|
||||||
|
// 增加返回一个卡序号
|
||||||
|
addResult.data.cardNo = decrypted[6] * 256 + decrypted[7];
|
||||||
|
}
|
||||||
|
// 触发卡片确认事件
|
||||||
|
emitRegisterCardConfirmEvent(addResult)
|
||||||
|
// 断开蓝牙连接
|
||||||
|
await this.disconnectDevice()
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case subCmdIds.registerFingerprint:
|
||||||
|
console.log('注册指纹开始回调')
|
||||||
|
// 返回锁版应答的Status状态
|
||||||
|
this.characteristicValueCallback(new Result(decrypted[2]))
|
||||||
|
break;
|
||||||
|
case subCmdIds.registerFingerprintProcess:
|
||||||
|
console.log('注册指纹过程回调', decrypted)
|
||||||
|
emitRegisterFingerprintProcessEvent(decrypted)
|
||||||
|
break;
|
||||||
|
case subCmdIds.registerFingerprintConfirm:
|
||||||
|
if (this.requestParams.operate === 0) {
|
||||||
|
const addResult = await addFingerprintRequest({
|
||||||
|
...this.requestParams,
|
||||||
|
isCoerced: this.requestParams.isForce,
|
||||||
|
fingerRight: this.requestParams.isAdmin,
|
||||||
|
lockId: this.lockInfo.lockId,
|
||||||
|
fingerprintNumber: this.requestParams.no || this.requestParams.fingerprintNumber,
|
||||||
|
fingerprintUserNo: this.requestParams.fingerprintUserNo
|
||||||
|
})
|
||||||
|
if (addResult.code === Result.Success.code) {
|
||||||
|
console.log('注册指纹确认回调')
|
||||||
|
// 触发指纹确认事件
|
||||||
|
emitRegisterFingerprintConfirmEvent(addResult)
|
||||||
|
// 断开蓝牙连接
|
||||||
|
await this.disconnectDevice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -938,7 +1043,8 @@ export async function parsingCharacteristicValue(binaryData) {
|
|||||||
lockId: this.lockInfo.lockId,
|
lockId: this.lockInfo.lockId,
|
||||||
electricQuantity: decrypted[7],
|
electricQuantity: decrypted[7],
|
||||||
electricQuantityStandby: decrypted[9]
|
electricQuantityStandby: decrypted[9]
|
||||||
}).then(() => {})
|
}).then(() => {
|
||||||
|
})
|
||||||
}
|
}
|
||||||
this.characteristicValueCallback(new Result(decrypted[6], {lock: this.lockInfo}))
|
this.characteristicValueCallback(new Result(decrypted[6], {lock: this.lockInfo}))
|
||||||
break
|
break
|
||||||
@ -1040,6 +1146,7 @@ export function createPackageHeader(encryptionType, originalLength) {
|
|||||||
return headArray
|
return headArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 断开与设备的连接
|
// 断开与设备的连接
|
||||||
export async function disconnectDevice() {
|
export async function disconnectDevice() {
|
||||||
return await closeBLEConnection(this.lockInfo.deviceId)
|
return await closeBLEConnection(this.lockInfo.deviceId)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user