@zat-design/sisyphus-react 4.0.11 → 4.0.13

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.
@@ -3,11 +3,21 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
3
3
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
4
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
5
5
  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); }
6
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
12
  /* eslint-disable no-redeclare */
13
+ import { useState, useEffect } from 'react';
7
14
  import { useProConfig } from "../../ProConfigProvider";
8
15
  import { getEnumData } from "../utils";
9
16
  var baseEnumStorage = (_ref = window.localStorage.getItem('zat-design-pro-component-cacheKey') && JSON.parse(window.localStorage.getItem('zat-design-pro-component-cacheKey'))) !== null && _ref !== void 0 ? _ref : null;
10
17
 
18
+ // 模块级缓存,用于存储正在进行的 IndexedDB 读取 Promise,避免重复读取
19
+ var indexedDBLoadingCache = new Map();
20
+
11
21
  /**
12
22
  * input code output [DataOption[],getEnumLabel]
13
23
  * @param code
@@ -44,25 +54,121 @@ var baseEnumStorage = (_ref = window.localStorage.getItem('zat-design-pro-compon
44
54
  */
45
55
 
46
56
  function useEnum(codes, value, compose) {
47
- var _ref2 = useProConfig('globalConfig') || {},
57
+ var _ref2 = useProConfig('ProEnum') || {},
48
58
  _ref2$storage = _ref2.storage,
49
- storage = _ref2$storage === void 0 ? 'localStorage' : _ref2$storage;
50
- var _ref3 = useProConfig('ProEnum') || {},
51
- _ref3$cacheKey = _ref3.cacheKey,
52
- cacheKey = _ref3$cacheKey === void 0 ? 'zat-design-pro-component-cacheKey' : _ref3$cacheKey,
53
- _ref3$fieldNames = _ref3.fieldNames,
54
- fieldNames = _ref3$fieldNames === void 0 ? {} : _ref3$fieldNames,
55
- _ref3$clear = _ref3.clear,
56
- clear = _ref3$clear === void 0 ? true : _ref3$clear;
59
+ storage = _ref2$storage === void 0 ? 'localStorage' : _ref2$storage,
60
+ _ref2$cacheKey = _ref2.cacheKey,
61
+ cacheKey = _ref2$cacheKey === void 0 ? 'zat-design-pro-component-cacheKey' : _ref2$cacheKey,
62
+ _ref2$fieldNames = _ref2.fieldNames,
63
+ fieldNames = _ref2$fieldNames === void 0 ? {} : _ref2$fieldNames,
64
+ _ref2$clear = _ref2.clear,
65
+ clear = _ref2$clear === void 0 ? true : _ref2$clear,
66
+ _ref2$dics = _ref2.dics,
67
+ dics = _ref2$dics === void 0 ? {} : _ref2$dics;
57
68
 
58
69
  // 存在子应用自管理枚举时,需要根据其指定的cacheKey进行缓存
59
70
  if (cacheKey !== 'zat-design-pro-component-cacheKey') {
60
71
  baseEnumStorage = null;
61
72
  }
62
- var catchData = getEnumData(storage, cacheKey, baseEnumStorage);
63
73
 
64
- // 默认枚举缓存数据
65
- baseEnumStorage = catchData;
74
+ // 使用 state 来存储异步加载的数据
75
+ var _useState = useState(() => {
76
+ // 优先使用全局状态中的 dics 数据(如果存在)
77
+ if (storage === 'indexedDB' && dics && Object.keys(dics).length > 0) {
78
+ return {
79
+ data: dics
80
+ };
81
+ }
82
+ // 初始化:对于同步存储,直接返回数据;对于 IndexedDB,返回空数据
83
+ if (storage === 'indexedDB') {
84
+ return {
85
+ data: {}
86
+ };
87
+ }
88
+ return getEnumData(storage, cacheKey, baseEnumStorage) || {
89
+ data: {}
90
+ };
91
+ }),
92
+ _useState2 = _slicedToArray(_useState, 2),
93
+ enumData = _useState2[0],
94
+ setEnumData = _useState2[1];
95
+
96
+ // 监听全局状态中的 dics 变化,优先使用 dics 数据
97
+ useEffect(() => {
98
+ if (storage === 'indexedDB' && dics && Object.keys(dics).length > 0) {
99
+ setEnumData(prevData => {
100
+ // 只有当 dics 有数据且与当前数据不同时才更新
101
+ if (JSON.stringify(dics) !== JSON.stringify(prevData === null || prevData === void 0 ? void 0 : prevData.data)) {
102
+ return {
103
+ data: dics
104
+ };
105
+ }
106
+ return prevData;
107
+ });
108
+ }
109
+ }, [storage, cacheKey, dics]);
110
+
111
+ // 异步加载 IndexedDB 数据
112
+ useEffect(() => {
113
+ if (storage === 'indexedDB') {
114
+ // 使用模块级缓存避免重复读取
115
+ var loadPromise = indexedDBLoadingCache.get(cacheKey);
116
+ if (!loadPromise) {
117
+ loadPromise = Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage)).then(data => {
118
+ // 读取完成后,从缓存中移除
119
+ indexedDBLoadingCache.delete(cacheKey);
120
+ return data;
121
+ }).catch(error => {
122
+ // 读取失败后,从缓存中移除
123
+ indexedDBLoadingCache.delete(cacheKey);
124
+ // 错误已在 getEnumData 中处理,这里返回空数据
125
+ return {
126
+ data: {}
127
+ };
128
+ });
129
+ indexedDBLoadingCache.set(cacheKey, loadPromise);
130
+ }
131
+ loadPromise.then(data => {
132
+ // 如果数据为空或无效,且当前 enumData 也是空的,尝试重新读取
133
+ if ((!data || !data.data || Object.keys(data.data).length === 0) && (!enumData || !enumData.data || Object.keys(enumData.data).length === 0)) {
134
+ // 延迟重试,给 IndexedDB 一些时间
135
+ setTimeout(() => {
136
+ // 清除缓存,允许重新读取
137
+ indexedDBLoadingCache.delete(cacheKey);
138
+ Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage)).then(retryData => {
139
+ if (retryData && retryData.data && Object.keys(retryData.data).length > 0) {
140
+ setEnumData(prevData => {
141
+ if (retryData && JSON.stringify(retryData) !== JSON.stringify(prevData)) {
142
+ baseEnumStorage = retryData;
143
+ return retryData;
144
+ }
145
+ return prevData;
146
+ });
147
+ }
148
+ }).catch(() => {
149
+ // 重试失败,保持空数据
150
+ });
151
+ }, 100);
152
+ } else {
153
+ setEnumData(prevData => {
154
+ if (data && JSON.stringify(data) !== JSON.stringify(prevData)) {
155
+ baseEnumStorage = data;
156
+ return data || {
157
+ data: {}
158
+ };
159
+ }
160
+ return prevData;
161
+ });
162
+ }
163
+ });
164
+ }
165
+ }, [storage, cacheKey, enumData]);
166
+ var catchData = storage === 'indexedDB' ? enumData : getEnumData(storage, cacheKey, baseEnumStorage);
167
+
168
+ // 默认枚举缓存数据(仅同步存储)
169
+ if (storage !== 'indexedDB') {
170
+ baseEnumStorage = catchData;
171
+ }
66
172
  if (!codes) {
67
173
  return catchData;
68
174
  }
@@ -9,7 +9,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
9
9
  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); }
10
10
  import { useEffect } from 'react';
11
11
  import { useDeepCompareEffect, useRequest as useRequestFunc } from 'ahooks';
12
- import { diffCode, getEnumData, setEnumData, cacheFieldNames, baseCacheKey } from "../utils";
12
+ import { diffCode, getEnumData, setEnumData, removeEnumData, cacheFieldNames, baseCacheKey } from "../utils";
13
13
  import locale from "../../locale";
14
14
  import "../utils/eventCenter";
15
15
  var baseEnumStorage = (_ref = window.localStorage.getItem(baseCacheKey) && JSON.parse(window.localStorage.getItem(baseCacheKey))) !== null && _ref !== void 0 ? _ref : null;
@@ -108,12 +108,21 @@ var useEnumRequest = (props, dispatch) => {
108
108
  });
109
109
  res.data = response;
110
110
  }
111
- cacheData = getEnumData(storage, cacheKey, baseEnumStorage) || {
111
+
112
+ // 获取缓存数据(支持异步)
113
+ _context.next = 17;
114
+ return Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage) || {
112
115
  data: {}
113
- }; // 合并缓存数据
116
+ });
117
+ case 17:
118
+ cacheData = _context.sent;
119
+ // 合并缓存数据
114
120
  res.data = _objectSpread(_objectSpread({}, cacheData === null || cacheData === void 0 ? void 0 : cacheData.data), res.data);
115
- setEnumData(storage, cacheKey, res);
116
121
 
122
+ // 设置缓存数据(支持异步)
123
+ _context.next = 21;
124
+ return Promise.resolve(setEnumData(storage, cacheKey, res));
125
+ case 21:
117
126
  // 同步数据到全局
118
127
  dispatch({
119
128
  type: 'setProEnumDic',
@@ -127,7 +136,7 @@ var useEnumRequest = (props, dispatch) => {
127
136
  }, 10000);
128
137
  }
129
138
  return _context.abrupt("return", res);
130
- case 21:
139
+ case 24:
131
140
  case "end":
132
141
  return _context.stop();
133
142
  }
@@ -139,6 +148,30 @@ var useEnumRequest = (props, dispatch) => {
139
148
  return setCache;
140
149
  }(),
141
150
  getCache: () => {
151
+ // 支持异步读取
152
+ var cachePromise = Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage) || {
153
+ data: {}
154
+ });
155
+
156
+ // 对于同步存储,直接返回;对于异步存储,返回 Promise
157
+ if (storage === 'indexedDB') {
158
+ return cachePromise.then(res => {
159
+ dispatch({
160
+ type: 'setProEnumDic',
161
+ payload: _objectSpread(_objectSpread(_objectSpread({}, dics), dataSource), res === null || res === void 0 ? void 0 : res.data)
162
+ });
163
+ if (main) {
164
+ setTimeout(() => {
165
+ var _locale$ProEnum4;
166
+ window.eventCenter.publish('zat-design-pro-component-event', res.data);
167
+ logDebug(locale === null || locale === void 0 || (_locale$ProEnum4 = locale.ProEnum) === null || _locale$ProEnum4 === void 0 ? void 0 : _locale$ProEnum4.mainInitByCache);
168
+ }, 10000);
169
+ }
170
+ return res;
171
+ });
172
+ }
173
+
174
+ // 同步存储的处理
142
175
  var res = getEnumData(storage, cacheKey, baseEnumStorage) || {
143
176
  data: {}
144
177
  };
@@ -148,9 +181,9 @@ var useEnumRequest = (props, dispatch) => {
148
181
  });
149
182
  if (main) {
150
183
  setTimeout(() => {
151
- var _locale$ProEnum4;
184
+ var _locale$ProEnum5;
152
185
  window.eventCenter.publish('zat-design-pro-component-event', res.data);
153
- logDebug(locale === null || locale === void 0 || (_locale$ProEnum4 = locale.ProEnum) === null || _locale$ProEnum4 === void 0 ? void 0 : _locale$ProEnum4.mainInitByCache);
186
+ logDebug(locale === null || locale === void 0 || (_locale$ProEnum5 = locale.ProEnum) === null || _locale$ProEnum5 === void 0 ? void 0 : _locale$ProEnum5.mainInitByCache);
154
187
  }, 10000);
155
188
  }
156
189
  return res;
@@ -160,26 +193,29 @@ var useEnumRequest = (props, dispatch) => {
160
193
  status = _res$status === void 0 ? 200 : _res$status,
161
194
  msg = res.message;
162
195
  if (status !== 200) {
163
- var _locale$ProEnum5;
164
- throw new Error(locale === null || locale === void 0 || (_locale$ProEnum5 = locale.ProEnum) === null || _locale$ProEnum5 === void 0 ? void 0 : _locale$ProEnum5.requestError);
196
+ var _locale$ProEnum6;
197
+ throw new Error(locale === null || locale === void 0 || (_locale$ProEnum6 = locale.ProEnum) === null || _locale$ProEnum6 === void 0 ? void 0 : _locale$ProEnum6.requestError);
165
198
  }
166
199
  }
167
200
  }));
168
201
  var mergeData = /*#__PURE__*/function () {
169
202
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
170
- var cacheData, _useRequest$options2, _useRequest$options3, enumData, cacheCodes, codes, ignoreCodes, diff, response, res, _locale$ProEnum6;
203
+ var cacheData, _useRequest$options2, _useRequest$options3, enumData, cacheCodes, codes, ignoreCodes, diff, response, res, _locale$ProEnum7;
171
204
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
172
205
  while (1) switch (_context2.prev = _context2.next) {
173
206
  case 0:
174
- cacheData = getEnumData(storage, cacheKey, baseEnumStorage) || {
207
+ _context2.next = 2;
208
+ return Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage) || {
175
209
  data: {}
176
- };
210
+ });
211
+ case 2:
212
+ cacheData = _context2.sent;
177
213
  if (!(typeof cacheData === 'object')) {
178
- _context2.next = 28;
214
+ _context2.next = 31;
179
215
  break;
180
216
  }
181
217
  if (!(typeof cacheData.data === 'object' && cacheData.data !== null)) {
182
- _context2.next = 28;
218
+ _context2.next = 31;
183
219
  break;
184
220
  }
185
221
  enumData = cacheData.data;
@@ -188,34 +224,34 @@ var useEnumRequest = (props, dispatch) => {
188
224
  ignoreCodes = (useRequest === null || useRequest === void 0 || (_useRequest$options3 = useRequest.options) === null || _useRequest$options3 === void 0 ? void 0 : _useRequest$options3.ignoreCodes) || []; // 忽略清洗的 codes
189
225
  diff = diffCode(cacheCodes, codes);
190
226
  if (!diff) {
191
- _context2.next = 27;
227
+ _context2.next = 30;
192
228
  break;
193
229
  }
194
- _context2.next = 11;
230
+ _context2.next = 13;
195
231
  return useRequest === null || useRequest === void 0 ? void 0 : useRequest.service();
196
- case 11:
232
+ case 13:
197
233
  res = _context2.sent;
198
234
  if (!(transformResponse && typeof transformResponse === 'function')) {
199
- _context2.next = 20;
235
+ _context2.next = 22;
200
236
  break;
201
237
  }
202
- _context2.next = 15;
238
+ _context2.next = 17;
203
239
  return transformResponse(res);
204
- case 15:
240
+ case 17:
205
241
  response = _context2.sent;
206
242
  if (!(typeof response !== 'object' || response == null)) {
207
- _context2.next = 18;
243
+ _context2.next = 20;
208
244
  break;
209
245
  }
210
- throw new Error(locale === null || locale === void 0 || (_locale$ProEnum6 = locale.ProEnum) === null || _locale$ProEnum6 === void 0 ? void 0 : _locale$ProEnum6.errorMessage);
211
- case 18:
212
- _context2.next = 21;
213
- break;
246
+ throw new Error(locale === null || locale === void 0 || (_locale$ProEnum7 = locale.ProEnum) === null || _locale$ProEnum7 === void 0 ? void 0 : _locale$ProEnum7.errorMessage);
214
247
  case 20:
248
+ _context2.next = 23;
249
+ break;
250
+ case 22:
215
251
  if (res.status === 200) {
216
252
  response = res.data;
217
253
  }
218
- case 21:
254
+ case 23:
219
255
  // 只返回fieldNames对象的key
220
256
  if (clear) {
221
257
  Object.keys(response).forEach(key => {
@@ -230,15 +266,17 @@ var useEnumRequest = (props, dispatch) => {
230
266
  });
231
267
  }
232
268
  cacheData.data = _objectSpread(_objectSpread({}, cacheData.data), response);
233
- setEnumData(storage, cacheKey, cacheData);
269
+ _context2.next = 27;
270
+ return Promise.resolve(setEnumData(storage, cacheKey, cacheData));
271
+ case 27:
234
272
  // 同步数据到全局
235
273
  dispatch({
236
274
  type: 'setProEnumDic',
237
275
  payload: _objectSpread(_objectSpread(_objectSpread({}, dics), dataSource), cacheData.data)
238
276
  });
239
- _context2.next = 28;
277
+ _context2.next = 31;
240
278
  break;
241
- case 27:
279
+ case 30:
242
280
  if (dataSource && Object.keys(dataSource)) {
243
281
  // 子系统也可能会有 dataSource
244
282
  dispatch({
@@ -246,7 +284,7 @@ var useEnumRequest = (props, dispatch) => {
246
284
  payload: _objectSpread(_objectSpread({}, dics), dataSource)
247
285
  });
248
286
  }
249
- case 28:
287
+ case 31:
250
288
  case "end":
251
289
  return _context2.stop();
252
290
  }
@@ -257,56 +295,115 @@ var useEnumRequest = (props, dispatch) => {
257
295
  };
258
296
  }();
259
297
  useDeepCompareEffect(() => {
260
- if (useRequest && useRequest !== null && useRequest !== void 0 && useRequest.service) {
261
- var _ref4 = (useRequest === null || useRequest === void 0 ? void 0 : useRequest.options) || {},
262
- defaultParams = _ref4.defaultParams;
263
- var params = Array.isArray(defaultParams) ? defaultParams === null || defaultParams === void 0 ? void 0 : defaultParams[0] : defaultParams || {};
264
- if (requestRefresh) {
265
- window.localStorage.removeItem(cacheKey);
266
- window.sessionStorage.removeItem(cacheKey);
267
- }
268
- enumRes.run(params);
298
+ var executeAsync = /*#__PURE__*/function () {
299
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
300
+ var _ref5, defaultParams, _params, res, _res;
301
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
302
+ while (1) switch (_context3.prev = _context3.next) {
303
+ case 0:
304
+ if (!(useRequest && useRequest !== null && useRequest !== void 0 && useRequest.service)) {
305
+ _context3.next = 13;
306
+ break;
307
+ }
308
+ _ref5 = (useRequest === null || useRequest === void 0 ? void 0 : useRequest.options) || {}, defaultParams = _ref5.defaultParams;
309
+ _params = Array.isArray(defaultParams) ? defaultParams === null || defaultParams === void 0 ? void 0 : defaultParams[0] : defaultParams || {};
310
+ if (!requestRefresh) {
311
+ _context3.next = 9;
312
+ break;
313
+ }
314
+ window.localStorage.removeItem(cacheKey);
315
+ window.sessionStorage.removeItem(cacheKey);
316
+ // 清除 IndexedDB
317
+ if (!(storage === 'indexedDB')) {
318
+ _context3.next = 9;
319
+ break;
320
+ }
321
+ _context3.next = 9;
322
+ return removeEnumData('indexedDB', cacheKey);
323
+ case 9:
324
+ enumRes.run(_params);
269
325
 
270
- // TODO 这段代码目前看起来是没啥用的、没起到作用
271
- mergeData();
272
- } else if (Object.keys(dataSource)) {
273
- var res = getEnumData(storage, cacheKey, baseEnumStorage) || {
274
- data: {}
275
- };
276
- dispatch({
277
- type: 'setProEnumDic',
278
- payload: _objectSpread(_objectSpread({}, dataSource), res === null || res === void 0 ? void 0 : res.data)
279
- });
280
- } else {
281
- var _res = getEnumData(storage, cacheKey, baseEnumStorage) || {
282
- data: {}
326
+ // TODO 这段代码目前看起来是没啥用的、没起到作用
327
+ mergeData();
328
+ _context3.next = 24;
329
+ break;
330
+ case 13:
331
+ if (!Object.keys(dataSource)) {
332
+ _context3.next = 20;
333
+ break;
334
+ }
335
+ _context3.next = 16;
336
+ return Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage) || {
337
+ data: {}
338
+ });
339
+ case 16:
340
+ res = _context3.sent;
341
+ dispatch({
342
+ type: 'setProEnumDic',
343
+ payload: _objectSpread(_objectSpread({}, dataSource), res === null || res === void 0 ? void 0 : res.data)
344
+ });
345
+ _context3.next = 24;
346
+ break;
347
+ case 20:
348
+ _context3.next = 22;
349
+ return Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage) || {
350
+ data: {}
351
+ });
352
+ case 22:
353
+ _res = _context3.sent;
354
+ dispatch({
355
+ type: 'setProEnumDic',
356
+ payload: _objectSpread({}, _res === null || _res === void 0 ? void 0 : _res.data)
357
+ });
358
+ case 24:
359
+ case "end":
360
+ return _context3.stop();
361
+ }
362
+ }, _callee3);
363
+ }));
364
+ return function executeAsync() {
365
+ return _ref4.apply(this, arguments);
283
366
  };
284
- dispatch({
285
- type: 'setProEnumDic',
286
- payload: _objectSpread({}, _res === null || _res === void 0 ? void 0 : _res.data)
287
- });
288
- }
367
+ }();
368
+ executeAsync();
289
369
  }, [useRequest === null || useRequest === void 0 ? void 0 : useRequest.options]);
290
- var shareProEnumDic = cacheData => {
291
- logDebug(cacheData);
292
- var storageData = getEnumData(storage, cacheKey, baseEnumStorage) || {
293
- data: {}
370
+ var shareProEnumDic = /*#__PURE__*/function () {
371
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(cacheData) {
372
+ var storageData;
373
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
374
+ while (1) switch (_context4.prev = _context4.next) {
375
+ case 0:
376
+ logDebug(cacheData);
377
+ _context4.next = 3;
378
+ return Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage) || {
379
+ data: {}
380
+ });
381
+ case 3:
382
+ storageData = _context4.sent;
383
+ dispatch({
384
+ type: 'setProEnumDic',
385
+ payload: _objectSpread(_objectSpread(_objectSpread({}, dataSource), cacheData), storageData)
386
+ });
387
+ case 5:
388
+ case "end":
389
+ return _context4.stop();
390
+ }
391
+ }, _callee4);
392
+ }));
393
+ return function shareProEnumDic(_x2) {
394
+ return _ref6.apply(this, arguments);
294
395
  };
295
- dispatch({
296
- type: 'setProEnumDic',
297
- payload: _objectSpread(_objectSpread(_objectSpread({}, dataSource), cacheData), storageData)
298
- });
299
- };
396
+ }();
300
397
  useEffect(() => {
301
398
  if (main) {
302
- var _locale$ProEnum7;
399
+ var _locale$ProEnum8;
303
400
  window.eventCenter.publish('zat-design-pro-component-event', {});
304
- logDebug(locale === null || locale === void 0 || (_locale$ProEnum7 = locale.ProEnum) === null || _locale$ProEnum7 === void 0 ? void 0 : _locale$ProEnum7.mainInitOnce);
401
+ logDebug(locale === null || locale === void 0 || (_locale$ProEnum8 = locale.ProEnum) === null || _locale$ProEnum8 === void 0 ? void 0 : _locale$ProEnum8.mainInitOnce);
305
402
  }
306
403
  if (!main && share) {
307
- var _locale$ProEnum8;
404
+ var _locale$ProEnum9;
308
405
  window.eventCenter.subscribe('zat-design-pro-component-event', shareProEnumDic);
309
- logDebug(locale === null || locale === void 0 || (_locale$ProEnum8 = locale.ProEnum) === null || _locale$ProEnum8 === void 0 ? void 0 : _locale$ProEnum8.sonInitEvent);
406
+ logDebug(locale === null || locale === void 0 || (_locale$ProEnum9 = locale.ProEnum) === null || _locale$ProEnum9 === void 0 ? void 0 : _locale$ProEnum9.sonInitEvent);
310
407
  }
311
408
  return () => {
312
409
  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;
@@ -37,20 +37,24 @@ var useFrequentEnumRequest = (props, dispatch) => {
37
37
  }
38
38
 
39
39
  // 确保response.data存在,如果不存在则使用response本身
40
- enumData = ((_response = response) === null || _response === void 0 ? void 0 : _response.data) || response; // 替换缓存中的指定枚举
41
- updatedCacheData = replaceFrequentEnumCache({
40
+ enumData = ((_response = response) === null || _response === void 0 ? void 0 : _response.data) || response; // 替换缓存中的指定枚举(支持异步)
41
+ _context.next = 5;
42
+ return Promise.resolve(replaceFrequentEnumCache({
42
43
  storage,
43
44
  cacheKey,
44
45
  enums: (frequentEnums === null || frequentEnums === void 0 ? void 0 : frequentEnums.enums) || [],
45
46
  newData: enumData,
46
47
  fieldNames,
47
48
  clear
48
- }); // 同步数据到全局状态
49
+ }));
50
+ case 5:
51
+ updatedCacheData = _context.sent;
52
+ // 同步数据到全局状态
49
53
  dispatch({
50
54
  type: 'setProEnumDic',
51
55
  payload: _objectSpread(_objectSpread(_objectSpread({}, dics), dataSource), updatedCacheData.data)
52
56
  });
53
- case 5:
57
+ case 7:
54
58
  case "end":
55
59
  return _context.stop();
56
60
  }
@@ -79,7 +79,12 @@ export interface ProEnumConfigType {
79
79
  * @description 字段别名
80
80
  * @default { label: 'label', value: 'value', children: 'children' }
81
81
  */
82
- fieldNames?: Record<'label' | 'value' | 'children', string>;
82
+ fieldNames?: {
83
+ label?: string;
84
+ value?: string;
85
+ children?: string;
86
+ [key: string]: string | undefined;
87
+ };
83
88
  /**
84
89
  * @description 缓存的key、默认 zat-design-pro-component-cacheKey
85
90
  * @default "zat-design-pro-component-cacheKey"
@@ -94,7 +99,7 @@ export interface ProEnumConfigType {
94
99
  * @description 存储位置、不设置、默认读取 globalConfig 里面的
95
100
  * @default "localStorage"
96
101
  */
97
- storage: 'localStorage' | 'sessionStorage';
102
+ storage: 'localStorage' | 'sessionStorage' | 'indexedDB';
98
103
  /**
99
104
  * @description 默认静态枚举数据
100
105
  * @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 频繁枚举配置