238 lines
7.1 KiB
JavaScript
238 lines
7.1 KiB
JavaScript
// 命令ID
|
|
export const cmdIds = {
|
|
// 获取公钥
|
|
getPublicKey: 0x3090,
|
|
// 获取私钥
|
|
getCommKey: 0x3091,
|
|
// 获取锁状态
|
|
getLockStatus: 0x3040,
|
|
// 新增用户
|
|
addUser: 0x3001,
|
|
// 开门
|
|
openDoor: 0x3005,
|
|
// 重置设备
|
|
resetDevice: 0x3004,
|
|
// 清理用户
|
|
cleanUser: 0x300c,
|
|
// 扩展命令
|
|
expandCmd: 0x3030
|
|
}
|
|
|
|
// 子命令ID
|
|
export const subCmdIds = {
|
|
// 修改管理员密码
|
|
updateAdminPassword: 2,
|
|
// 设置开锁密码
|
|
setLockPassword: 3,
|
|
// 重置开锁密码
|
|
resetLockPassword: 19,
|
|
// 同步开门记录
|
|
syncOpenRecord: 41,
|
|
// 注册卡片
|
|
registerCard: 24,
|
|
// 注册卡片确认
|
|
registerCardConfirm: 22,
|
|
// 注册卡片取消
|
|
registerCardCancel: 25,
|
|
// 注册指纹
|
|
registerFingerprint: 36,
|
|
// 注册指纹确认
|
|
registerFingerprintConfirm: 32,
|
|
// 注册指纹取消
|
|
registerFingerprintCancel: 37,
|
|
// 注册指纹过程
|
|
registerFingerprintProcess: 33,
|
|
// 注册人脸
|
|
registerFace: 81,
|
|
// 注册人脸确认
|
|
registerFaceConfirm: 82,
|
|
// 注册人脸取消
|
|
registerFaceCancel: 86,
|
|
// 注册人脸过程
|
|
registerFaceProcess: 83,
|
|
// 注册遥控
|
|
registerRemote: 26,
|
|
// 注册遥控确认
|
|
registerRemoteConfirm: 27,
|
|
// 注册遥控取消
|
|
registerRemoteCancel: 28,
|
|
// 注册掌纹
|
|
registerPalmVein: 42,
|
|
// 注册掌纹确认
|
|
registerPalmVeinConfirm: 43,
|
|
// 注册掌纹取消
|
|
registerPalmVeinCancel: 44,
|
|
}
|
|
|
|
// 回调事件key昵称
|
|
export const eventKeys = {
|
|
// 注册卡片确认
|
|
registerCardConfirm: 'registerCardConfirm',
|
|
// 注册指纹过程
|
|
registerFingerprintProcess: 'registerFingerprintProcess',
|
|
// 注册指纹确认
|
|
registerFingerprintConfirm: 'registerFingerprintConfirm',
|
|
// 注册人脸过程
|
|
registerFaceProcess: 'registerFaceProcess',
|
|
// 注册人脸确认
|
|
registerFaceConfirm: 'registerFaceConfirm',
|
|
// 注册掌纹确认
|
|
registerPalmVeinConfirm: 'registerPalmVeinConfirm',
|
|
// 注册遥控确认
|
|
registerRemoteConfirm: 'registerRemoteConfirm',
|
|
}
|
|
|
|
|
|
export class Result {
|
|
static codes = {
|
|
Success: 0,
|
|
Fail: -1,
|
|
|
|
NotMoreData: -10,
|
|
|
|
NotAvailableBluetooth: -20,
|
|
NotAvailableBluetoothPermission: -21,
|
|
NotAvailableWeChatNearbyDevicesPermission: -22,
|
|
NotAvailableWeChatLocationPermission: -23,
|
|
NotAvailableWeChatNearbyDevicesEmpty: -24,
|
|
NotAvailableWeChatBluetoothPermission: -25,
|
|
DeviceHasBeenReset: -30,
|
|
|
|
NotRegisteredLock: 4,
|
|
NotTokenLock: 6,
|
|
NotMoreKeyLock: 12,
|
|
ReadyHasKeyLock: 15,
|
|
ReadyHasPassword: 251
|
|
}
|
|
|
|
static resultsMap = new Map([
|
|
[Result.codes.Success, {message: '成功', data: {}}],
|
|
[Result.codes.Fail, {message: '失败', data: {}}],
|
|
|
|
[Result.codes.NotMoreData, {message: '没有更多数据', data: {}}],
|
|
|
|
[Result.codes.NotAvailableBluetooth, {message: '蓝牙尚未打开,请先打开蓝牙', data: {}}],
|
|
[
|
|
Result.codes.NotAvailableBluetoothPermission,
|
|
{message: '小程序蓝牙功能被禁用,请打开小程序蓝牙权限', data: {}}
|
|
],
|
|
[
|
|
Result.codes.NotAvailableWeChatNearbyDevicesPermission,
|
|
{message: '蓝牙功能需要附近设备权限,请前往设置开启微信的附近设备权限后再试', data: {}}
|
|
],
|
|
[
|
|
Result.codes.NotAvailableWeChatLocationPermission,
|
|
{message: '蓝牙功能需要定位权限,请前往设置开启微信的定位权限后再试', data: {}}
|
|
],
|
|
[
|
|
Result.codes.NotAvailableWeChatNearbyDevicesEmpty,
|
|
{
|
|
message: '蓝牙功能需要定位服务,请前往设置开启定位服务后再试',
|
|
data: {}
|
|
}
|
|
],
|
|
[
|
|
Result.codes.NotAvailableWeChatBluetoothPermission,
|
|
{
|
|
message: '微信的蓝牙权限被禁用,请前往设置开启微信的蓝牙权限后再试',
|
|
data: {}
|
|
}
|
|
],
|
|
[Result.codes.DeviceHasBeenReset, {message: '设备已被重置', data: {}}],
|
|
|
|
[Result.codes.NotRegisteredLock, {message: '用户在锁端未注册', data: {}}],
|
|
[Result.codes.NotTokenLock, {message: '用户在锁端token失效', data: {}}],
|
|
[Result.codes.NotMoreKeyLock, {message: '锁端钥匙数量已达上限', data: {}}],
|
|
[Result.codes.ReadyHasKeyLock, {message: '用户已是锁端用户', data: {}}],
|
|
[Result.codes.ReadyHasPassword, {message: '该密码已存在,请更换。', data: {}}]
|
|
])
|
|
|
|
constructor(code, data, message) {
|
|
const result = Result.resultsMap.get(code)
|
|
if (result) {
|
|
this.code = code
|
|
this.message = message || result.message
|
|
this.data = data || result.data
|
|
} else {
|
|
this.code = code
|
|
this.message = message || ''
|
|
this.data = data || {}
|
|
}
|
|
}
|
|
|
|
// 成功
|
|
static get Success() {
|
|
return new Result(Result.codes.Success)
|
|
}
|
|
|
|
// 失败(默认错误)
|
|
static get Fail() {
|
|
return new Result(Result.codes.Fail)
|
|
}
|
|
|
|
// 没有更多数据
|
|
static get NotMoreData() {
|
|
return new Result(Result.codes.NotMoreData)
|
|
}
|
|
|
|
// 蓝牙未开启
|
|
static get NotAvailableBluetooth() {
|
|
return new Result(Result.codes.NotAvailableBluetooth)
|
|
}
|
|
|
|
// 小程序蓝牙权限被禁用
|
|
static get NotAvailableBluetoothPermission() {
|
|
return new Result(Result.codes.NotAvailableBluetoothPermission)
|
|
}
|
|
|
|
// 微信附近的设备权限被禁用
|
|
static get NotAvailableWeChatNearbyDevicesPermission() {
|
|
return new Result(Result.codes.NotAvailableWeChatNearbyDevicesPermission)
|
|
}
|
|
|
|
// 微信定位权限被禁用
|
|
static get NotAvailableWeChatLocationPermission() {
|
|
return new Result(Result.codes.NotAvailableWeChatLocationPermission)
|
|
}
|
|
|
|
// 手机定位服务被关闭
|
|
static get NotAvailableWeChatNearbyDevicesEmpty() {
|
|
return new Result(Result.codes.NotAvailableWeChatNearbyDevicesEmpty)
|
|
}
|
|
|
|
// 微信的蓝牙权限被禁用
|
|
static get NotAvailableWeChatBluetoothPermission() {
|
|
return new Result(Result.codes.NotAvailableWeChatBluetoothPermission)
|
|
}
|
|
|
|
// 设备已被重置
|
|
static get DeviceHasBeenReset() {
|
|
return new Result(Result.codes.DeviceHasBeenReset)
|
|
}
|
|
|
|
// 用户在锁端未注册
|
|
static get NotRegisteredLock() {
|
|
return new Result(Result.codes.NotRegisteredLock)
|
|
}
|
|
|
|
// 用户在锁端token失效
|
|
static get NotTokenLock() {
|
|
return new Result(Result.codes.NotTokenLock)
|
|
}
|
|
|
|
// 锁端钥匙数量已达上限
|
|
static get NotMoreKeyLock() {
|
|
return new Result(Result.codes.NotMoreKeyLock)
|
|
}
|
|
|
|
// 锁端钥匙数量已达上限
|
|
static get ReadyHasKeyLock() {
|
|
return new Result(Result.codes.ReadyHasKeyLock)
|
|
}
|
|
|
|
// 密码已存在
|
|
static get ReadyHasPassword() {
|
|
return new Result(Result.codes.ReadyHasPassword)
|
|
}
|
|
}
|