@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
|
@@ -3,7 +3,14 @@ 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;
|
|
@@ -44,25 +51,64 @@ var baseEnumStorage = (_ref = window.localStorage.getItem('zat-design-pro-compon
|
|
|
44
51
|
*/
|
|
45
52
|
|
|
46
53
|
function useEnum(codes, value, compose) {
|
|
47
|
-
var _ref2 = useProConfig('
|
|
54
|
+
var _ref2 = useProConfig('ProEnum') || {},
|
|
48
55
|
_ref2$storage = _ref2.storage,
|
|
49
|
-
storage = _ref2$storage === void 0 ? 'localStorage' : _ref2$storage
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
clear = _ref3$clear === void 0 ? true : _ref3$clear;
|
|
56
|
+
storage = _ref2$storage === void 0 ? 'localStorage' : _ref2$storage,
|
|
57
|
+
_ref2$cacheKey = _ref2.cacheKey,
|
|
58
|
+
cacheKey = _ref2$cacheKey === void 0 ? 'zat-design-pro-component-cacheKey' : _ref2$cacheKey,
|
|
59
|
+
_ref2$fieldNames = _ref2.fieldNames,
|
|
60
|
+
fieldNames = _ref2$fieldNames === void 0 ? {} : _ref2$fieldNames,
|
|
61
|
+
_ref2$clear = _ref2.clear,
|
|
62
|
+
clear = _ref2$clear === void 0 ? true : _ref2$clear;
|
|
57
63
|
|
|
58
64
|
// 存在子应用自管理枚举时,需要根据其指定的cacheKey进行缓存
|
|
59
65
|
if (cacheKey !== 'zat-design-pro-component-cacheKey') {
|
|
60
66
|
baseEnumStorage = null;
|
|
61
67
|
}
|
|
62
|
-
var catchData = getEnumData(storage, cacheKey, baseEnumStorage);
|
|
63
68
|
|
|
64
|
-
//
|
|
65
|
-
|
|
69
|
+
// 使用 state 来存储异步加载的数据
|
|
70
|
+
var _useState = useState(() => {
|
|
71
|
+
// 初始化:对于同步存储,直接返回数据;对于 IndexedDB,返回空数据
|
|
72
|
+
if (storage === 'indexedDB') {
|
|
73
|
+
return {
|
|
74
|
+
data: {}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return getEnumData(storage, cacheKey, baseEnumStorage) || {
|
|
78
|
+
data: {}
|
|
79
|
+
};
|
|
80
|
+
}),
|
|
81
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
82
|
+
enumData = _useState2[0],
|
|
83
|
+
setEnumData = _useState2[1];
|
|
84
|
+
|
|
85
|
+
// 异步加载 IndexedDB 数据
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (storage === 'indexedDB') {
|
|
88
|
+
Promise.resolve(getEnumData(storage, cacheKey, baseEnumStorage)).then(data => {
|
|
89
|
+
setEnumData(prevData => {
|
|
90
|
+
if (data && JSON.stringify(data) !== JSON.stringify(prevData)) {
|
|
91
|
+
baseEnumStorage = data;
|
|
92
|
+
return data || {
|
|
93
|
+
data: {}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return prevData;
|
|
97
|
+
});
|
|
98
|
+
}).catch(() => {
|
|
99
|
+
// 错误已在 getEnumData 中处理,这里只设置空数据
|
|
100
|
+
setEnumData({
|
|
101
|
+
data: {}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}, [storage, cacheKey]);
|
|
106
|
+
var catchData = storage === 'indexedDB' ? enumData : getEnumData(storage, cacheKey, baseEnumStorage);
|
|
107
|
+
|
|
108
|
+
// 默认枚举缓存数据(仅同步存储)
|
|
109
|
+
if (storage !== 'indexedDB') {
|
|
110
|
+
baseEnumStorage = catchData;
|
|
111
|
+
}
|
|
66
112
|
if (!codes) {
|
|
67
113
|
return catchData;
|
|
68
114
|
}
|
|
@@ -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
|
-
|
|
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
|
|
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$
|
|
184
|
+
var _locale$ProEnum5;
|
|
152
185
|
window.eventCenter.publish('zat-design-pro-component-event', res.data);
|
|
153
|
-
logDebug(locale === null || locale === void 0 || (_locale$
|
|
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$
|
|
164
|
-
throw new Error(locale === null || locale === void 0 || (_locale$
|
|
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$
|
|
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
|
-
|
|
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 =
|
|
214
|
+
_context2.next = 31;
|
|
179
215
|
break;
|
|
180
216
|
}
|
|
181
217
|
if (!(typeof cacheData.data === 'object' && cacheData.data !== null)) {
|
|
182
|
-
_context2.next =
|
|
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 =
|
|
227
|
+
_context2.next = 30;
|
|
192
228
|
break;
|
|
193
229
|
}
|
|
194
|
-
_context2.next =
|
|
230
|
+
_context2.next = 13;
|
|
195
231
|
return useRequest === null || useRequest === void 0 ? void 0 : useRequest.service();
|
|
196
|
-
case
|
|
232
|
+
case 13:
|
|
197
233
|
res = _context2.sent;
|
|
198
234
|
if (!(transformResponse && typeof transformResponse === 'function')) {
|
|
199
|
-
_context2.next =
|
|
235
|
+
_context2.next = 22;
|
|
200
236
|
break;
|
|
201
237
|
}
|
|
202
|
-
_context2.next =
|
|
238
|
+
_context2.next = 17;
|
|
203
239
|
return transformResponse(res);
|
|
204
|
-
case
|
|
240
|
+
case 17:
|
|
205
241
|
response = _context2.sent;
|
|
206
242
|
if (!(typeof response !== 'object' || response == null)) {
|
|
207
|
-
_context2.next =
|
|
243
|
+
_context2.next = 20;
|
|
208
244
|
break;
|
|
209
245
|
}
|
|
210
|
-
throw new Error(locale === null || locale === void 0 || (_locale$
|
|
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
|
|
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
|
-
|
|
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 =
|
|
277
|
+
_context2.next = 31;
|
|
240
278
|
break;
|
|
241
|
-
case
|
|
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
|
|
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
|
-
|
|
261
|
-
var _ref4 = (
|
|
262
|
-
defaultParams
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
285
|
-
|
|
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 =
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
296
|
-
type: 'setProEnumDic',
|
|
297
|
-
payload: _objectSpread(_objectSpread(_objectSpread({}, dataSource), cacheData), storageData)
|
|
298
|
-
});
|
|
299
|
-
};
|
|
396
|
+
}();
|
|
300
397
|
useEffect(() => {
|
|
301
398
|
if (main) {
|
|
302
|
-
var _locale$
|
|
399
|
+
var _locale$ProEnum8;
|
|
303
400
|
window.eventCenter.publish('zat-design-pro-component-event', {});
|
|
304
|
-
logDebug(locale === null || locale === void 0 || (_locale$
|
|
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$
|
|
404
|
+
var _locale$ProEnum9;
|
|
308
405
|
window.eventCenter.subscribe('zat-design-pro-component-event', shareProEnumDic);
|
|
309
|
-
logDebug(locale === null || locale === void 0 || (_locale$
|
|
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
|
-
|
|
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
|
|
57
|
+
case 7:
|
|
54
58
|
case "end":
|
|
55
59
|
return _context.stop();
|
|
56
60
|
}
|
|
@@ -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 频繁枚举配置
|
|
@@ -1,19 +1,72 @@
|
|
|
1
|
+
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; }
|
|
1
2
|
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; }
|
|
2
3
|
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; }
|
|
3
4
|
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; }
|
|
4
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
5
6
|
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); }
|
|
7
|
+
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); } }
|
|
8
|
+
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); }); }; }
|
|
6
9
|
import { getEnumData, setEnumData, cacheFieldNames } from "./index";
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* 替换频繁枚举缓存数据的参数接口
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
/**
|
|
15
|
+
* IndexedDB 异步版本的替换频繁枚举缓存数据
|
|
16
|
+
*/
|
|
17
|
+
function replaceFrequentEnumCacheAsync(_x) {
|
|
18
|
+
return _replaceFrequentEnumCacheAsync.apply(this, arguments);
|
|
19
|
+
}
|
|
12
20
|
/**
|
|
13
21
|
* 替换频繁枚举缓存数据
|
|
14
22
|
* @param params 参数对象
|
|
15
23
|
* @returns 更新后的缓存数据
|
|
16
24
|
*/
|
|
25
|
+
function _replaceFrequentEnumCacheAsync() {
|
|
26
|
+
_replaceFrequentEnumCacheAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
27
|
+
var storage, cacheKey, enums, newData, fieldNames, clear, cacheData;
|
|
28
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
29
|
+
while (1) switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
storage = params.storage, cacheKey = params.cacheKey, enums = params.enums, newData = params.newData, fieldNames = params.fieldNames, clear = params.clear;
|
|
32
|
+
_context.next = 3;
|
|
33
|
+
return Promise.resolve(getEnumData(storage, cacheKey) || {
|
|
34
|
+
data: {}
|
|
35
|
+
});
|
|
36
|
+
case 3:
|
|
37
|
+
cacheData = _context.sent;
|
|
38
|
+
// 确保cacheData.data存在
|
|
39
|
+
if (!cacheData.data) {
|
|
40
|
+
cacheData.data = {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 只替换指定的枚举
|
|
44
|
+
enums.forEach(code => {
|
|
45
|
+
if (newData[code]) {
|
|
46
|
+
var processedData = newData[code];
|
|
47
|
+
|
|
48
|
+
// 应用数据清洗逻辑
|
|
49
|
+
if (clear && Array.isArray(processedData)) {
|
|
50
|
+
processedData = processedData.map(item => {
|
|
51
|
+
return cacheFieldNames(fieldNames, item);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
cacheData.data[code] = processedData;
|
|
55
|
+
cacheData.time = Date.now();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
_context.next = 8;
|
|
59
|
+
return Promise.resolve(setEnumData(storage, cacheKey, cacheData));
|
|
60
|
+
case 8:
|
|
61
|
+
return _context.abrupt("return", cacheData);
|
|
62
|
+
case 9:
|
|
63
|
+
case "end":
|
|
64
|
+
return _context.stop();
|
|
65
|
+
}
|
|
66
|
+
}, _callee);
|
|
67
|
+
}));
|
|
68
|
+
return _replaceFrequentEnumCacheAsync.apply(this, arguments);
|
|
69
|
+
}
|
|
17
70
|
export function replaceFrequentEnumCache(params) {
|
|
18
71
|
var _params$storage = params.storage,
|
|
19
72
|
storage = _params$storage === void 0 ? 'localStorage' : _params$storage,
|
|
@@ -45,7 +98,17 @@ export function replaceFrequentEnumCache(params) {
|
|
|
45
98
|
data: {}
|
|
46
99
|
};
|
|
47
100
|
}
|
|
48
|
-
|
|
101
|
+
|
|
102
|
+
// IndexedDB 异步处理
|
|
103
|
+
if (storage === 'indexedDB') {
|
|
104
|
+
return replaceFrequentEnumCacheAsync(params);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// localStorage/sessionStorage 同步处理(保持原逻辑)
|
|
108
|
+
var cacheDataResult = getEnumData(storage, cacheKey);
|
|
109
|
+
// getEnumData 对于非 indexedDB 返回同步值,对于 indexedDB 返回 Promise
|
|
110
|
+
// 这里 storage 不是 indexedDB,所以是同步值
|
|
111
|
+
var cacheData = cacheDataResult || {
|
|
49
112
|
data: {}
|
|
50
113
|
};
|
|
51
114
|
|