@zat-design/sisyphus-react 4.0.11 → 4.0.12
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/es/ProEnum/hooks/useEnum.js +58 -12
- package/es/ProEnum/hooks/useEnumRequest.js +167 -70
- package/es/ProEnum/hooks/useFrequentEnumRequest.d.ts +1 -1
- package/es/ProEnum/hooks/useFrequentEnumRequest.js +8 -4
- package/es/ProEnum/propsType.d.ts +1 -1
- package/es/ProEnum/utils/frequentEnum.d.ts +2 -2
- package/es/ProEnum/utils/frequentEnum.js +65 -2
- package/es/ProEnum/utils/index.d.ts +11 -5
- package/es/ProEnum/utils/index.js +281 -15
- package/es/ProForm/components/combination/Group/utils/index.d.ts +16 -16
- package/lib/ProEnum/hooks/useEnum.js +58 -12
- package/lib/ProEnum/hooks/useEnumRequest.js +166 -69
- package/lib/ProEnum/hooks/useFrequentEnumRequest.d.ts +1 -1
- package/lib/ProEnum/hooks/useFrequentEnumRequest.js +8 -4
- package/lib/ProEnum/propsType.d.ts +1 -1
- package/lib/ProEnum/utils/frequentEnum.d.ts +2 -2
- package/lib/ProEnum/utils/frequentEnum.js +65 -2
- package/lib/ProEnum/utils/index.d.ts +11 -5
- package/lib/ProEnum/utils/index.js +281 -16
- package/lib/ProForm/components/combination/Group/utils/index.d.ts +16 -16
- package/package.json +2 -1
|
@@ -115,12 +115,21 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
115
115
|
});
|
|
116
116
|
res.data = response;
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
|
|
119
|
+
// 获取缓存数据(支持异步)
|
|
120
|
+
_context.next = 17;
|
|
121
|
+
return Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage) || {
|
|
119
122
|
data: {}
|
|
120
|
-
};
|
|
123
|
+
});
|
|
124
|
+
case 17:
|
|
125
|
+
cacheData = _context.sent;
|
|
126
|
+
// 合并缓存数据
|
|
121
127
|
res.data = _objectSpread(_objectSpread({}, cacheData === null || cacheData === void 0 ? void 0 : cacheData.data), res.data);
|
|
122
|
-
(0, _utils.setEnumData)(storage, cacheKey, res);
|
|
123
128
|
|
|
129
|
+
// 设置缓存数据(支持异步)
|
|
130
|
+
_context.next = 21;
|
|
131
|
+
return Promise.resolve((0, _utils.setEnumData)(storage, cacheKey, res));
|
|
132
|
+
case 21:
|
|
124
133
|
// 同步数据到全局
|
|
125
134
|
dispatch({
|
|
126
135
|
type: 'setProEnumDic',
|
|
@@ -134,7 +143,7 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
134
143
|
}, 10000);
|
|
135
144
|
}
|
|
136
145
|
return _context.abrupt("return", res);
|
|
137
|
-
case
|
|
146
|
+
case 24:
|
|
138
147
|
case "end":
|
|
139
148
|
return _context.stop();
|
|
140
149
|
}
|
|
@@ -146,6 +155,30 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
146
155
|
return setCache;
|
|
147
156
|
}(),
|
|
148
157
|
getCache: () => {
|
|
158
|
+
// 支持异步读取
|
|
159
|
+
var cachePromise = Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage) || {
|
|
160
|
+
data: {}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// 对于同步存储,直接返回;对于异步存储,返回 Promise
|
|
164
|
+
if (storage === 'indexedDB') {
|
|
165
|
+
return cachePromise.then(res => {
|
|
166
|
+
dispatch({
|
|
167
|
+
type: 'setProEnumDic',
|
|
168
|
+
payload: _objectSpread(_objectSpread(_objectSpread({}, dics), dataSource), res === null || res === void 0 ? void 0 : res.data)
|
|
169
|
+
});
|
|
170
|
+
if (main) {
|
|
171
|
+
setTimeout(() => {
|
|
172
|
+
var _locale$ProEnum4;
|
|
173
|
+
window.eventCenter.publish('zat-design-pro-component-event', res.data);
|
|
174
|
+
logDebug(_locale.default === null || _locale.default === void 0 || (_locale$ProEnum4 = _locale.default.ProEnum) === null || _locale$ProEnum4 === void 0 ? void 0 : _locale$ProEnum4.mainInitByCache);
|
|
175
|
+
}, 10000);
|
|
176
|
+
}
|
|
177
|
+
return res;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 同步存储的处理
|
|
149
182
|
var res = (0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage) || {
|
|
150
183
|
data: {}
|
|
151
184
|
};
|
|
@@ -155,9 +188,9 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
155
188
|
});
|
|
156
189
|
if (main) {
|
|
157
190
|
setTimeout(() => {
|
|
158
|
-
var _locale$
|
|
191
|
+
var _locale$ProEnum5;
|
|
159
192
|
window.eventCenter.publish('zat-design-pro-component-event', res.data);
|
|
160
|
-
logDebug(_locale.default === null || _locale.default === void 0 || (_locale$
|
|
193
|
+
logDebug(_locale.default === null || _locale.default === void 0 || (_locale$ProEnum5 = _locale.default.ProEnum) === null || _locale$ProEnum5 === void 0 ? void 0 : _locale$ProEnum5.mainInitByCache);
|
|
161
194
|
}, 10000);
|
|
162
195
|
}
|
|
163
196
|
return res;
|
|
@@ -167,26 +200,29 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
167
200
|
status = _res$status === void 0 ? 200 : _res$status,
|
|
168
201
|
msg = res.message;
|
|
169
202
|
if (status !== 200) {
|
|
170
|
-
var _locale$
|
|
171
|
-
throw new Error(_locale.default === null || _locale.default === void 0 || (_locale$
|
|
203
|
+
var _locale$ProEnum6;
|
|
204
|
+
throw new Error(_locale.default === null || _locale.default === void 0 || (_locale$ProEnum6 = _locale.default.ProEnum) === null || _locale$ProEnum6 === void 0 ? void 0 : _locale$ProEnum6.requestError);
|
|
172
205
|
}
|
|
173
206
|
}
|
|
174
207
|
}));
|
|
175
208
|
var mergeData = /*#__PURE__*/function () {
|
|
176
209
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
177
|
-
var cacheData, _useRequest$options2, _useRequest$options3, enumData, cacheCodes, codes, ignoreCodes, diff, response, res, _locale$
|
|
210
|
+
var cacheData, _useRequest$options2, _useRequest$options3, enumData, cacheCodes, codes, ignoreCodes, diff, response, res, _locale$ProEnum7;
|
|
178
211
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
179
212
|
while (1) switch (_context2.prev = _context2.next) {
|
|
180
213
|
case 0:
|
|
181
|
-
|
|
214
|
+
_context2.next = 2;
|
|
215
|
+
return Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage) || {
|
|
182
216
|
data: {}
|
|
183
|
-
};
|
|
217
|
+
});
|
|
218
|
+
case 2:
|
|
219
|
+
cacheData = _context2.sent;
|
|
184
220
|
if (!(typeof cacheData === 'object')) {
|
|
185
|
-
_context2.next =
|
|
221
|
+
_context2.next = 31;
|
|
186
222
|
break;
|
|
187
223
|
}
|
|
188
224
|
if (!(typeof cacheData.data === 'object' && cacheData.data !== null)) {
|
|
189
|
-
_context2.next =
|
|
225
|
+
_context2.next = 31;
|
|
190
226
|
break;
|
|
191
227
|
}
|
|
192
228
|
enumData = cacheData.data;
|
|
@@ -195,34 +231,34 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
195
231
|
ignoreCodes = (useRequest === null || useRequest === void 0 || (_useRequest$options3 = useRequest.options) === null || _useRequest$options3 === void 0 ? void 0 : _useRequest$options3.ignoreCodes) || []; // 忽略清洗的 codes
|
|
196
232
|
diff = (0, _utils.diffCode)(cacheCodes, codes);
|
|
197
233
|
if (!diff) {
|
|
198
|
-
_context2.next =
|
|
234
|
+
_context2.next = 30;
|
|
199
235
|
break;
|
|
200
236
|
}
|
|
201
|
-
_context2.next =
|
|
237
|
+
_context2.next = 13;
|
|
202
238
|
return useRequest === null || useRequest === void 0 ? void 0 : useRequest.service();
|
|
203
|
-
case
|
|
239
|
+
case 13:
|
|
204
240
|
res = _context2.sent;
|
|
205
241
|
if (!(transformResponse && typeof transformResponse === 'function')) {
|
|
206
|
-
_context2.next =
|
|
242
|
+
_context2.next = 22;
|
|
207
243
|
break;
|
|
208
244
|
}
|
|
209
|
-
_context2.next =
|
|
245
|
+
_context2.next = 17;
|
|
210
246
|
return transformResponse(res);
|
|
211
|
-
case
|
|
247
|
+
case 17:
|
|
212
248
|
response = _context2.sent;
|
|
213
249
|
if (!(typeof response !== 'object' || response == null)) {
|
|
214
|
-
_context2.next =
|
|
250
|
+
_context2.next = 20;
|
|
215
251
|
break;
|
|
216
252
|
}
|
|
217
|
-
throw new Error(_locale.default === null || _locale.default === void 0 || (_locale$
|
|
218
|
-
case 18:
|
|
219
|
-
_context2.next = 21;
|
|
220
|
-
break;
|
|
253
|
+
throw new Error(_locale.default === null || _locale.default === void 0 || (_locale$ProEnum7 = _locale.default.ProEnum) === null || _locale$ProEnum7 === void 0 ? void 0 : _locale$ProEnum7.errorMessage);
|
|
221
254
|
case 20:
|
|
255
|
+
_context2.next = 23;
|
|
256
|
+
break;
|
|
257
|
+
case 22:
|
|
222
258
|
if (res.status === 200) {
|
|
223
259
|
response = res.data;
|
|
224
260
|
}
|
|
225
|
-
case
|
|
261
|
+
case 23:
|
|
226
262
|
// 只返回fieldNames对象的key
|
|
227
263
|
if (clear) {
|
|
228
264
|
Object.keys(response).forEach(key => {
|
|
@@ -237,15 +273,17 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
237
273
|
});
|
|
238
274
|
}
|
|
239
275
|
cacheData.data = _objectSpread(_objectSpread({}, cacheData.data), response);
|
|
240
|
-
|
|
276
|
+
_context2.next = 27;
|
|
277
|
+
return Promise.resolve((0, _utils.setEnumData)(storage, cacheKey, cacheData));
|
|
278
|
+
case 27:
|
|
241
279
|
// 同步数据到全局
|
|
242
280
|
dispatch({
|
|
243
281
|
type: 'setProEnumDic',
|
|
244
282
|
payload: _objectSpread(_objectSpread(_objectSpread({}, dics), dataSource), cacheData.data)
|
|
245
283
|
});
|
|
246
|
-
_context2.next =
|
|
284
|
+
_context2.next = 31;
|
|
247
285
|
break;
|
|
248
|
-
case
|
|
286
|
+
case 30:
|
|
249
287
|
if (dataSource && Object.keys(dataSource)) {
|
|
250
288
|
// 子系统也可能会有 dataSource
|
|
251
289
|
dispatch({
|
|
@@ -253,7 +291,7 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
253
291
|
payload: _objectSpread(_objectSpread({}, dics), dataSource)
|
|
254
292
|
});
|
|
255
293
|
}
|
|
256
|
-
case
|
|
294
|
+
case 31:
|
|
257
295
|
case "end":
|
|
258
296
|
return _context2.stop();
|
|
259
297
|
}
|
|
@@ -264,56 +302,115 @@ var useEnumRequest = (props, dispatch) => {
|
|
|
264
302
|
};
|
|
265
303
|
}();
|
|
266
304
|
(0, _ahooks.useDeepCompareEffect)(() => {
|
|
267
|
-
|
|
268
|
-
var _ref4 = (
|
|
269
|
-
defaultParams
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
305
|
+
var executeAsync = /*#__PURE__*/function () {
|
|
306
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
307
|
+
var _ref5, defaultParams, _params, res, _res;
|
|
308
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
309
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
310
|
+
case 0:
|
|
311
|
+
if (!(useRequest && useRequest !== null && useRequest !== void 0 && useRequest.service)) {
|
|
312
|
+
_context3.next = 13;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
_ref5 = (useRequest === null || useRequest === void 0 ? void 0 : useRequest.options) || {}, defaultParams = _ref5.defaultParams;
|
|
316
|
+
_params = Array.isArray(defaultParams) ? defaultParams === null || defaultParams === void 0 ? void 0 : defaultParams[0] : defaultParams || {};
|
|
317
|
+
if (!requestRefresh) {
|
|
318
|
+
_context3.next = 9;
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
window.localStorage.removeItem(cacheKey);
|
|
322
|
+
window.sessionStorage.removeItem(cacheKey);
|
|
323
|
+
// 清除 IndexedDB
|
|
324
|
+
if (!(storage === 'indexedDB')) {
|
|
325
|
+
_context3.next = 9;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
_context3.next = 9;
|
|
329
|
+
return (0, _utils.removeEnumData)('indexedDB', cacheKey);
|
|
330
|
+
case 9:
|
|
331
|
+
enumRes.run(_params);
|
|
276
332
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
333
|
+
// TODO 这段代码目前看起来是没啥用的、没起到作用
|
|
334
|
+
mergeData();
|
|
335
|
+
_context3.next = 24;
|
|
336
|
+
break;
|
|
337
|
+
case 13:
|
|
338
|
+
if (!Object.keys(dataSource)) {
|
|
339
|
+
_context3.next = 20;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
_context3.next = 16;
|
|
343
|
+
return Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage) || {
|
|
344
|
+
data: {}
|
|
345
|
+
});
|
|
346
|
+
case 16:
|
|
347
|
+
res = _context3.sent;
|
|
348
|
+
dispatch({
|
|
349
|
+
type: 'setProEnumDic',
|
|
350
|
+
payload: _objectSpread(_objectSpread({}, dataSource), res === null || res === void 0 ? void 0 : res.data)
|
|
351
|
+
});
|
|
352
|
+
_context3.next = 24;
|
|
353
|
+
break;
|
|
354
|
+
case 20:
|
|
355
|
+
_context3.next = 22;
|
|
356
|
+
return Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage) || {
|
|
357
|
+
data: {}
|
|
358
|
+
});
|
|
359
|
+
case 22:
|
|
360
|
+
_res = _context3.sent;
|
|
361
|
+
dispatch({
|
|
362
|
+
type: 'setProEnumDic',
|
|
363
|
+
payload: _objectSpread({}, _res === null || _res === void 0 ? void 0 : _res.data)
|
|
364
|
+
});
|
|
365
|
+
case 24:
|
|
366
|
+
case "end":
|
|
367
|
+
return _context3.stop();
|
|
368
|
+
}
|
|
369
|
+
}, _callee3);
|
|
370
|
+
}));
|
|
371
|
+
return function executeAsync() {
|
|
372
|
+
return _ref4.apply(this, arguments);
|
|
290
373
|
};
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
payload: _objectSpread({}, _res === null || _res === void 0 ? void 0 : _res.data)
|
|
294
|
-
});
|
|
295
|
-
}
|
|
374
|
+
}();
|
|
375
|
+
executeAsync();
|
|
296
376
|
}, [useRequest === null || useRequest === void 0 ? void 0 : useRequest.options]);
|
|
297
|
-
var shareProEnumDic =
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
377
|
+
var shareProEnumDic = /*#__PURE__*/function () {
|
|
378
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(cacheData) {
|
|
379
|
+
var storageData;
|
|
380
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
381
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
382
|
+
case 0:
|
|
383
|
+
logDebug(cacheData);
|
|
384
|
+
_context4.next = 3;
|
|
385
|
+
return Promise.resolve((0, _utils.getEnumData)(storage, cacheKey, baseEnumStorage) || {
|
|
386
|
+
data: {}
|
|
387
|
+
});
|
|
388
|
+
case 3:
|
|
389
|
+
storageData = _context4.sent;
|
|
390
|
+
dispatch({
|
|
391
|
+
type: 'setProEnumDic',
|
|
392
|
+
payload: _objectSpread(_objectSpread(_objectSpread({}, dataSource), cacheData), storageData)
|
|
393
|
+
});
|
|
394
|
+
case 5:
|
|
395
|
+
case "end":
|
|
396
|
+
return _context4.stop();
|
|
397
|
+
}
|
|
398
|
+
}, _callee4);
|
|
399
|
+
}));
|
|
400
|
+
return function shareProEnumDic(_x2) {
|
|
401
|
+
return _ref6.apply(this, arguments);
|
|
301
402
|
};
|
|
302
|
-
|
|
303
|
-
type: 'setProEnumDic',
|
|
304
|
-
payload: _objectSpread(_objectSpread(_objectSpread({}, dataSource), cacheData), storageData)
|
|
305
|
-
});
|
|
306
|
-
};
|
|
403
|
+
}();
|
|
307
404
|
(0, _react.useEffect)(() => {
|
|
308
405
|
if (main) {
|
|
309
|
-
var _locale$
|
|
406
|
+
var _locale$ProEnum8;
|
|
310
407
|
window.eventCenter.publish('zat-design-pro-component-event', {});
|
|
311
|
-
logDebug(_locale.default === null || _locale.default === void 0 || (_locale$
|
|
408
|
+
logDebug(_locale.default === null || _locale.default === void 0 || (_locale$ProEnum8 = _locale.default.ProEnum) === null || _locale$ProEnum8 === void 0 ? void 0 : _locale$ProEnum8.mainInitOnce);
|
|
312
409
|
}
|
|
313
410
|
if (!main && share) {
|
|
314
|
-
var _locale$
|
|
411
|
+
var _locale$ProEnum9;
|
|
315
412
|
window.eventCenter.subscribe('zat-design-pro-component-event', shareProEnumDic);
|
|
316
|
-
logDebug(_locale.default === null || _locale.default === void 0 || (_locale$
|
|
413
|
+
logDebug(_locale.default === null || _locale.default === void 0 || (_locale$ProEnum9 = _locale.default.ProEnum) === null || _locale$ProEnum9 === void 0 ? void 0 : _locale$ProEnum9.sonInitEvent);
|
|
317
414
|
}
|
|
318
415
|
return () => {
|
|
319
416
|
window.eventCenter.unsubscribe('zat-design-pro-component-event', shareProEnumDic);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FrequentEnumConfig } from '../propsType';
|
|
2
|
-
type StorageType = 'localStorage' | 'sessionStorage';
|
|
2
|
+
type StorageType = 'localStorage' | 'sessionStorage' | 'indexedDB';
|
|
3
3
|
interface UseFrequentEnumRequestProps {
|
|
4
4
|
frequentEnums?: FrequentEnumConfig;
|
|
5
5
|
fieldNames: any;
|
|
@@ -43,20 +43,24 @@ var useFrequentEnumRequest = (props, dispatch) => {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// 确保response.data存在,如果不存在则使用response本身
|
|
46
|
-
enumData = ((_response = response) === null || _response === void 0 ? void 0 : _response.data) || response; //
|
|
47
|
-
|
|
46
|
+
enumData = ((_response = response) === null || _response === void 0 ? void 0 : _response.data) || response; // 替换缓存中的指定枚举(支持异步)
|
|
47
|
+
_context.next = 5;
|
|
48
|
+
return Promise.resolve((0, _frequentEnum.replaceFrequentEnumCache)({
|
|
48
49
|
storage,
|
|
49
50
|
cacheKey,
|
|
50
51
|
enums: (frequentEnums === null || frequentEnums === void 0 ? void 0 : frequentEnums.enums) || [],
|
|
51
52
|
newData: enumData,
|
|
52
53
|
fieldNames,
|
|
53
54
|
clear
|
|
54
|
-
});
|
|
55
|
+
}));
|
|
56
|
+
case 5:
|
|
57
|
+
updatedCacheData = _context.sent;
|
|
58
|
+
// 同步数据到全局状态
|
|
55
59
|
dispatch({
|
|
56
60
|
type: 'setProEnumDic',
|
|
57
61
|
payload: _objectSpread(_objectSpread(_objectSpread({}, dics), dataSource), updatedCacheData.data)
|
|
58
62
|
});
|
|
59
|
-
case
|
|
63
|
+
case 7:
|
|
60
64
|
case "end":
|
|
61
65
|
return _context.stop();
|
|
62
66
|
}
|
|
@@ -94,7 +94,7 @@ export interface ProEnumConfigType {
|
|
|
94
94
|
* @description 存储位置、不设置、默认读取 globalConfig 里面的
|
|
95
95
|
* @default "localStorage"
|
|
96
96
|
*/
|
|
97
|
-
storage: 'localStorage' | 'sessionStorage';
|
|
97
|
+
storage: 'localStorage' | 'sessionStorage' | 'indexedDB';
|
|
98
98
|
/**
|
|
99
99
|
* @description 默认静态枚举数据
|
|
100
100
|
* @default {}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FrequentEnumConfig } from '../propsType';
|
|
2
|
-
type StorageType = 'localStorage' | 'sessionStorage';
|
|
2
|
+
type StorageType = 'localStorage' | 'sessionStorage' | 'indexedDB';
|
|
3
3
|
/**
|
|
4
4
|
* 替换频繁枚举缓存数据的参数接口
|
|
5
5
|
*/
|
|
@@ -22,7 +22,7 @@ export interface ReplaceFrequentEnumCacheParams {
|
|
|
22
22
|
* @param params 参数对象
|
|
23
23
|
* @returns 更新后的缓存数据
|
|
24
24
|
*/
|
|
25
|
-
export declare function replaceFrequentEnumCache(params: ReplaceFrequentEnumCacheParams): any
|
|
25
|
+
export declare function replaceFrequentEnumCache(params: ReplaceFrequentEnumCacheParams): any | Promise<any>;
|
|
26
26
|
/**
|
|
27
27
|
* 验证频繁枚举配置
|
|
28
28
|
* @param config 频繁枚举配置
|
|
@@ -7,20 +7,73 @@ exports.mergeFrequentEnumData = mergeFrequentEnumData;
|
|
|
7
7
|
exports.replaceFrequentEnumCache = replaceFrequentEnumCache;
|
|
8
8
|
exports.validateFrequentEnumConfig = validateFrequentEnumConfig;
|
|
9
9
|
var _index = require("./index");
|
|
10
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
10
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
12
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
13
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
14
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
14
15
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
17
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
15
18
|
/**
|
|
16
19
|
* 替换频繁枚举缓存数据的参数接口
|
|
17
20
|
*/
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* IndexedDB 异步版本的替换频繁枚举缓存数据
|
|
23
|
+
*/
|
|
24
|
+
function replaceFrequentEnumCacheAsync(_x) {
|
|
25
|
+
return _replaceFrequentEnumCacheAsync.apply(this, arguments);
|
|
26
|
+
}
|
|
19
27
|
/**
|
|
20
28
|
* 替换频繁枚举缓存数据
|
|
21
29
|
* @param params 参数对象
|
|
22
30
|
* @returns 更新后的缓存数据
|
|
23
31
|
*/
|
|
32
|
+
function _replaceFrequentEnumCacheAsync() {
|
|
33
|
+
_replaceFrequentEnumCacheAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
34
|
+
var storage, cacheKey, enums, newData, fieldNames, clear, cacheData;
|
|
35
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
36
|
+
while (1) switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
storage = params.storage, cacheKey = params.cacheKey, enums = params.enums, newData = params.newData, fieldNames = params.fieldNames, clear = params.clear;
|
|
39
|
+
_context.next = 3;
|
|
40
|
+
return Promise.resolve((0, _index.getEnumData)(storage, cacheKey) || {
|
|
41
|
+
data: {}
|
|
42
|
+
});
|
|
43
|
+
case 3:
|
|
44
|
+
cacheData = _context.sent;
|
|
45
|
+
// 确保cacheData.data存在
|
|
46
|
+
if (!cacheData.data) {
|
|
47
|
+
cacheData.data = {};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 只替换指定的枚举
|
|
51
|
+
enums.forEach(code => {
|
|
52
|
+
if (newData[code]) {
|
|
53
|
+
var processedData = newData[code];
|
|
54
|
+
|
|
55
|
+
// 应用数据清洗逻辑
|
|
56
|
+
if (clear && Array.isArray(processedData)) {
|
|
57
|
+
processedData = processedData.map(item => {
|
|
58
|
+
return (0, _index.cacheFieldNames)(fieldNames, item);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
cacheData.data[code] = processedData;
|
|
62
|
+
cacheData.time = Date.now();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
_context.next = 8;
|
|
66
|
+
return Promise.resolve((0, _index.setEnumData)(storage, cacheKey, cacheData));
|
|
67
|
+
case 8:
|
|
68
|
+
return _context.abrupt("return", cacheData);
|
|
69
|
+
case 9:
|
|
70
|
+
case "end":
|
|
71
|
+
return _context.stop();
|
|
72
|
+
}
|
|
73
|
+
}, _callee);
|
|
74
|
+
}));
|
|
75
|
+
return _replaceFrequentEnumCacheAsync.apply(this, arguments);
|
|
76
|
+
}
|
|
24
77
|
function replaceFrequentEnumCache(params) {
|
|
25
78
|
var _params$storage = params.storage,
|
|
26
79
|
storage = _params$storage === void 0 ? 'localStorage' : _params$storage,
|
|
@@ -52,7 +105,17 @@ function replaceFrequentEnumCache(params) {
|
|
|
52
105
|
data: {}
|
|
53
106
|
};
|
|
54
107
|
}
|
|
55
|
-
|
|
108
|
+
|
|
109
|
+
// IndexedDB 异步处理
|
|
110
|
+
if (storage === 'indexedDB') {
|
|
111
|
+
return replaceFrequentEnumCacheAsync(params);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// localStorage/sessionStorage 同步处理(保持原逻辑)
|
|
115
|
+
var cacheDataResult = (0, _index.getEnumData)(storage, cacheKey);
|
|
116
|
+
// getEnumData 对于非 indexedDB 返回同步值,对于 indexedDB 返回 Promise
|
|
117
|
+
// 这里 storage 不是 indexedDB,所以是同步值
|
|
118
|
+
var cacheData = cacheDataResult || {
|
|
56
119
|
data: {}
|
|
57
120
|
};
|
|
58
121
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataOption } from '../propsType';
|
|
2
|
-
type StorageType = 'localStorage' | 'sessionStorage';
|
|
2
|
+
type StorageType = 'localStorage' | 'sessionStorage' | 'indexedDB';
|
|
3
3
|
export declare const baseCacheKey = "zat-design-pro-component-cacheKey";
|
|
4
4
|
interface EnumRes {
|
|
5
5
|
data: Record<string, DataOption[]>;
|
|
@@ -12,14 +12,20 @@ interface EnumRes {
|
|
|
12
12
|
* @param baseEnumStorage
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
|
-
export declare function getEnumData(storage: StorageType, cacheKey: string, baseEnumStorage?: any): EnumRes
|
|
15
|
+
export declare function getEnumData(storage: StorageType, cacheKey: string, baseEnumStorage?: any): EnumRes | Promise<EnumRes>;
|
|
16
16
|
/**
|
|
17
17
|
* 设置枚举数据
|
|
18
18
|
* @param storage
|
|
19
19
|
* @param cacheKey
|
|
20
20
|
* @param data
|
|
21
21
|
*/
|
|
22
|
-
export declare function setEnumData(storage: StorageType, cacheKey: string, data: any):
|
|
22
|
+
export declare function setEnumData(storage: StorageType, cacheKey: string, data: any): void | Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* 删除枚举缓存数据
|
|
25
|
+
* @param storage
|
|
26
|
+
* @param cacheKey
|
|
27
|
+
*/
|
|
28
|
+
export declare function removeEnumData(storage: StorageType, cacheKey: string): Promise<void>;
|
|
23
29
|
/**
|
|
24
30
|
* 判断枚举列表是否存在
|
|
25
31
|
* @param storage
|
|
@@ -27,7 +33,7 @@ export declare function setEnumData(storage: StorageType, cacheKey: string, data
|
|
|
27
33
|
* @param code
|
|
28
34
|
* @returns
|
|
29
35
|
*/
|
|
30
|
-
export declare function hasEnumList(storage: StorageType, cacheKey: any, code: string): import("../propsType").DataOptionType[];
|
|
36
|
+
export declare function hasEnumList(storage: StorageType, cacheKey: any, code: string): false | import("../propsType").DataOptionType[];
|
|
31
37
|
/**
|
|
32
38
|
* 判断是否是对象
|
|
33
39
|
* @param obj
|
|
@@ -41,7 +47,7 @@ export declare function isObject(obj: any): boolean;
|
|
|
41
47
|
* @param cacheKey
|
|
42
48
|
* @param responseData
|
|
43
49
|
*/
|
|
44
|
-
export declare function mergeCacheData(storage: string, code: string, cacheKey: string, responseData: any): void
|
|
50
|
+
export declare function mergeCacheData(storage: string, code: string, cacheKey: string, responseData: any): Promise<void>;
|
|
45
51
|
/**
|
|
46
52
|
* diff code 差异
|
|
47
53
|
* @param cacheCodes
|