@ray-js/lock-sdk 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/lib/api/index.js +13 -15
  2. package/lib/api/linkage.d.ts +0 -18
  3. package/lib/api/linkage.js +61 -81
  4. package/lib/api/lock.d.ts +0 -69
  5. package/lib/api/lock.js +91 -113
  6. package/lib/api/log.d.ts +0 -33
  7. package/lib/api/log.js +33 -38
  8. package/lib/api/setting.d.ts +0 -11
  9. package/lib/api/setting.js +17 -30
  10. package/lib/api/temp.d.ts +0 -48
  11. package/lib/api/temp.js +85 -115
  12. package/lib/api/user.d.ts +5 -54
  13. package/lib/api/user.js +40 -52
  14. package/lib/api/video.d.ts +0 -5
  15. package/lib/api/video.js +9 -15
  16. package/lib/config/dp-code/index.d.ts +0 -117
  17. package/lib/config/dp-code/index.js +79 -221
  18. package/lib/config/dp-map/common.d.ts +0 -3
  19. package/lib/config/dp-map/common.js +101 -116
  20. package/lib/config/dp-map/normal.js +29 -50
  21. package/lib/config/dp-map/open.d.ts +0 -16
  22. package/lib/config/dp-map/open.js +62 -63
  23. package/lib/config/dp-map/unlock-method-big.d.ts +0 -60
  24. package/lib/config/dp-map/unlock-method-big.js +196 -233
  25. package/lib/config/dp-map/unlock-method.d.ts +0 -63
  26. package/lib/config/dp-map/unlock-method.js +189 -227
  27. package/lib/config/index.d.ts +0 -25
  28. package/lib/config/index.js +21 -54
  29. package/lib/constant.d.ts +12 -40
  30. package/lib/constant.js +83 -136
  31. package/lib/event.d.ts +0 -6
  32. package/lib/event.js +1 -8
  33. package/lib/index.d.ts +0 -7
  34. package/lib/index.js +45 -71
  35. package/lib/interface.d.ts +0 -523
  36. package/lib/interface.js +1 -1
  37. package/lib/linkage.d.ts +0 -18
  38. package/lib/linkage.js +125 -162
  39. package/lib/log.d.ts +0 -50
  40. package/lib/log.js +255 -290
  41. package/lib/media.d.ts +0 -34
  42. package/lib/media.js +6 -77
  43. package/lib/open.d.ts +0 -35
  44. package/lib/open.js +129 -224
  45. package/lib/other.d.ts +0 -24
  46. package/lib/other.js +98 -159
  47. package/lib/parse/index.d.ts +0 -4
  48. package/lib/parse/index.js +13 -19
  49. package/lib/signal.d.ts +0 -13
  50. package/lib/signal.js +17 -31
  51. package/lib/sleep.d.ts +0 -42
  52. package/lib/sleep.js +41 -98
  53. package/lib/state.d.ts +0 -38
  54. package/lib/state.js +223 -369
  55. package/lib/sync/remote-serect-key.d.ts +0 -4
  56. package/lib/sync/remote-serect-key.js +33 -49
  57. package/lib/sync/t0.d.ts +0 -3
  58. package/lib/sync/t0.js +14 -21
  59. package/lib/sync/temp.d.ts +0 -5
  60. package/lib/sync/temp.js +68 -77
  61. package/lib/sync/unlock-mothod.d.ts +0 -3
  62. package/lib/sync/unlock-mothod.js +28 -40
  63. package/lib/temporary.d.ts +0 -149
  64. package/lib/temporary.js +469 -593
  65. package/lib/unlock-method.d.ts +0 -185
  66. package/lib/unlock-method.js +479 -650
  67. package/lib/user.d.ts +2 -81
  68. package/lib/user.js +202 -336
  69. package/lib/utils/base64-to-hex.js +10 -10
  70. package/lib/utils/byte.d.ts +0 -16
  71. package/lib/utils/byte.js +57 -68
  72. package/lib/utils/constant.js +7 -11
  73. package/lib/utils/device.d.ts +46 -83
  74. package/lib/utils/device.js +294 -322
  75. package/lib/utils/errors.js +75 -122
  76. package/lib/utils/event.js +79 -135
  77. package/lib/utils/hex-to-base64.js +5 -5
  78. package/lib/utils/hex-to-bytes.d.ts +0 -5
  79. package/lib/utils/hex-to-bytes.js +10 -15
  80. package/lib/utils/index.d.ts +0 -42
  81. package/lib/utils/index.js +247 -377
  82. package/lib/utils/log.d.ts +1 -4
  83. package/lib/utils/log.js +71 -74
  84. package/lib/utils/publishDps.d.ts +0 -5
  85. package/lib/utils/publishDps.js +58 -80
  86. package/package.json +3 -4
@@ -1,703 +1,532 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import "core-js/modules/esnext.iterator.constructor.js";
3
- import "core-js/modules/esnext.iterator.map.js";
4
1
  import dpUtils from "@ray-js/tuya-dp-transform";
5
- import { bindUnlockMethodToUser, bindUnlockMethodToUserByRecord, checkFreeUnlockMethods, createUnlockMethod, removeUnlockMethod, editUnlockMethod, fetchCreatePasswordSN, fetchFreeUnlockMethods, getUnlockMethodInfo, unbindMemberUnlockMethod } from "./api/lock";
2
+ import { bindUnlockMethodToUser, bindUnlockMethodToUserByRecord, checkFreeUnlockMethods, createUnlockMethod, removeUnlockMethod, editUnlockMethod, fetchCreatePasswordSN, fetchFreeUnlockMethods, getUnlockMethodInfo, unbindMemberUnlockMethod, } from "./api/lock";
6
3
  import { getUserDetail } from "./api/user";
7
4
  import config from "./config";
8
5
  import dpCodes from "./config/dp-code";
9
- import { add as addMap, reportAdd as reportAddMap, remove as removeMap, reportRemove as reportRemoveMap } from "./config/dp-map/unlock-method";
10
- import { add as addBigMap, reportAdd as reportAddBigMap, remove as removeBigMap, reportRemove as reportRemoveBigMap } from "./config/dp-map/unlock-method-big";
6
+ import { add as addMap, reportAdd as reportAddMap, remove as removeMap, reportRemove as reportRemoveMap, } from "./config/dp-map/unlock-method";
7
+ import { add as addBigMap, reportAdd as reportAddBigMap, remove as removeBigMap, reportRemove as reportRemoveBigMap, } from "./config/dp-map/unlock-method-big";
11
8
  import { validConfigDpMap } from "./config/dp-map/common";
12
- import { getPermanentSetting, getUnlockMethodTypeByDpCode, getUnlockMethodTypeByType, isAdmin, parallelOnly, sleep } from "./utils";
9
+ import { getPermanentSetting, getUnlockMethodTypeByDpCode, getUnlockMethodTypeByType, isAdmin, parallelOnly, sleep, } from "./utils";
13
10
  import { getError } from "./utils/errors";
14
11
  import { publishDps } from "./utils/publishDps";
15
12
  import { encrypt } from "./utils/device";
16
13
  import emitter from "./utils/event";
17
14
  import { DPCHANGE, UNLOCK_METHOD_EVENT } from "./utils/constant";
18
15
  import { sendPhoneVerifyCode } from "./api";
19
- const getAddUnlockError = status => {
20
- if (status >= 0 && status <= 10) {
21
- return getError(1015 + status);
22
- }
23
- if (status === 0xfe) {
24
- return getError(1026);
25
- }
26
- return getError(1016);
27
- };
28
-
29
- /**
30
- * 获取开锁方式详细信息
31
- * @param {number} id 开锁方式 id
32
- * @returns
33
- */
34
- export const getUnlockMethodDetail = async id => {
35
- var _cloudData$notifyInfo, _cloudData$notifyInfo2, _cloudData$notifyInfo3;
36
- const cloudData = await getUnlockMethodInfo({
37
- devId: config.devInfo.devId,
38
- opModeId: id
39
- });
40
- const detail = {
41
- isBound: cloudData.allocateFlag === 1,
42
- phase: cloudData.phase,
43
- dpId: Number(cloudData.opmode),
44
- isSpecial: cloudData.unlockAttr === 1,
45
- unlockName: cloudData.unlockName,
46
- userId: cloudData.userId,
47
- unlockId: Number(cloudData.opmodeValue),
48
- lockUserId: cloudData.lockUserId,
49
- id: cloudData.opmodeId,
50
- userType: cloudData.userType,
51
- notifyInfo: {
52
- appSend: !!((_cloudData$notifyInfo = cloudData.notifyInfo) !== null && _cloudData$notifyInfo !== void 0 && _cloudData$notifyInfo.appSend),
53
- msgPhone: (_cloudData$notifyInfo2 = cloudData.notifyInfo) === null || _cloudData$notifyInfo2 === void 0 ? void 0 : _cloudData$notifyInfo2.msgPhone,
54
- countryCode: (_cloudData$notifyInfo3 = cloudData.notifyInfo) === null || _cloudData$notifyInfo3 === void 0 ? void 0 : _cloudData$notifyInfo3.countryCode
16
+ const getAddUnlockError = (status) => {
17
+ if (status >= 0 && status <= 10) {
18
+ return getError(1015 + status);
19
+ }
20
+ if (status === 0xfe) {
21
+ return getError(1026);
55
22
  }
56
- };
57
- return detail;
23
+ return getError(1016);
58
24
  };
59
- const getUnlockMethodBase = async (type, userId) => {
60
- const {
61
- idsByCode,
62
- devInfo: {
63
- devId
64
- },
65
- supportBigData,
66
- dpSchema
67
- } = config;
68
- const unlockMethodConfig = getUnlockMethodTypeByType(type);
69
- const addDpCode = supportBigData ? dpCodes.unlockMethodCreateW : dpCodes.unlockMethodCreate;
70
- const dpId = idsByCode[unlockMethodConfig.code];
71
- const [user, sn] = await Promise.all([getUserDetail({
72
- devId: devId,
73
- userId: userId
74
- }), fetchCreatePasswordSN({
75
- devId: devId,
76
- dpId
77
- })]);
78
- const {
79
- userType,
80
- lockUserId,
81
- userTimeSet
82
- } = user;
83
- let validConfig;
84
- // 处理时效配置
85
- if (userTimeSet) {
86
- validConfig = dpUtils.parse(userTimeSet,
87
- // @ts-expect-error
88
- validConfigDpMap.childMap);
89
- } else {
90
- validConfig = getPermanentSetting();
91
- }
92
-
93
- // 组装开始入录数据
94
- const dpData = {
95
- type: unlockMethodConfig.id,
96
- stage: 0,
97
- admin: isAdmin(userType),
98
- memberId: lockUserId,
99
- unlockId: supportBigData ? 0xffff : 0xff,
100
- validConfig,
101
- validNum: 0,
102
- pwdLength: 0,
103
- pwd: [],
104
- sn
105
- };
106
- return {
107
- unlockMethodConfig,
108
- devId,
109
- userType,
110
- lockUserId,
111
- sn,
112
- dpId,
113
- addDpCode,
114
- addDpMap: supportBigData ? addBigMap : addMap,
115
- addDpReportMap: supportBigData ? reportAddBigMap : reportAddMap,
116
- dpData
117
- };
25
+ export const getUnlockMethodDetail = async (id) => {
26
+ const cloudData = await getUnlockMethodInfo({
27
+ devId: config.devInfo.devId,
28
+ opModeId: id,
29
+ });
30
+ const detail = {
31
+ isBound: cloudData.allocateFlag === 1,
32
+ phase: cloudData.phase,
33
+ dpId: Number(cloudData.opmode),
34
+ isSpecial: cloudData.unlockAttr === 1,
35
+ unlockName: cloudData.unlockName,
36
+ userId: cloudData.userId,
37
+ unlockId: Number(cloudData.opmodeValue),
38
+ lockUserId: cloudData.lockUserId,
39
+ id: cloudData.opmodeId,
40
+ userType: cloudData.userType,
41
+ notifyInfo: {
42
+ appSend: !!cloudData.notifyInfo?.appSend,
43
+ msgPhone: cloudData.notifyInfo?.msgPhone,
44
+ countryCode: cloudData.notifyInfo?.countryCode,
45
+ },
46
+ };
47
+ return detail;
118
48
  };
119
- const checkSpecial = (isSpecial, params, oldSetting) => {
120
- const supportedPhone = checkSpecialSupportPhone();
121
- if (isSpecial) {
122
- if (!(params !== null && params !== void 0 && params.appSend)) {
123
- if (!supportedPhone) {
124
- throw getError(1057);
125
- } else if (!(params !== null && params !== void 0 && params.msgPhone)) {
126
- throw getError(1058);
127
- }
49
+ const getUnlockMethodBase = async (type, userId) => {
50
+ const { idsByCode, devInfo: { devId }, supportBigData, dpSchema, } = config;
51
+ const unlockMethodConfig = getUnlockMethodTypeByType(type);
52
+ const addDpCode = supportBigData
53
+ ? dpCodes.unlockMethodCreateW
54
+ : dpCodes.unlockMethodCreate;
55
+ const dpId = idsByCode[unlockMethodConfig.code];
56
+ const [user, sn] = await Promise.all([
57
+ getUserDetail({
58
+ devId: devId,
59
+ userId: userId,
60
+ }),
61
+ fetchCreatePasswordSN({
62
+ devId: devId,
63
+ dpId,
64
+ }),
65
+ ]);
66
+ const { userType, lockUserId, userTimeSet } = user;
67
+ let validConfig;
68
+ if (userTimeSet) {
69
+ validConfig = dpUtils.parse(userTimeSet, validConfigDpMap.childMap);
128
70
  }
129
- if (supportedPhone && params !== null && params !== void 0 && params.msgPhone) {
130
- if (!params.countryCode) {
131
- throw getError(1056);
132
- }
133
- if (params.msgPhone !== (oldSetting === null || oldSetting === void 0 ? void 0 : oldSetting.msgPhone) && !params.verifyCode) {
134
- throw getError(1055);
135
- }
71
+ else {
72
+ validConfig = getPermanentSetting();
136
73
  }
137
- }
138
- return {
139
- unlockAttr: isSpecial ? 1 : 0,
140
- notifyInfo: {
141
- appSend: !!(params !== null && params !== void 0 && params.appSend),
142
- msgPhone: supportedPhone ? params === null || params === void 0 ? void 0 : params.msgPhone : undefined,
143
- countryCode: supportedPhone ? params === null || params === void 0 ? void 0 : params.countryCode : undefined,
144
- msgPhoneVerifyCode: supportedPhone ? params === null || params === void 0 ? void 0 : params.verifyCode : undefined
74
+ const dpData = {
75
+ type: unlockMethodConfig.id,
76
+ stage: 0,
77
+ admin: isAdmin(userType),
78
+ memberId: lockUserId,
79
+ unlockId: supportBigData ? 0xffff : 0xff,
80
+ validConfig,
81
+ validNum: 0,
82
+ pwdLength: 0,
83
+ pwd: [],
84
+ sn,
85
+ };
86
+ return {
87
+ unlockMethodConfig,
88
+ devId,
89
+ userType,
90
+ lockUserId,
91
+ sn,
92
+ dpId,
93
+ addDpCode,
94
+ addDpMap: (supportBigData ? addBigMap : addMap),
95
+ addDpReportMap: (supportBigData ? reportAddBigMap : reportAddMap),
96
+ dpData,
97
+ };
98
+ };
99
+ const checkSpecial = (isSpecial, params, oldSetting) => {
100
+ const supportedPhone = checkSpecialSupportPhone();
101
+ if (isSpecial) {
102
+ if (!params?.appSend) {
103
+ if (!supportedPhone) {
104
+ throw getError(1057);
105
+ }
106
+ else if (!params?.msgPhone) {
107
+ throw getError(1058);
108
+ }
109
+ }
110
+ if (supportedPhone && params?.msgPhone) {
111
+ if (!params.countryCode) {
112
+ throw getError(1056);
113
+ }
114
+ if (params.msgPhone !== oldSetting?.msgPhone && !params.verifyCode) {
115
+ throw getError(1055);
116
+ }
117
+ }
145
118
  }
146
- };
119
+ return {
120
+ unlockAttr: isSpecial ? 1 : 0,
121
+ notifyInfo: {
122
+ appSend: !!params?.appSend,
123
+ msgPhone: supportedPhone ? params?.msgPhone : undefined,
124
+ countryCode: supportedPhone ? params?.countryCode : undefined,
125
+ msgPhoneVerifyCode: supportedPhone ? params?.verifyCode : undefined,
126
+ },
127
+ };
147
128
  };
148
-
149
- /**
150
- * 检查是否支持短信通知
151
- * @returns 是否支持短信通知
152
- */
153
129
  export const checkSpecialSupportPhone = () => {
154
- return !!config.dpSchema[dpCodes.message];
130
+ return !!config.dpSchema[dpCodes.message];
155
131
  };
156
-
157
- /**
158
- * 添加开锁密码
159
- */
160
- export const addPassword = async params => {
161
- // 数据验证
162
- if (!params.password) {
163
- throw getError(1054);
164
- }
165
- const specialInfo = checkSpecial(!!params.isSpecial, params.specialInfo);
166
- const {
167
- lockUserId,
168
- dpData,
169
- sn,
170
- addDpCode,
171
- addDpMap,
172
- addDpReportMap,
173
- devId,
174
- dpId,
175
- unlockMethodConfig
176
- } = await getUnlockMethodBase("password", params.userId);
177
- dpData.pwdLength = params.password.length;
178
- dpData.pwd = params.password.split("").map(Number);
179
- const res = await publishDps({
180
- [addDpCode]: dpUtils.format(dpData, addDpMap)
181
- }, {
182
- checkReport: dpData => {
183
- if (typeof dpData[addDpCode] !== "undefined") {
184
- const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
185
- let hasReport = result.type === unlockMethodConfig.id && [0xff, 0xfd].includes(result.stage);
186
- // 是否严格模式
187
- if (config.strictMode) {
188
- hasReport = hasReport && result.memberId === lockUserId && result.sn === sn;
189
- }
190
- if (hasReport) {
191
- if (result.memberId !== lockUserId) {
192
- console.warn(`AddPassword: lockUserId mismatch, expected ${lockUserId}, got ${result.memberId}`);
193
- }
194
- return result;
195
- }
196
- return false;
197
- }
198
- console.warn("AddPassword: An invalid value may have been reported");
199
- return false;
132
+ export const addPassword = async (params) => {
133
+ if (!params.password) {
134
+ throw getError(1054);
200
135
  }
201
- });
202
- if (res.stage === 0xfd) {
203
- // 0xfd 表示添加失败
204
- throw getAddUnlockError(res.status);
205
- }
206
-
207
- // 保存云端数据
208
- const aesPwd = await encrypt(devId, params.password);
209
-
210
- // 收到上报成功后,隔 300毫秒再保存云端
211
- await sleep(300);
212
- return await createUnlockMethod(_objectSpread({
213
- devId: devId,
214
- userId: params.userId,
215
- unlockId: `${dpId}-${res.unlockId}`,
216
- unlockName: params.name,
217
- unlockDetail: aesPwd
218
- }, specialInfo));
136
+ const specialInfo = checkSpecial(!!params.isSpecial, params.specialInfo);
137
+ const { lockUserId, dpData, sn, addDpCode, addDpMap, addDpReportMap, devId, dpId, unlockMethodConfig, } = await getUnlockMethodBase("password", params.userId);
138
+ dpData.pwdLength = params.password.length;
139
+ dpData.pwd = params.password.split("").map(Number);
140
+ const res = await publishDps({
141
+ [addDpCode]: dpUtils.format(dpData, addDpMap),
142
+ }, {
143
+ checkReport: (dpData) => {
144
+ if (typeof dpData[addDpCode] !== "undefined") {
145
+ const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
146
+ let hasReport = result.type === unlockMethodConfig.id &&
147
+ [0xff, 0xfd].includes(result.stage);
148
+ if (config.strictMode) {
149
+ hasReport =
150
+ hasReport && result.memberId === lockUserId && result.sn === sn;
151
+ }
152
+ if (hasReport) {
153
+ if (result.memberId !== lockUserId) {
154
+ console.warn(`AddPassword: lockUserId mismatch, expected ${lockUserId}, got ${result.memberId}`);
155
+ }
156
+ return result;
157
+ }
158
+ return false;
159
+ }
160
+ console.warn("AddPassword: An invalid value may have been reported");
161
+ return false;
162
+ },
163
+ });
164
+ if (res.stage === 0xfd) {
165
+ throw getAddUnlockError(res.status);
166
+ }
167
+ const aesPwd = await encrypt(devId, params.password);
168
+ await sleep(300);
169
+ return await createUnlockMethod({
170
+ devId: devId,
171
+ userId: params.userId,
172
+ unlockId: `${dpId}-${res.unlockId}`,
173
+ unlockName: params.name,
174
+ unlockDetail: aesPwd,
175
+ ...specialInfo,
176
+ });
219
177
  };
220
178
  const addUnlockMethodData = {
221
- unlockMethodConfig: {},
222
- total: 0,
223
- dpCode: "",
224
- dpMap: {},
225
- sn: 0,
226
- lockUserId: 0,
227
- timeoutId: 0,
228
- userId: "",
229
- // 云端用户 id
230
- unlockDpId: 0,
231
- timeout: 15000
179
+ unlockMethodConfig: {},
180
+ total: 0,
181
+ dpCode: "",
182
+ dpMap: {},
183
+ sn: 0,
184
+ lockUserId: 0,
185
+ timeoutId: 0,
186
+ userId: "",
187
+ unlockDpId: 0,
188
+ timeout: 15000,
232
189
  };
233
- const handleAddTimeout = function () {
234
- let timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 15000;
235
- clearTimeout(addUnlockMethodData.timeoutId);
236
- // @ts-expect-error
237
- addUnlockMethodData.timeoutId = setTimeout(() => {
238
- emitter.off(DPCHANGE, handleAddReport);
239
- // 超时处理
240
- emitter.emit(UNLOCK_METHOD_EVENT, {
241
- type: addUnlockMethodData.unlockMethodConfig.type,
242
- stage: "fail",
243
- lockUserId: addUnlockMethodData.lockUserId,
244
- error: getError(1002)
245
- });
246
- }, timeout);
190
+ const handleAddTimeout = (timeout = 15000) => {
191
+ clearTimeout(addUnlockMethodData.timeoutId);
192
+ addUnlockMethodData.timeoutId = setTimeout(() => {
193
+ emitter.off(DPCHANGE, handleAddReport);
194
+ emitter.emit(UNLOCK_METHOD_EVENT, {
195
+ type: addUnlockMethodData.unlockMethodConfig.type,
196
+ stage: "fail",
197
+ lockUserId: addUnlockMethodData.lockUserId,
198
+ error: getError(1002),
199
+ });
200
+ }, timeout);
247
201
  };
248
- const handleAddReport = async dps => {
249
- if (dps[addUnlockMethodData.dpCode]) {
250
- const result = dpUtils.parse(dps[addUnlockMethodData.dpCode], addUnlockMethodData.dpMap);
251
- let eventData = null;
252
- if (result.type !== addUnlockMethodData.unlockMethodConfig.id) {
253
- // 开锁方式类型不匹配或sn(消息uuid)不匹配,忽略此次上报
254
- return;
255
- }
256
- if (config.strictMode) {
257
- // 严格模式下,严格匹配协议规则
258
- if (result.sn !== addUnlockMethodData.sn || result.memberId !== addUnlockMethodData.lockUserId) {
259
- return;
260
- }
261
- } else {
262
- // 非严格模式下,告警不匹配
263
- if (result.sn !== addUnlockMethodData.sn) {
264
- // sn 不匹配,告警
265
- console.warn(`AddUnlockMethod: sn mismatch, expected ${addUnlockMethodData.sn}, got ${result.sn}`);
266
- }
267
- if (result.memberId !== addUnlockMethodData.lockUserId) {
268
- // 成员 id 不匹配,告警
269
- console.warn(`AddUnlockMethod: lockUserId mismatch, expected ${addUnlockMethodData.lockUserId}, got ${result.memberId}`);
270
- }
271
- }
272
- const type = addUnlockMethodData.unlockMethodConfig.type;
273
- switch (result.stage) {
274
- case 0xfc:
275
- {
276
- // 重新计时
277
- handleAddTimeout(addUnlockMethodData.timeout);
278
- // 录入中
279
- eventData = {
280
- type,
281
- stage: "step",
282
- lockUserId: result.memberId,
283
- step: result.step,
284
- total: addUnlockMethodData.total
285
- };
286
- break;
202
+ const handleAddReport = async (dps) => {
203
+ if (dps[addUnlockMethodData.dpCode]) {
204
+ const result = dpUtils.parse(dps[addUnlockMethodData.dpCode], addUnlockMethodData.dpMap);
205
+ let eventData = null;
206
+ if (result.type !== addUnlockMethodData.unlockMethodConfig.id) {
207
+ return;
287
208
  }
288
- case 0xfd:
289
- {
290
- clearMonitoringAddReport();
291
- // 录入失败
292
- eventData = {
293
- stage: "fail",
294
- type,
295
- lockUserId: result.memberId,
296
- error: getAddUnlockError(result.status)
297
- };
298
- break;
209
+ if (config.strictMode) {
210
+ if (result.sn !== addUnlockMethodData.sn ||
211
+ result.memberId !== addUnlockMethodData.lockUserId) {
212
+ return;
213
+ }
299
214
  }
300
- case 0xfe:
301
- {
302
- clearMonitoringAddReport();
303
- if (isCancelAddUnlockMethod) {
304
- // 主动取消录入,则不处理
305
- isCancelAddUnlockMethod = false;
306
- return;
307
- }
308
- // 取消录入
309
- eventData = {
310
- stage: "fail",
311
- type,
312
- lockUserId: result.memberId,
313
- error: getAddUnlockError(result.status)
314
- };
315
- break;
215
+ else {
216
+ if (result.sn !== addUnlockMethodData.sn) {
217
+ console.warn(`AddUnlockMethod: sn mismatch, expected ${addUnlockMethodData.sn}, got ${result.sn}`);
218
+ }
219
+ if (result.memberId !== addUnlockMethodData.lockUserId) {
220
+ console.warn(`AddUnlockMethod: lockUserId mismatch, expected ${addUnlockMethodData.lockUserId}, got ${result.memberId}`);
221
+ }
316
222
  }
317
- case 0xff:
318
- {
319
- clearMonitoringAddReport();
320
- try {
321
- // 收到上报成功后,隔 300毫秒再保存云端
322
- await sleep(300);
323
- // 直接添加云端接口,确保云端数据与设备侧一致
324
- const res = await createUnlockMethod({
325
- devId: config.devInfo.devId,
326
- userId: addUnlockMethodData.userId,
327
- unlockId: `${addUnlockMethodData.unlockDpId}-${result.unlockId}`,
328
- unlockName: "",
329
- unlockAttr: 0
330
- });
331
- eventData = {
332
- stage: "success",
333
- type,
334
- id: res.opModeId,
335
- name: res.unlockName
336
- };
337
- } catch {
338
- eventData = {
339
- stage: "fail",
340
- type,
341
- lockUserId: result.memberId,
342
- error: getError(1053)
343
- };
344
- }
345
- break;
223
+ const type = addUnlockMethodData.unlockMethodConfig.type;
224
+ switch (result.stage) {
225
+ case 0xfc: {
226
+ handleAddTimeout(addUnlockMethodData.timeout);
227
+ eventData = {
228
+ type,
229
+ stage: "step",
230
+ lockUserId: result.memberId,
231
+ step: result.step,
232
+ total: addUnlockMethodData.total,
233
+ };
234
+ break;
235
+ }
236
+ case 0xfd: {
237
+ clearMonitoringAddReport();
238
+ eventData = {
239
+ stage: "fail",
240
+ type,
241
+ lockUserId: result.memberId,
242
+ error: getAddUnlockError(result.status),
243
+ };
244
+ break;
245
+ }
246
+ case 0xfe: {
247
+ clearMonitoringAddReport();
248
+ if (isCancelAddUnlockMethod) {
249
+ isCancelAddUnlockMethod = false;
250
+ return;
251
+ }
252
+ eventData = {
253
+ stage: "fail",
254
+ type,
255
+ lockUserId: result.memberId,
256
+ error: getAddUnlockError(result.status),
257
+ };
258
+ break;
259
+ }
260
+ case 0xff: {
261
+ clearMonitoringAddReport();
262
+ try {
263
+ await sleep(300);
264
+ const res = await createUnlockMethod({
265
+ devId: config.devInfo.devId,
266
+ userId: addUnlockMethodData.userId,
267
+ unlockId: `${addUnlockMethodData.unlockDpId}-${result.unlockId}`,
268
+ unlockName: "",
269
+ unlockAttr: 0,
270
+ });
271
+ eventData = {
272
+ stage: "success",
273
+ type,
274
+ id: res.opModeId,
275
+ name: res.unlockName,
276
+ };
277
+ }
278
+ catch {
279
+ eventData = {
280
+ stage: "fail",
281
+ type,
282
+ lockUserId: result.memberId,
283
+ error: getError(1053),
284
+ };
285
+ }
286
+ break;
287
+ }
288
+ default:
289
+ }
290
+ if (eventData) {
291
+ if (emitter.hasListener(UNLOCK_METHOD_EVENT)) {
292
+ emitter.emit(UNLOCK_METHOD_EVENT, eventData);
293
+ }
294
+ else {
295
+ emitter.cache(UNLOCK_METHOD_EVENT, eventData);
296
+ }
346
297
  }
347
- default:
348
- // 其他状态,则不处理
349
- }
350
- if (eventData) {
351
- if (emitter.hasListener(UNLOCK_METHOD_EVENT)) {
352
- emitter.emit(UNLOCK_METHOD_EVENT, eventData);
353
- } else {
354
- // 由于存在上报录入开始后,紧跟着会上报失败,因此项无监听器时则暂存数据
355
- emitter.cache(UNLOCK_METHOD_EVENT, eventData);
356
- }
357
298
  }
358
- }
359
299
  };
360
300
  const clearMonitoringAddReport = () => {
361
- clearTimeout(addUnlockMethodData.timeoutId);
362
- // 清除监听器
363
- emitter.off(DPCHANGE, handleAddReport);
301
+ clearTimeout(addUnlockMethodData.timeoutId);
302
+ emitter.off(DPCHANGE, handleAddReport);
364
303
  };
365
- const monitoringAddReport = option => {
366
- // 缓存添加开锁方式的数据
367
- Object.assign(addUnlockMethodData, option);
368
- // 先移除之前的监听器,确保不会重复添加
369
- emitter.clearCache(UNLOCK_METHOD_EVENT);
370
- emitter.off(DPCHANGE, handleAddReport);
371
- emitter.on(DPCHANGE, handleAddReport);
372
- // 超时处理
373
- handleAddTimeout(option.timeout);
304
+ const monitoringAddReport = (option) => {
305
+ Object.assign(addUnlockMethodData, option);
306
+ emitter.clearCache(UNLOCK_METHOD_EVENT);
307
+ emitter.off(DPCHANGE, handleAddReport);
308
+ emitter.on(DPCHANGE, handleAddReport);
309
+ handleAddTimeout(option.timeout);
374
310
  };
375
- export const startAddUnlockMethod = async params => {
376
- const {
377
- unlockMethodConfig,
378
- lockUserId,
379
- dpData,
380
- sn,
381
- addDpCode,
382
- addDpMap,
383
- addDpReportMap,
384
- dpId
385
- } = await getUnlockMethodBase(params.type, params.userId);
386
- isCancelAddUnlockMethod = false;
387
- const res = await publishDps({
388
- [addDpCode]: dpUtils.format(dpData, addDpMap)
389
- }, {
390
- checkReport: dpData => {
391
- if (typeof dpData[addDpCode] !== "undefined") {
392
- const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
393
- let hasReport = result.type === unlockMethodConfig.id;
394
- // 是否严格模式
395
- if (config.strictMode) {
396
- hasReport = hasReport && result.memberId === lockUserId && result.sn === sn;
397
- }
398
- if (hasReport) {
399
- if (result.memberId !== lockUserId) {
400
- console.warn(`StartAddUnlockMethod: lockUserId mismatch, expected ${lockUserId}, got ${result.memberId}`);
401
- }
402
- // 由于有些锁对sn 的支持不一样,这里不强制 sn 相等
403
- if (result.sn !== sn) {
404
- console.warn("AddPassword: An invalid sn may have been reported");
405
- }
406
- return result;
407
- }
408
- return false;
409
- }
410
- console.warn("AddPassword: An invalid value may have been reported");
411
- return false;
412
- }
413
- });
414
- if (res.stage === 0) {
415
- // 触发 dp 上报监听
416
- monitoringAddReport({
417
- unlockMethodConfig,
418
- total: res.total,
419
- dpCode: addDpCode,
420
- dpMap: addDpReportMap,
421
- sn,
422
- lockUserId,
423
- userId: params.userId,
424
- unlockDpId: dpId
311
+ export const startAddUnlockMethod = async (params) => {
312
+ const { unlockMethodConfig, lockUserId, dpData, sn, addDpCode, addDpMap, addDpReportMap, dpId, } = await getUnlockMethodBase(params.type, params.userId);
313
+ isCancelAddUnlockMethod = false;
314
+ const res = await publishDps({
315
+ [addDpCode]: dpUtils.format(dpData, addDpMap),
316
+ }, {
317
+ checkReport: (dpData) => {
318
+ if (typeof dpData[addDpCode] !== "undefined") {
319
+ const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
320
+ let hasReport = result.type === unlockMethodConfig.id;
321
+ if (config.strictMode) {
322
+ hasReport =
323
+ hasReport && result.memberId === lockUserId && result.sn === sn;
324
+ }
325
+ if (hasReport) {
326
+ if (result.memberId !== lockUserId) {
327
+ console.warn(`StartAddUnlockMethod: lockUserId mismatch, expected ${lockUserId}, got ${result.memberId}`);
328
+ }
329
+ if (result.sn !== sn) {
330
+ console.warn("AddPassword: An invalid sn may have been reported");
331
+ }
332
+ return result;
333
+ }
334
+ return false;
335
+ }
336
+ console.warn("AddPassword: An invalid value may have been reported");
337
+ return false;
338
+ },
425
339
  });
426
- return {
427
- total: res.total
428
- };
429
- }
430
- if (res.stage === 0xfd) {
431
- // 0xfd 表示添加失败
432
- throw getAddUnlockError(res.status);
433
- }
434
- throw getError(1027);
340
+ if (res.stage === 0) {
341
+ monitoringAddReport({
342
+ unlockMethodConfig,
343
+ total: res.total,
344
+ dpCode: addDpCode,
345
+ dpMap: addDpReportMap,
346
+ sn,
347
+ lockUserId,
348
+ userId: params.userId,
349
+ unlockDpId: dpId,
350
+ });
351
+ return { total: res.total };
352
+ }
353
+ if (res.stage === 0xfd) {
354
+ throw getAddUnlockError(res.status);
355
+ }
356
+ throw getError(1027);
435
357
  };
436
-
437
- /**
438
- * 更新开锁方式
439
- * 仅支持更新开锁方式名称和特殊开锁方式的通知信息
440
- * @param {updateUnlockMethodParams} params 入参
441
- * @returns
442
- */
443
- export const updateUnlockMethod = async params => {
444
- // 获取开锁方式的详细信息
445
- const detail = await getUnlockMethodDetail(params.id);
446
- // 数据验证
447
- const specialInfo = checkSpecial(!!params.isSpecial, params.specialInfo, detail.notifyInfo);
448
- return await editUnlockMethod(_objectSpread({
449
- devId: config.devInfo.devId,
450
- opModeId: params.id,
451
- unlockName: params.name
452
- }, specialInfo));
358
+ export const updateUnlockMethod = async (params) => {
359
+ const detail = await getUnlockMethodDetail(params.id);
360
+ const specialInfo = checkSpecial(!!params.isSpecial, params.specialInfo, detail.notifyInfo);
361
+ return await editUnlockMethod({
362
+ devId: config.devInfo.devId,
363
+ opModeId: params.id,
364
+ unlockName: params.name,
365
+ ...specialInfo,
366
+ });
453
367
  };
454
- // 标记是否主动取消录入
455
368
  let isCancelAddUnlockMethod = false;
456
- /**
457
- * 取消添加开锁方式
458
- * @param {CancelAddUnlockMethodParams} params 入参
459
- * @returns
460
- */
461
- export const cancelAddUnlockMethod = parallelOnly(async params => {
462
- // 获取 dp 数据
463
- const {
464
- dpData,
465
- addDpCode,
466
- addDpMap,
467
- addDpReportMap,
468
- unlockMethodConfig,
469
- lockUserId,
470
- sn
471
- } = await getUnlockMethodBase(params.type, params.userId);
472
- dpData.stage = 0xfe; // 设置 stage 为 0xfe,表示取消添加
473
- isCancelAddUnlockMethod = true;
474
- await publishDps({
475
- [addDpCode]: dpUtils.format(dpData, addDpMap)
476
- }, {
477
- checkReport: dpData => {
478
- if (typeof dpData[addDpCode] !== "undefined") {
479
- const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
480
- let hasReport = result.type === unlockMethodConfig.id;
481
- // 是否严格模式
482
- if (config.strictMode) {
483
- hasReport = hasReport && result.stage === 0xfe && result.memberId === lockUserId && result.sn === sn;
484
- }
485
- if (hasReport) {
486
- return result;
487
- }
488
- console.warn("CancelAddUnlockMethod: An invalid value may have been reported");
489
- }
490
- return false;
491
- }
492
- });
493
- return true;
369
+ export const cancelAddUnlockMethod = parallelOnly(async (params) => {
370
+ const { dpData, addDpCode, addDpMap, addDpReportMap, unlockMethodConfig, lockUserId, sn, } = await getUnlockMethodBase(params.type, params.userId);
371
+ dpData.stage = 0xfe;
372
+ isCancelAddUnlockMethod = true;
373
+ await publishDps({
374
+ [addDpCode]: dpUtils.format(dpData, addDpMap),
375
+ }, {
376
+ checkReport: (dpData) => {
377
+ if (typeof dpData[addDpCode] !== "undefined") {
378
+ const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
379
+ let hasReport = result.type === unlockMethodConfig.id;
380
+ if (config.strictMode) {
381
+ hasReport =
382
+ hasReport &&
383
+ result.stage === 0xfe &&
384
+ result.memberId === lockUserId &&
385
+ result.sn === sn;
386
+ }
387
+ if (hasReport) {
388
+ return result;
389
+ }
390
+ console.warn("CancelAddUnlockMethod: An invalid value may have been reported");
391
+ }
392
+ return false;
393
+ },
394
+ });
395
+ return true;
494
396
  });
495
-
496
- /**
497
- * 删除开锁方式
498
- * @param {number} id 开锁方式 id
499
- */
500
- export const deleteUnlockMethod = parallelOnly(async id => {
501
- const {
502
- lockUserId,
503
- unlockId,
504
- userType,
505
- dpId
506
- } = await getUnlockMethodDetail(id);
507
- const dpCode = config.codesById[dpId];
508
- const unlockMethodConfig = getUnlockMethodTypeByDpCode(dpCode);
509
- // 获取对应的 dp
510
- const removeDPCode = config.supportBigData ? dpCodes.unlockMethodDelW : dpCodes.unlockMethodDel;
511
- if (!config.dpSchema[removeDPCode]) {
512
- throw getError(1014);
513
- }
514
- const dpData = {
515
- type: unlockMethodConfig.id,
516
- stage: 0,
517
- admin: isAdmin(userType),
518
- memberId: lockUserId,
519
- unlockId,
520
- target: 1
521
- };
522
- const res = await publishDps({
523
- [removeDPCode]: dpUtils.format(dpData, config.supportBigData ? removeBigMap : removeMap)
524
- }, {
525
- checkReport: dpData => {
526
- if (typeof dpData[removeDPCode] !== "undefined") {
527
- const result = dpUtils.parse(dpData[removeDPCode], config.supportBigData ? reportRemoveBigMap : reportRemoveMap);
528
- let hasReport = result.type === unlockMethodConfig.id;
529
- // 是否严格模式
530
- if (config.strictMode) {
531
- hasReport = hasReport && result.stage === 0 && result.memberId === lockUserId && result.unlockId === unlockId;
532
- }
533
- if (hasReport) {
534
- if (result.unlockId !== unlockId) {
535
- console.warn(`RemoveUnlockMethod: unlockId mismatch, expected ${unlockId}, got ${result.unlockId}`);
536
- }
537
- return result;
538
- }
539
- console.warn("RemoveUnlockMethod: An invalid value may have been reported");
540
- }
541
- return false;
397
+ export const deleteUnlockMethod = parallelOnly(async (id) => {
398
+ const { lockUserId, unlockId, userType, dpId } = await getUnlockMethodDetail(id);
399
+ const dpCode = config.codesById[dpId];
400
+ const unlockMethodConfig = getUnlockMethodTypeByDpCode(dpCode);
401
+ const removeDPCode = config.supportBigData
402
+ ? dpCodes.unlockMethodDelW
403
+ : dpCodes.unlockMethodDel;
404
+ if (!config.dpSchema[removeDPCode]) {
405
+ throw getError(1014);
542
406
  }
543
- });
544
- if (res.status !== 255 && res.status !== 1) {
545
- switch (res.status) {
546
- case 2:
547
- throw getError(1029);
548
- case 0:
549
- default:
550
- throw getError(1028);
407
+ const dpData = {
408
+ type: unlockMethodConfig.id,
409
+ stage: 0,
410
+ admin: isAdmin(userType),
411
+ memberId: lockUserId,
412
+ unlockId,
413
+ target: 1,
414
+ };
415
+ const res = await publishDps({
416
+ [removeDPCode]: dpUtils.format(dpData, (config.supportBigData ? removeBigMap : removeMap)),
417
+ }, {
418
+ checkReport: (dpData) => {
419
+ if (typeof dpData[removeDPCode] !== "undefined") {
420
+ const result = dpUtils.parse(dpData[removeDPCode], (config.supportBigData
421
+ ? reportRemoveBigMap
422
+ : reportRemoveMap));
423
+ let hasReport = result.type === unlockMethodConfig.id;
424
+ if (config.strictMode) {
425
+ hasReport =
426
+ hasReport &&
427
+ result.stage === 0 &&
428
+ result.memberId === lockUserId &&
429
+ result.unlockId === unlockId;
430
+ }
431
+ if (hasReport) {
432
+ if (result.unlockId !== unlockId) {
433
+ console.warn(`RemoveUnlockMethod: unlockId mismatch, expected ${unlockId}, got ${result.unlockId}`);
434
+ }
435
+ return result;
436
+ }
437
+ console.warn("RemoveUnlockMethod: An invalid value may have been reported");
438
+ }
439
+ return false;
440
+ },
441
+ });
442
+ if (res.status !== 255 && res.status !== 1) {
443
+ switch (res.status) {
444
+ case 2:
445
+ throw getError(1029);
446
+ case 0:
447
+ default:
448
+ throw getError(1028);
449
+ }
551
450
  }
552
- }
553
- await removeUnlockMethod({
554
- devId: config.devInfo.devId,
555
- opmodeId: id
556
- });
451
+ await removeUnlockMethod({
452
+ devId: config.devInfo.devId,
453
+ opmodeId: id,
454
+ });
557
455
  });
558
-
559
- /**
560
- * 检测是否有未绑定的开锁方式
561
- * @returns
562
- */
563
456
  export const checkUnBindUnlockMethods = async () => {
564
- const data = await checkFreeUnlockMethods({
565
- devId: config.devInfo.devId
566
- });
567
- // 由于atop 返回的值,双端不一致,这里处理下
568
- return data === true || data === 1;
457
+ const data = await checkFreeUnlockMethods({
458
+ devId: config.devInfo.devId,
459
+ });
460
+ return data === true || data === 1;
569
461
  };
570
-
571
- /**
572
- * 获取未关联开锁方式列表
573
- */
574
462
  export const getUnbindUnlockMethods = async () => {
575
- const cloudData = await fetchFreeUnlockMethods({
576
- devId: config.devInfo.devId
577
- });
578
-
579
- // 转化数据
580
- const list = cloudData.map(item => {
581
- const unlockMethodConfig = getUnlockMethodTypeByDpCode(item.standardDp);
582
- return {
583
- type: unlockMethodConfig.type,
584
- list: item.unlockInfo.map(unlock => {
463
+ const cloudData = await fetchFreeUnlockMethods({
464
+ devId: config.devInfo.devId,
465
+ });
466
+ const list = cloudData.map((item) => {
467
+ const unlockMethodConfig = getUnlockMethodTypeByDpCode(item.standardDp);
585
468
  return {
586
- unlockId: Number(unlock.unlockId.split("-")[1]),
587
- unlockName: unlock.unlockName,
588
- id: unlock.opmodeId,
589
- unlockSn: unlock.unlockSn,
590
- type: unlockMethodConfig.type,
591
- dpId: Number(item.opmode),
592
- dpCode: item.standardDp
469
+ type: unlockMethodConfig.type,
470
+ list: item.unlockInfo.map((unlock) => {
471
+ return {
472
+ unlockId: Number(unlock.unlockId.split("-")[1]),
473
+ unlockName: unlock.unlockName,
474
+ id: unlock.opmodeId,
475
+ unlockSn: unlock.unlockSn,
476
+ type: unlockMethodConfig.type,
477
+ dpId: Number(item.opmode),
478
+ dpCode: item.standardDp,
479
+ };
480
+ }),
593
481
  };
594
- })
595
- };
596
- });
597
- return list;
482
+ });
483
+ return list;
598
484
  };
599
-
600
- /**
601
- * 绑定未关联开锁方式到用户入参
602
- */
603
-
604
- /**
605
- * 绑定未关联开锁方式到用户
606
- * @param params
607
- * @returns
608
- */
609
- export const bindUnlockMethod = params => {
610
- const unlockIds = params.unlockList.map(item => {
611
- const unlockMethodConfig = getUnlockMethodTypeByType(item.type);
612
- const dpId = config.idsByCode[unlockMethodConfig.code];
613
- return `${dpId}-${item.unlockId}`;
614
- });
615
- return bindUnlockMethodToUser({
616
- devId: config.devInfo.devId,
617
- userId: params.userId,
618
- unlockIds: unlockIds
619
- });
485
+ export const bindUnlockMethod = (params) => {
486
+ const unlockIds = params.unlockList.map((item) => {
487
+ const unlockMethodConfig = getUnlockMethodTypeByType(item.type);
488
+ const dpId = config.idsByCode[unlockMethodConfig.code];
489
+ return `${dpId}-${item.unlockId}`;
490
+ });
491
+ return bindUnlockMethodToUser({
492
+ devId: config.devInfo.devId,
493
+ userId: params.userId,
494
+ unlockIds: unlockIds,
495
+ });
620
496
  };
621
-
622
- /**
623
- * 解绑用户的开锁方式
624
- * @param {number} id 开锁方式 id
625
- * @returns
626
- */
627
- export const unbindUnlockMethod = async id => {
628
- const detail = await getUnlockMethodDetail(id);
629
- if (!detail.isBound) {
630
- throw getError(1050);
631
- }
632
- return unbindMemberUnlockMethod({
633
- devId: config.devInfo.devId,
634
- userId: detail.userId,
635
- unlockIds: [`${detail.dpId}-${detail.unlockId}`]
636
- });
497
+ export const unbindUnlockMethod = async (id) => {
498
+ const detail = await getUnlockMethodDetail(id);
499
+ if (!detail.isBound) {
500
+ throw getError(1050);
501
+ }
502
+ return unbindMemberUnlockMethod({
503
+ devId: config.devInfo.devId,
504
+ userId: detail.userId,
505
+ unlockIds: [`${detail.dpId}-${detail.unlockId}`],
506
+ });
637
507
  };
638
- /**
639
- * 绑定开门记录中未关联开锁方式到用户
640
- * @param {UnbindUnlockMethodParams} params
641
- * @returns
642
- */
643
- export const bindUnlockMethodFromLog = params => {
644
- const {
645
- idsByCode
646
- } = config;
647
- const unlockIds = params.unlockList.map(item => {
648
- const unlockMethodConfig = getUnlockMethodTypeByType(item.type);
649
- const dpId = idsByCode[unlockMethodConfig.code];
650
- return `${dpId}-${item.unlockId}`;
651
- });
652
- return bindUnlockMethodToUserByRecord({
653
- devId: config.devInfo.devId,
654
- userId: params.userId,
655
- unlockIds: unlockIds
656
- });
508
+ export const bindUnlockMethodFromLog = (params) => {
509
+ const { idsByCode } = config;
510
+ const unlockIds = params.unlockList.map((item) => {
511
+ const unlockMethodConfig = getUnlockMethodTypeByType(item.type);
512
+ const dpId = idsByCode[unlockMethodConfig.code];
513
+ return `${dpId}-${item.unlockId}`;
514
+ });
515
+ return bindUnlockMethodToUserByRecord({
516
+ devId: config.devInfo.devId,
517
+ userId: params.userId,
518
+ unlockIds: unlockIds,
519
+ });
520
+ };
521
+ export const sendVerifyCode = (params) => {
522
+ return sendPhoneVerifyCode({
523
+ ...params,
524
+ devId: config.devInfo.devId,
525
+ });
657
526
  };
658
- /**
659
- *
660
- * @param params
661
- * @returns
662
- */
663
- export const sendVerifyCode = params => {
664
- return sendPhoneVerifyCode(_objectSpread(_objectSpread({}, params), {}, {
665
- devId: config.devInfo.devId
666
- }));
527
+ export const onAddUnlockMethod = (listener) => {
528
+ emitter.on(UNLOCK_METHOD_EVENT, listener);
667
529
  };
668
-
669
- /**
670
- * 添加开锁方式步骤事件类型
671
- */
672
-
673
- /**
674
- * 添加开锁方式成员事件类型
675
- */
676
-
677
- /**
678
- * 添加开锁方式错误事件类型
679
- */
680
-
681
- /**
682
- * 添加开锁方式监听器事件类型
683
- */
684
-
685
- /**
686
- * 添加开锁方式步骤监听器类型
687
- */
688
-
689
- /**
690
- * 注册开锁方式步骤监听器
691
- * @param {AddUnlockMethodListener} listener 监听器
692
- */
693
- export const onAddUnlockMethod = listener => {
694
- emitter.on(UNLOCK_METHOD_EVENT, listener);
530
+ export const offAddUnlockMethod = (listener) => {
531
+ emitter.off(UNLOCK_METHOD_EVENT, listener);
695
532
  };
696
-
697
- /**
698
- * 注销开锁方式步骤监听器
699
- * @param {AddUnlockMethodListener} listener 监听器
700
- */
701
- export const offAddUnlockMethod = listener => {
702
- emitter.off(UNLOCK_METHOD_EVENT, listener);
703
- };