@zat-design/sisyphus-react 3.13.19-beta.3 → 3.13.19-beta.5

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.
@@ -42,7 +42,7 @@ var antdLangMap = {
42
42
  'en-US': enUS // en-US
43
43
  };
44
44
  var reducer = function reducer(state, action) {
45
- var _state$ProEnum, _state$ProEnum2;
45
+ var _state$ProEnum;
46
46
  switch (action.type) {
47
47
  case 'set':
48
48
  return _objectSpread(_objectSpread({}, state), action.payload);
@@ -59,7 +59,7 @@ var reducer = function reducer(state, action) {
59
59
  case 'setProEnumDic':
60
60
  return _objectSpread(_objectSpread({}, state), {}, {
61
61
  ProEnum: _objectSpread(_objectSpread({}, state.ProEnum), {}, {
62
- dics: _objectSpread(_objectSpread(_objectSpread({}, ((_state$ProEnum = state.ProEnum) === null || _state$ProEnum === void 0 ? void 0 : _state$ProEnum.dics) || {}), ((_state$ProEnum2 = state.ProEnum) === null || _state$ProEnum2 === void 0 ? void 0 : _state$ProEnum2.dataSource) || {}), action.payload)
62
+ dics: _objectSpread(_objectSpread({}, ((_state$ProEnum = state.ProEnum) === null || _state$ProEnum === void 0 ? void 0 : _state$ProEnum.dataSource) || {}), action.payload)
63
63
  })
64
64
  });
65
65
  default:
@@ -19,9 +19,7 @@ var useFrequentEnumRequest = function useFrequentEnumRequest(props, dispatch) {
19
19
  data: {}
20
20
  });
21
21
  }, _objectSpread(_objectSpread({
22
- manual: true,
23
- cacheTime: 0,
24
- staleTime: 0
22
+ manual: true
25
23
  }, frequentEnums === null || frequentEnums === void 0 ? void 0 : frequentEnums.options), {}, {
26
24
  onSuccess: function () {
27
25
  var _onSuccess = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(res) {
@@ -20,14 +20,14 @@ import _cloneDeep from "lodash/cloneDeep";
20
20
  var _excluded = ["code", "type", "dataSource", "useRequest", "value", "component", "onChange", "transformResponse", "otherProps", "isView"],
21
21
  _excluded2 = ["fieldNames", "clear", "storage", "cacheKey", "showCodeName", "useRequest", "transformResponse"];
22
22
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
23
- import { useDeepCompareEffect, useRequest as useRequestFunc } from 'ahooks';
23
+ import { useDeepCompareEffect, useRequest as useRequestFunc, useLocalStorageState } from 'ahooks';
24
24
  import React, { useState, useEffect, useMemo } from 'react';
25
25
  import ProSelect from '../ProSelect';
26
26
  import { useProConfig } from '../ProConfigProvider';
27
27
  import ProEnumTag from './components/Tag';
28
28
  import ProEnumGroup from './components/Group';
29
29
  import Container from '../ProForm/components/Container';
30
- import { isObject, getEnumData } from './utils';
30
+ import { isObject } from './utils';
31
31
  import getEnumLabel from './utils/getEnumLabel';
32
32
  import useEnum from './hooks/useEnum';
33
33
  import locale from '../locale';
@@ -67,7 +67,11 @@ var ProEnum = function ProEnum(props) {
67
67
  // 优先使用props中的配置,如果没有则使用全局配置
68
68
  var finalUseRequest = useRequest || configUseRequest;
69
69
  var finalTransformResponse = transformResponse || configTransformResponse;
70
- var cacheData = getEnumData(storage, cacheKey);
70
+ var _useLocalStorageState = useLocalStorageState(cacheKey, {
71
+ listenStorageChange: true
72
+ }),
73
+ _useLocalStorageState2 = _slicedToArray(_useLocalStorageState, 1),
74
+ cacheData = _useLocalStorageState2[0];
71
75
  var _isView = isView !== undefined && isView !== null ? isView : (_otherProps$isView = otherProps === null || otherProps === void 0 ? void 0 : otherProps.isView) !== null && _otherProps$isView !== void 0 ? _otherProps$isView : configIsView;
72
76
  enumProps.showCodeName = (_enumProps$showCodeNa = enumProps.showCodeName) !== null && _enumProps$showCodeNa !== void 0 ? _enumProps$showCodeNa : showCodeName;
73
77
  var label = 'label';
@@ -148,17 +152,22 @@ var ProEnum = function ProEnum(props) {
148
152
  }, [finalUseRequest === null || finalUseRequest === void 0 ? void 0 : finalUseRequest.options]);
149
153
  var enumLists = useMemo(function () {
150
154
  var lists = [];
155
+ var nextDics = dics;
156
+ if (cacheData && Object.keys(cacheData.data).length) {
157
+ nextDics = cacheData.data;
158
+ }
151
159
  if (_isString(code)) {
152
- lists = (dics === null || dics === void 0 ? void 0 : dics[code]) || [];
160
+ var _nextDics;
161
+ lists = ((_nextDics = nextDics) === null || _nextDics === void 0 ? void 0 : _nextDics[code]) || [];
153
162
  }
154
163
  if (_isArray(code)) {
155
164
  code.forEach(function (enumCode) {
156
- var _lists;
157
- _isArray(dics === null || dics === void 0 ? void 0 : dics[enumCode]) && (_lists = lists).push.apply(_lists, _toConsumableArray(dics === null || dics === void 0 ? void 0 : dics[enumCode]));
165
+ var _nextDics2, _lists, _nextDics3;
166
+ _isArray((_nextDics2 = nextDics) === null || _nextDics2 === void 0 ? void 0 : _nextDics2[enumCode]) && (_lists = lists).push.apply(_lists, _toConsumableArray((_nextDics3 = nextDics) === null || _nextDics3 === void 0 ? void 0 : _nextDics3[enumCode]));
158
167
  });
159
168
  }
160
169
  return lists;
161
- }, [dics, code]);
170
+ }, [dics, code, cacheData]);
162
171
  var renderComponent = function renderComponent() {
163
172
  var list = [];
164
173
  // 优先使用组件内部自己传入的数据源或者请求得到的数据
@@ -53,6 +53,7 @@ export function replaceFrequentEnumCache(params) {
53
53
  });
54
54
  }
55
55
  cacheData.data[code] = processedData;
56
+ cacheData.time = Date.now();
56
57
  }
57
58
  });
58
59
  setEnumData(storage, cacheKey, cacheData);
@@ -51,7 +51,7 @@ var antdLangMap = {
51
51
  'en-US': _en_US.default // en-US
52
52
  };
53
53
  var reducer = function reducer(state, action) {
54
- var _state$ProEnum, _state$ProEnum2;
54
+ var _state$ProEnum;
55
55
  switch (action.type) {
56
56
  case 'set':
57
57
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state), action.payload);
@@ -68,7 +68,7 @@ var reducer = function reducer(state, action) {
68
68
  case 'setProEnumDic':
69
69
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state), {}, {
70
70
  ProEnum: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state.ProEnum), {}, {
71
- dics: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, ((_state$ProEnum = state.ProEnum) === null || _state$ProEnum === void 0 ? void 0 : _state$ProEnum.dics) || {}), ((_state$ProEnum2 = state.ProEnum) === null || _state$ProEnum2 === void 0 ? void 0 : _state$ProEnum2.dataSource) || {}), action.payload)
71
+ dics: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ((_state$ProEnum = state.ProEnum) === null || _state$ProEnum === void 0 ? void 0 : _state$ProEnum.dataSource) || {}), action.payload)
72
72
  })
73
73
  });
74
74
  default:
@@ -26,9 +26,7 @@ var useFrequentEnumRequest = function useFrequentEnumRequest(props, dispatch) {
26
26
  data: {}
27
27
  });
28
28
  }, (0, _objectSpread2.default)((0, _objectSpread2.default)({
29
- manual: true,
30
- cacheTime: 0,
31
- staleTime: 0
29
+ manual: true
32
30
  }, frequentEnums === null || frequentEnums === void 0 ? void 0 : frequentEnums.options), {}, {
33
31
  onSuccess: function () {
34
32
  var _onSuccess = (0, _asyncToGenerator2.default)(/*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(res) {
@@ -75,7 +75,11 @@ var ProEnum = function ProEnum(props) {
75
75
  // 优先使用props中的配置,如果没有则使用全局配置
76
76
  var finalUseRequest = useRequest || configUseRequest;
77
77
  var finalTransformResponse = transformResponse || configTransformResponse;
78
- var cacheData = (0, _utils.getEnumData)(storage, cacheKey);
78
+ var _useLocalStorageState = (0, _ahooks.useLocalStorageState)(cacheKey, {
79
+ listenStorageChange: true
80
+ }),
81
+ _useLocalStorageState2 = (0, _slicedToArray2.default)(_useLocalStorageState, 1),
82
+ cacheData = _useLocalStorageState2[0];
79
83
  var _isView = isView !== undefined && isView !== null ? isView : (_otherProps$isView = otherProps === null || otherProps === void 0 ? void 0 : otherProps.isView) !== null && _otherProps$isView !== void 0 ? _otherProps$isView : configIsView;
80
84
  enumProps.showCodeName = (_enumProps$showCodeNa = enumProps.showCodeName) !== null && _enumProps$showCodeNa !== void 0 ? _enumProps$showCodeNa : showCodeName;
81
85
  var label = 'label';
@@ -156,17 +160,22 @@ var ProEnum = function ProEnum(props) {
156
160
  }, [finalUseRequest === null || finalUseRequest === void 0 ? void 0 : finalUseRequest.options]);
157
161
  var enumLists = (0, _react.useMemo)(function () {
158
162
  var lists = [];
163
+ var nextDics = dics;
164
+ if (cacheData && Object.keys(cacheData.data).length) {
165
+ nextDics = cacheData.data;
166
+ }
159
167
  if ((0, _isString2.default)(code)) {
160
- lists = (dics === null || dics === void 0 ? void 0 : dics[code]) || [];
168
+ var _nextDics;
169
+ lists = ((_nextDics = nextDics) === null || _nextDics === void 0 ? void 0 : _nextDics[code]) || [];
161
170
  }
162
171
  if ((0, _isArray2.default)(code)) {
163
172
  code.forEach(function (enumCode) {
164
- var _lists;
165
- (0, _isArray2.default)(dics === null || dics === void 0 ? void 0 : dics[enumCode]) && (_lists = lists).push.apply(_lists, (0, _toConsumableArray2.default)(dics === null || dics === void 0 ? void 0 : dics[enumCode]));
173
+ var _nextDics2, _lists, _nextDics3;
174
+ (0, _isArray2.default)((_nextDics2 = nextDics) === null || _nextDics2 === void 0 ? void 0 : _nextDics2[enumCode]) && (_lists = lists).push.apply(_lists, (0, _toConsumableArray2.default)((_nextDics3 = nextDics) === null || _nextDics3 === void 0 ? void 0 : _nextDics3[enumCode]));
166
175
  });
167
176
  }
168
177
  return lists;
169
- }, [dics, code]);
178
+ }, [dics, code, cacheData]);
170
179
  var renderComponent = function renderComponent() {
171
180
  var list = [];
172
181
  // 优先使用组件内部自己传入的数据源或者请求得到的数据
@@ -62,6 +62,7 @@ function replaceFrequentEnumCache(params) {
62
62
  });
63
63
  }
64
64
  cacheData.data[code] = processedData;
65
+ cacheData.time = Date.now();
65
66
  }
66
67
  });
67
68
  (0, _index.setEnumData)(storage, cacheKey, cacheData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.13.19-beta.3",
3
+ "version": "3.13.19-beta.5",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",