@ray-js/lock-sdk 1.0.1 → 1.0.3-beta-1
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.
- package/lib/api/index.js +13 -15
- package/lib/api/linkage.d.ts +0 -18
- package/lib/api/linkage.js +61 -81
- package/lib/api/lock.d.ts +0 -69
- package/lib/api/lock.js +91 -113
- package/lib/api/log.d.ts +0 -33
- package/lib/api/log.js +33 -38
- package/lib/api/setting.d.ts +0 -11
- package/lib/api/setting.js +17 -30
- package/lib/api/temp.d.ts +0 -48
- package/lib/api/temp.js +85 -115
- package/lib/api/user.d.ts +5 -54
- package/lib/api/user.js +40 -52
- package/lib/api/video.d.ts +0 -5
- package/lib/api/video.js +9 -15
- package/lib/config/dp-code/index.d.ts +0 -117
- package/lib/config/dp-code/index.js +79 -221
- package/lib/config/dp-map/common.d.ts +0 -3
- package/lib/config/dp-map/common.js +101 -116
- package/lib/config/dp-map/normal.js +29 -50
- package/lib/config/dp-map/open.d.ts +0 -16
- package/lib/config/dp-map/open.js +62 -63
- package/lib/config/dp-map/unlock-method-big.d.ts +0 -60
- package/lib/config/dp-map/unlock-method-big.js +196 -233
- package/lib/config/dp-map/unlock-method.d.ts +0 -63
- package/lib/config/dp-map/unlock-method.js +189 -227
- package/lib/config/index.d.ts +0 -25
- package/lib/config/index.js +21 -54
- package/lib/constant.d.ts +12 -40
- package/lib/constant.js +83 -136
- package/lib/event.d.ts +0 -6
- package/lib/event.js +1 -8
- package/lib/index.d.ts +0 -7
- package/lib/index.js +45 -71
- package/lib/interface.d.ts +0 -523
- package/lib/interface.js +1 -1
- package/lib/linkage.d.ts +0 -18
- package/lib/linkage.js +125 -162
- package/lib/log.d.ts +0 -50
- package/lib/log.js +255 -290
- package/lib/media.d.ts +0 -34
- package/lib/media.js +6 -77
- package/lib/open.d.ts +0 -35
- package/lib/open.js +129 -224
- package/lib/other.d.ts +8 -26
- package/lib/other.js +107 -159
- package/lib/parse/index.d.ts +0 -4
- package/lib/parse/index.js +13 -19
- package/lib/signal.d.ts +0 -13
- package/lib/signal.js +17 -31
- package/lib/sleep.d.ts +0 -42
- package/lib/sleep.js +41 -98
- package/lib/state.d.ts +0 -38
- package/lib/state.js +223 -369
- package/lib/sync/remote-serect-key.d.ts +0 -4
- package/lib/sync/remote-serect-key.js +33 -49
- package/lib/sync/t0.d.ts +0 -3
- package/lib/sync/t0.js +14 -21
- package/lib/sync/temp.d.ts +0 -5
- package/lib/sync/temp.js +68 -77
- package/lib/sync/unlock-mothod.d.ts +0 -3
- package/lib/sync/unlock-mothod.js +28 -40
- package/lib/temporary.d.ts +0 -149
- package/lib/temporary.js +469 -593
- package/lib/unlock-method.d.ts +0 -185
- package/lib/unlock-method.js +479 -650
- package/lib/user.d.ts +2 -81
- package/lib/user.js +202 -336
- package/lib/utils/base64-to-hex.js +10 -10
- package/lib/utils/byte.d.ts +0 -16
- package/lib/utils/byte.js +57 -68
- package/lib/utils/constant.js +7 -11
- package/lib/utils/device.d.ts +46 -83
- package/lib/utils/device.js +294 -322
- package/lib/utils/errors.js +75 -122
- package/lib/utils/event.js +79 -135
- package/lib/utils/hex-to-base64.js +5 -5
- package/lib/utils/hex-to-bytes.d.ts +0 -5
- package/lib/utils/hex-to-bytes.js +10 -15
- package/lib/utils/index.d.ts +0 -42
- package/lib/utils/index.js +247 -377
- package/lib/utils/log.d.ts +1 -4
- package/lib/utils/log.js +71 -74
- package/lib/utils/publishDps.d.ts +0 -5
- package/lib/utils/publishDps.js +58 -80
- package/package.json +3 -4
package/lib/utils/index.js
CHANGED
|
@@ -1,419 +1,289 @@
|
|
|
1
|
-
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
-
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
|
-
import "core-js/modules/esnext.iterator.map.js";
|
|
4
1
|
import config from "../config";
|
|
5
2
|
import dpCodes from "../config/dp-code";
|
|
6
|
-
import { ProductCommunicationType } from "../constant";
|
|
3
|
+
import { ProductCommunicationType, } from "../constant";
|
|
7
4
|
import { LoopTypes } from "./constant";
|
|
8
|
-
import { getBackgroundFetchData, getCurrentHomeInfo, onBackgroundFetchData } from "./device";
|
|
5
|
+
import { getBackgroundFetchData, getCurrentHomeInfo, onBackgroundFetchData, } from "./device";
|
|
9
6
|
import { getError } from "./errors";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export const get24Time = time => {
|
|
17
|
-
const hours = Math.floor(time / 60);
|
|
18
|
-
return [hours, time % 60];
|
|
7
|
+
export const get24Time = (time) => {
|
|
8
|
+
const hours = Math.floor(time / 60);
|
|
9
|
+
const minutes = time % 60;
|
|
10
|
+
return [hours, minutes];
|
|
19
11
|
};
|
|
20
12
|
export const getNowTime = () => {
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
const now = new Date();
|
|
14
|
+
return now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
|
|
23
15
|
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 判断设备在线类型
|
|
27
|
-
* @param onlineType 设备的通道在线数据
|
|
28
|
-
* @param type 待检测的通道类型,0为wifi,1为局域网,2为蓝牙,3为Mesh, 4为 beacon
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
16
|
export const isOnlineByType = (onlineType, type) => {
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
const base = 2 ** type;
|
|
18
|
+
return (onlineType & base) >> type === 1;
|
|
34
19
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}, {
|
|
58
|
-
id: 11,
|
|
59
|
-
name: "blemesh",
|
|
60
|
-
short: "bm"
|
|
61
|
-
}, {
|
|
62
|
-
id: 12,
|
|
63
|
-
name: "zigbee",
|
|
64
|
-
short: "zig"
|
|
65
|
-
}, {
|
|
66
|
-
id: 13,
|
|
67
|
-
name: "infrared",
|
|
68
|
-
short: "inf"
|
|
69
|
-
}, {
|
|
70
|
-
id: 14,
|
|
71
|
-
name: "subpieces",
|
|
72
|
-
short: "sub"
|
|
73
|
-
}, {
|
|
74
|
-
id: 15,
|
|
75
|
-
name: "sigmesh",
|
|
76
|
-
short: "sig"
|
|
77
|
-
}, {
|
|
78
|
-
id: 16,
|
|
79
|
-
name: "mcu",
|
|
80
|
-
short: "mcu"
|
|
81
|
-
}, {
|
|
82
|
-
id: 17,
|
|
83
|
-
name: "ty_smesh",
|
|
84
|
-
short: "TY_SMESH"
|
|
85
|
-
}, {
|
|
86
|
-
id: 18,
|
|
87
|
-
name: "Zwave",
|
|
88
|
-
short: "Zwave"
|
|
89
|
-
}, {
|
|
90
|
-
id: 19,
|
|
91
|
-
name: "pl-mesh",
|
|
92
|
-
short: "pl-mesh"
|
|
93
|
-
}, {
|
|
94
|
-
id: 20,
|
|
95
|
-
name: "cat1",
|
|
96
|
-
short: "cat1"
|
|
97
|
-
}, {
|
|
98
|
-
id: 21,
|
|
99
|
-
name: "beacon",
|
|
100
|
-
short: "beacon"
|
|
101
|
-
}, {
|
|
102
|
-
id: 22,
|
|
103
|
-
name: "cat4",
|
|
104
|
-
short: "cat4"
|
|
105
|
-
}, {
|
|
106
|
-
id: 23,
|
|
107
|
-
name: "cat10",
|
|
108
|
-
short: "cat10"
|
|
109
|
-
}, {
|
|
110
|
-
id: 24,
|
|
111
|
-
name: "lte-catm",
|
|
112
|
-
short: "catm"
|
|
113
|
-
}, {
|
|
114
|
-
id: 25,
|
|
115
|
-
name: "thread",
|
|
116
|
-
short: "thread"
|
|
117
|
-
}];
|
|
20
|
+
const supportCapabilities = [
|
|
21
|
+
{ id: 0, name: "wifi", short: "wf" },
|
|
22
|
+
{ id: 1, name: "cable", short: "ca" },
|
|
23
|
+
{ id: 2, name: "gprs", short: "gp" },
|
|
24
|
+
{ id: 3, name: "nb-iot", short: "nb" },
|
|
25
|
+
{ id: 10, name: "bluetooth", short: "ble" },
|
|
26
|
+
{ id: 11, name: "blemesh", short: "bm" },
|
|
27
|
+
{ id: 12, name: "zigbee", short: "zig" },
|
|
28
|
+
{ id: 13, name: "infrared", short: "inf" },
|
|
29
|
+
{ id: 14, name: "subpieces", short: "sub" },
|
|
30
|
+
{ id: 15, name: "sigmesh", short: "sig" },
|
|
31
|
+
{ id: 16, name: "mcu", short: "mcu" },
|
|
32
|
+
{ id: 17, name: "ty_smesh", short: "TY_SMESH" },
|
|
33
|
+
{ id: 18, name: "Zwave", short: "Zwave" },
|
|
34
|
+
{ id: 19, name: "pl-mesh", short: "pl-mesh" },
|
|
35
|
+
{ id: 20, name: "cat1", short: "cat1" },
|
|
36
|
+
{ id: 21, name: "beacon", short: "beacon" },
|
|
37
|
+
{ id: 22, name: "cat4", short: "cat4" },
|
|
38
|
+
{ id: 23, name: "cat10", short: "cat10" },
|
|
39
|
+
{ id: 24, name: "lte-catm", short: "catm" },
|
|
40
|
+
{ id: 25, name: "thread", short: "thread" },
|
|
41
|
+
];
|
|
118
42
|
export function isCapability(capability, id) {
|
|
119
|
-
|
|
120
|
-
|
|
43
|
+
const redId = 1 << id;
|
|
44
|
+
return (capability & redId) === redId;
|
|
121
45
|
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 获取产品支持的通讯能力
|
|
125
|
-
* @param capability 产品能力值
|
|
126
|
-
* @returns
|
|
127
|
-
*/
|
|
128
46
|
export function getCapabilities(capability) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
47
|
+
return supportCapabilities.filter((item) => {
|
|
48
|
+
return isCapability(capability, item.id);
|
|
49
|
+
});
|
|
132
50
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
export const formatWeek = value => {
|
|
136
|
-
return parseInt([...value].reverse().join(""), 2);
|
|
51
|
+
export const formatWeek = (value) => {
|
|
52
|
+
return parseInt([...value].reverse().join(""), 2);
|
|
137
53
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
54
|
+
export const parseWeek = (value) => {
|
|
55
|
+
return Number(value)
|
|
56
|
+
.toString(2)
|
|
57
|
+
.padStart(7, "0")
|
|
58
|
+
.split("")
|
|
59
|
+
.reverse()
|
|
60
|
+
.map(Number)
|
|
61
|
+
.slice(0, 7);
|
|
142
62
|
};
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* 获取一个永久生效的设置
|
|
146
|
-
* @returns
|
|
147
|
-
*/
|
|
148
63
|
export const getPermanentSetting = () => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
};
|
|
64
|
+
const now = Math.floor(+new Date() / 1000);
|
|
65
|
+
return {
|
|
66
|
+
startTime: now,
|
|
67
|
+
endTime: now + 3153600000,
|
|
68
|
+
loop: LoopTypes.NONE,
|
|
69
|
+
loopConfig: 0,
|
|
70
|
+
weeks: [0, 0, 0, 0, 0, 0, 0],
|
|
71
|
+
days: [],
|
|
72
|
+
startHour: 0,
|
|
73
|
+
startMinute: 0,
|
|
74
|
+
endHour: 0,
|
|
75
|
+
endMinute: 0,
|
|
76
|
+
};
|
|
163
77
|
};
|
|
164
|
-
export const isAdmin = userType => userType === 10 || userType === 50 ? true : false;
|
|
165
|
-
export const validateEffectiveConfig = effective => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
break;
|
|
186
|
-
// case "month":
|
|
187
|
-
// if (!effective.days) {
|
|
188
|
-
// throw getError(1036);
|
|
189
|
-
// }
|
|
190
|
-
// break;
|
|
191
|
-
// default:
|
|
192
|
-
}
|
|
78
|
+
export const isAdmin = (userType) => userType === 10 || userType === 50 ? true : false;
|
|
79
|
+
export const validateEffectiveConfig = (effective) => {
|
|
80
|
+
if (!effective) {
|
|
81
|
+
throw getError(1032);
|
|
82
|
+
}
|
|
83
|
+
if (!effective.effectiveDate) {
|
|
84
|
+
throw getError(1033);
|
|
85
|
+
}
|
|
86
|
+
if (!effective.expiredDate) {
|
|
87
|
+
throw getError(1034);
|
|
88
|
+
}
|
|
89
|
+
if (+effective.effectiveDate > +effective.expiredDate) {
|
|
90
|
+
throw getError(1010);
|
|
91
|
+
}
|
|
92
|
+
switch (effective.repeat) {
|
|
93
|
+
case "week":
|
|
94
|
+
if (!effective.weeks) {
|
|
95
|
+
throw getError(1035);
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
193
99
|
};
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* 是否使用近场通道,一般为蓝牙
|
|
197
|
-
* @returns
|
|
198
|
-
*/
|
|
199
100
|
export const isUseNearChannel = () => {
|
|
200
|
-
|
|
201
|
-
onlineType,
|
|
202
|
-
|
|
203
|
-
communication
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
101
|
+
const { onlineType, devInfo, communication } = config;
|
|
102
|
+
const isBleOnline = isOnlineByType(onlineType, 2);
|
|
103
|
+
const isSupportWifi = communication.includes(ProductCommunicationType.WIFI);
|
|
104
|
+
const isSupportBle = communication.includes(ProductCommunicationType.BLUETOOTH);
|
|
105
|
+
const isSupportThread = communication.includes(ProductCommunicationType.THREAD);
|
|
106
|
+
if (isSupportWifi && isSupportBle) {
|
|
107
|
+
return isBleOnline;
|
|
108
|
+
}
|
|
109
|
+
if (isSupportThread && isSupportBle) {
|
|
110
|
+
return isBleOnline && !devInfo.isCloudOnline && !devInfo.isLocalOnline;
|
|
111
|
+
}
|
|
211
112
|
return isBleOnline;
|
|
212
|
-
}
|
|
213
|
-
// thread + ble 双模
|
|
214
|
-
if (isSupportThread && isSupportBle) {
|
|
215
|
-
return isBleOnline && !devInfo.isCloudOnline && !devInfo.isLocalOnline;
|
|
216
|
-
}
|
|
217
|
-
return isBleOnline;
|
|
218
113
|
};
|
|
219
|
-
export const parseOfflinePassword = value => {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return digitalCode;
|
|
114
|
+
export const parseOfflinePassword = (value) => {
|
|
115
|
+
if (config.passwordDigitalBase === 10) {
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
let digitalCode = Number(value).toString(config.passwordDigitalBase);
|
|
119
|
+
const zeroList = value.match(/(^0+)/);
|
|
120
|
+
if (zeroList) {
|
|
121
|
+
digitalCode = zeroList[0] + digitalCode;
|
|
122
|
+
}
|
|
123
|
+
if (config.passwordSupportZero === false) {
|
|
124
|
+
digitalCode = digitalCode
|
|
125
|
+
.split("")
|
|
126
|
+
.map((n) => {
|
|
127
|
+
return Number(n) + 1;
|
|
128
|
+
})
|
|
129
|
+
.join("");
|
|
130
|
+
}
|
|
131
|
+
return digitalCode;
|
|
238
132
|
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
*
|
|
242
|
-
* 注意此方法只支持 2010 年之后的时间戳
|
|
243
|
-
* @param timestamp 时间戳
|
|
244
|
-
*/
|
|
245
|
-
export const formatTimestampToMilliseconds = timestamp => {
|
|
246
|
-
const isMilliseconds = timestamp.toString().length >= 13;
|
|
247
|
-
return isMilliseconds ? timestamp : timestamp * 1000;
|
|
133
|
+
export const formatTimestampToMilliseconds = (timestamp) => {
|
|
134
|
+
const isMilliseconds = timestamp.toString().length >= 13;
|
|
135
|
+
return isMilliseconds ? timestamp : timestamp * 1000;
|
|
248
136
|
};
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
},
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
137
|
+
export const unlockMethodConfigs = [
|
|
138
|
+
{
|
|
139
|
+
type: "password",
|
|
140
|
+
code: dpCodes.unlockPassword,
|
|
141
|
+
id: 1,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: "card",
|
|
145
|
+
code: dpCodes.unlockCard,
|
|
146
|
+
id: 2,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: "finger",
|
|
150
|
+
code: dpCodes.unlockFingerprint,
|
|
151
|
+
id: 3,
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
type: "face",
|
|
155
|
+
code: dpCodes.unlockFace,
|
|
156
|
+
id: 4,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: "hand",
|
|
160
|
+
code: dpCodes.unlockHand,
|
|
161
|
+
id: 5,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: "fingerVein",
|
|
165
|
+
code: dpCodes.unlockFingerVein,
|
|
166
|
+
id: 6,
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
const getUnlockMethodType = (cb) => {
|
|
170
|
+
const result = unlockMethodConfigs.find(cb);
|
|
171
|
+
if (result && config.dpSchema[result.code]) {
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
throw getError(1014);
|
|
285
175
|
};
|
|
286
|
-
export const getUnlockMethodTypeByDpCode = dpCode => {
|
|
287
|
-
|
|
176
|
+
export const getUnlockMethodTypeByDpCode = (dpCode) => {
|
|
177
|
+
return getUnlockMethodType((item) => item.code === dpCode);
|
|
288
178
|
};
|
|
289
|
-
export const getUnlockMethodTypeById = id => {
|
|
290
|
-
|
|
179
|
+
export const getUnlockMethodTypeById = (id) => {
|
|
180
|
+
return getUnlockMethodType((item) => item.id === id);
|
|
291
181
|
};
|
|
292
|
-
export const getUnlockMethodTypeByType = type => {
|
|
293
|
-
|
|
182
|
+
export const getUnlockMethodTypeByType = (type) => {
|
|
183
|
+
return getUnlockMethodType((item) => item.type === type);
|
|
294
184
|
};
|
|
295
185
|
let cbIndex = 0;
|
|
296
186
|
const cbMap = {};
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
return result;
|
|
340
|
-
} catch (error) {
|
|
341
|
-
isRuning = false;
|
|
342
|
-
// 如果是 merge 模式,执行所有暂存的回调
|
|
343
|
-
if (cbMap[cbId] && cbMap[cbId][key]) {
|
|
344
|
-
let list = cbMap[cbId][key];
|
|
345
|
-
delete cbMap[cbId][key]; // 删除已处理的回调
|
|
346
|
-
setTimeout(() => {
|
|
347
|
-
list.forEach(item => item.reject(error));
|
|
348
|
-
}, 0);
|
|
349
|
-
}
|
|
350
|
-
throw error;
|
|
351
|
-
}
|
|
352
|
-
};
|
|
187
|
+
export const parallelMerge = (cb) => {
|
|
188
|
+
let isRuning = false;
|
|
189
|
+
let cbId = cbIndex++;
|
|
190
|
+
return async (...args) => {
|
|
191
|
+
const key = JSON.stringify(args);
|
|
192
|
+
if (isRuning) {
|
|
193
|
+
if (!cbMap[cbId]) {
|
|
194
|
+
cbMap[cbId] = {};
|
|
195
|
+
}
|
|
196
|
+
if (!cbMap[cbId][key]) {
|
|
197
|
+
cbMap[cbId][key] = [];
|
|
198
|
+
}
|
|
199
|
+
return new Promise((resolve, reject) => {
|
|
200
|
+
cbMap[cbId][key].push({ resolve, reject });
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
isRuning = true;
|
|
204
|
+
try {
|
|
205
|
+
const result = await cb(...args);
|
|
206
|
+
isRuning = false;
|
|
207
|
+
if (cbMap[cbId] && cbMap[cbId][key]) {
|
|
208
|
+
let list = cbMap[cbId][key];
|
|
209
|
+
delete cbMap[cbId][key];
|
|
210
|
+
setTimeout(() => {
|
|
211
|
+
list.forEach((item) => item.resolve(result));
|
|
212
|
+
}, 0);
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
isRuning = false;
|
|
218
|
+
if (cbMap[cbId] && cbMap[cbId][key]) {
|
|
219
|
+
let list = cbMap[cbId][key];
|
|
220
|
+
delete cbMap[cbId][key];
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
list.forEach((item) => item.reject(error));
|
|
223
|
+
}, 0);
|
|
224
|
+
}
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
353
228
|
};
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
} catch (error) {
|
|
374
|
-
isRuning = false;
|
|
375
|
-
throw error;
|
|
376
|
-
}
|
|
377
|
-
};
|
|
229
|
+
export const parallelOnly = (cb) => {
|
|
230
|
+
let isRuning = false;
|
|
231
|
+
let cbId = cbIndex++;
|
|
232
|
+
return async (...args) => {
|
|
233
|
+
let key;
|
|
234
|
+
if (isRuning) {
|
|
235
|
+
throw getError(1052);
|
|
236
|
+
}
|
|
237
|
+
isRuning = true;
|
|
238
|
+
try {
|
|
239
|
+
const result = await cb(...args);
|
|
240
|
+
isRuning = false;
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
isRuning = false;
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
378
248
|
};
|
|
379
|
-
const preFetchKeys = [
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
249
|
+
const preFetchKeys = [
|
|
250
|
+
"getRotate",
|
|
251
|
+
"getCurrentUser",
|
|
252
|
+
"getDeviceProperties",
|
|
253
|
+
];
|
|
383
254
|
const preFetchData = {};
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
preFetchData[key] = res.fetchedData[key].fetchedData;
|
|
389
|
-
});
|
|
255
|
+
onBackgroundFetchData(preFetchKeys, (res) => {
|
|
256
|
+
Object.keys(res?.fetchedData ?? {}).forEach((key) => {
|
|
257
|
+
preFetchData[key] = res.fetchedData[key].fetchedData;
|
|
258
|
+
});
|
|
390
259
|
});
|
|
391
260
|
export const getDataWithPreFetch = async (key, apiCb) => {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
try {
|
|
396
|
-
const result = await getBackgroundFetchData([key]);
|
|
397
|
-
if (result && result.fetchedData[key] && result.fetchedData[key].fetchedData) {
|
|
398
|
-
// 有数据时,则返回数据,无数据则执行接口调用
|
|
399
|
-
return result.fetchedData[key].fetchedData;
|
|
261
|
+
if (preFetchData[key]) {
|
|
262
|
+
return preFetchData[key];
|
|
400
263
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
264
|
+
try {
|
|
265
|
+
const result = await getBackgroundFetchData([key]);
|
|
266
|
+
if (result &&
|
|
267
|
+
result.fetchedData[key] &&
|
|
268
|
+
result.fetchedData[key].fetchedData) {
|
|
269
|
+
return result.fetchedData[key].fetchedData;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
}
|
|
274
|
+
return apiCb();
|
|
405
275
|
};
|
|
406
276
|
export const equels = (source, target) => {
|
|
407
|
-
|
|
277
|
+
return JSON.stringify(source) === JSON.stringify(target);
|
|
408
278
|
};
|
|
409
|
-
export const sleep = ms => {
|
|
410
|
-
|
|
279
|
+
export const sleep = (ms) => {
|
|
280
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
411
281
|
};
|
|
412
282
|
let homeInfo = null;
|
|
413
283
|
export const getHomeInfo = async () => {
|
|
414
|
-
|
|
284
|
+
if (homeInfo) {
|
|
285
|
+
return homeInfo;
|
|
286
|
+
}
|
|
287
|
+
homeInfo = await getCurrentHomeInfo();
|
|
415
288
|
return homeInfo;
|
|
416
|
-
|
|
417
|
-
homeInfo = await getCurrentHomeInfo();
|
|
418
|
-
return homeInfo;
|
|
419
|
-
};
|
|
289
|
+
};
|
package/lib/utils/log.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 处理日志数据
|
|
3
|
-
*/
|
|
4
1
|
import { LocalOperateData, LocalOperateRecordInfo } from "../interface";
|
|
5
|
-
export declare const handleLocalOperation: (log?: LocalOperateRecordInfo) => LocalOperateData | undefined;
|
|
2
|
+
export declare const handleLocalOperation: (log?: LocalOperateRecordInfo, dpValue?: string) => LocalOperateData | undefined;
|