@zat-design/sisyphus-react 4.5.10-beta.1 → 4.5.10-beta.2
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/FormsProvider/index.js +14 -21
- package/es/ProAction/components/CheckModalContent/index.js +12 -26
- package/es/ProAction/index.js +79 -83
- package/es/ProAction/propsType.js +0 -1
- package/es/ProConfigProvider/index.js +63 -110
- package/es/ProConfigProvider/propsType.js +0 -1
- package/es/ProDownload/index.js +55 -65
- package/es/ProDownload/propsType.js +0 -1
- package/es/ProDownload/utils.js +61 -95
- package/es/ProDrawerForm/components/ProDrawer/index.js +83 -113
- package/es/ProDrawerForm/components/ProModal/index.js +77 -108
- package/es/ProDrawerForm/components/index.js +6 -2
- package/es/ProDrawerForm/hooks/useConfirmClose.js +20 -39
- package/es/ProDrawerForm/index.js +29 -38
- package/es/ProDrawerForm/propsType.js +0 -1
- package/es/ProDrawerForm/utils/index.js +18 -36
- package/es/ProEditLabel/components/RenderProForm.js +45 -49
- package/es/ProEditLabel/index.js +126 -163
- package/es/ProEditLabel/propsType.js +0 -1
- package/es/ProEditLabel/utils/index.js +5 -8
- package/es/ProEditTable/components/ActionButton/index.js +111 -119
- package/es/ProEditTable/components/RcTable/BaseTable.js +38 -51
- package/es/ProEditTable/components/RcTable/DraggableTable.js +97 -129
- package/es/ProEditTable/components/RcTable/index.js +6 -4
- package/es/ProEditTable/components/RenderField/ListChangedWrapper.js +77 -95
- package/es/ProEditTable/components/RenderField/index.js +490 -587
- package/es/ProEditTable/components/RenderField/propsType.js +0 -1
- package/es/ProEditTable/components/RenderField/tools.js +115 -112
- package/es/ProEditTable/components/RenderToolbar/index.js +47 -73
- package/es/ProEditTable/components/Summary/index.js +38 -64
- package/es/ProEditTable/components/Validator/index.js +46 -46
- package/es/ProEditTable/components/index.js +12 -5
- package/es/ProEditTable/index.js +456 -378
- package/es/ProEditTable/propsType.js +0 -1
- package/es/ProEditTable/utils/config.js +60 -122
- package/es/ProEditTable/utils/diffOriginal.js +45 -82
- package/es/ProEditTable/utils/getDefaultProps.js +19 -24
- package/es/ProEditTable/utils/index.js +150 -236
- package/es/ProEditTable/utils/tools.js +149 -286
- package/es/ProEditTable/utils/transform.js +25 -30
- package/es/ProEditTable/utils/useEditTableError.js +30 -43
- package/es/ProEditTable/utils/useShouldUpdateForTable.js +42 -72
- package/es/ProEditTable/utils/validateAll.js +87 -154
- package/es/ProEnum/components/Group.js +38 -30
- package/es/ProEnum/components/Tag.js +22 -26
- package/es/ProEnum/hooks/useEnum.js +48 -116
- package/es/ProEnum/hooks/useEnumRequest.js +128 -179
- package/es/ProEnum/hooks/useFrequentEnumRequest.js +40 -48
- package/es/ProEnum/index.js +162 -172
- package/es/ProEnum/propsType.js +0 -1
- package/es/ProEnum/utils/eventCenter.js +10 -12
- package/es/ProEnum/utils/frequentEnum.js +35 -92
- package/es/ProEnum/utils/getEnum.js +32 -90
- package/es/ProEnum/utils/getEnumLabel.js +44 -49
- package/es/ProEnum/utils/index.js +93 -207
- package/es/ProForm/components/Container.js +13 -28
- package/es/ProForm/components/FormFooter/index.js +36 -44
- package/es/ProForm/components/FormFooter/propsType.js +0 -1
- package/es/ProForm/components/base/Checkbox/index.js +32 -59
- package/es/ProForm/components/base/DatePicker/index.js +49 -71
- package/es/ProForm/components/base/Input/index.js +63 -97
- package/es/ProForm/components/base/Input/propsType.js +0 -1
- package/es/ProForm/components/base/InputNumber/index.js +118 -172
- package/es/ProForm/components/base/Radio/index.js +39 -52
- package/es/ProForm/components/base/RangePicker/index.js +109 -127
- package/es/ProForm/components/base/RangePicker/useDateRange.js +20 -17
- package/es/ProForm/components/base/Select/index.js +63 -89
- package/es/ProForm/components/base/Switch/index.js +27 -35
- package/es/ProForm/components/base/SwitchCheckbox/index.js +36 -54
- package/es/ProForm/components/base/TextArea/index.js +30 -41
- package/es/ProForm/components/base/TimePicker/index.js +27 -37
- package/es/ProForm/components/combination/Container/index.js +37 -47
- package/es/ProForm/components/combination/Container/propsType.js +0 -1
- package/es/ProForm/components/combination/FormList/components/ActionButton.js +165 -237
- package/es/ProForm/components/combination/FormList/components/BlockFields.js +98 -103
- package/es/ProForm/components/combination/FormList/components/Empty.js +27 -54
- package/es/ProForm/components/combination/FormList/components/LineFields.js +57 -54
- package/es/ProForm/components/combination/FormList/components/ToolbarButton.js +61 -109
- package/es/ProForm/components/combination/FormList/index.js +151 -161
- package/es/ProForm/components/combination/FormList/propsType.js +0 -1
- package/es/ProForm/components/combination/FormList/utils.js +22 -38
- package/es/ProForm/components/combination/Group/component/AddonWrapper/index.js +12 -28
- package/es/ProForm/components/combination/Group/component/ComRender.js +50 -111
- package/es/ProForm/components/combination/Group/component/FlexibleGroup.js +105 -206
- package/es/ProForm/components/combination/Group/hooks/index.js +68 -128
- package/es/ProForm/components/combination/Group/index.js +87 -126
- package/es/ProForm/components/combination/Group/propsType.js +0 -1
- package/es/ProForm/components/combination/Group/utils/index.js +124 -239
- package/es/ProForm/components/combination/ProCascader/index.js +156 -199
- package/es/ProForm/components/combination/ProCascader/propsType.js +0 -1
- package/es/ProForm/components/combination/ProCascader/utils/index.js +12 -21
- package/es/ProForm/components/combination/ProModalSelect/hooks/useRequestList.js +63 -75
- package/es/ProForm/components/combination/ProModalSelect/index.js +290 -348
- package/es/ProForm/components/combination/ProModalSelect/propsType.js +0 -1
- package/es/ProForm/components/combination/ProModalSelect/utils/index.js +32 -39
- package/es/ProForm/components/combination/ProNumberRange/index.js +100 -156
- package/es/ProForm/components/combination/ProNumberRange/propsType.js +0 -1
- package/es/ProForm/components/combination/ProRangeLimit/index.js +104 -115
- package/es/ProForm/components/combination/ProRangeLimit/propsType.js +0 -1
- package/es/ProForm/components/combination/ProTimeLimit/hooks/useControlled.js +16 -16
- package/es/ProForm/components/combination/ProTimeLimit/index.js +75 -109
- package/es/ProForm/components/index.js +56 -34
- package/es/ProForm/components/render/ChangedWrapper.js +85 -94
- package/es/ProForm/components/render/ConfirmWrapper.js +27 -39
- package/es/ProForm/components/render/CustomComponentViewWrapper.js +65 -82
- package/es/ProForm/components/render/Render.js +223 -329
- package/es/ProForm/components/render/RenderFields.js +76 -113
- package/es/ProForm/components/render/propsType.js +0 -1
- package/es/ProForm/hooks/useControlled.js +8 -10
- package/es/ProForm/hooks/useDeepCompareMemo.js +11 -11
- package/es/ProForm/hooks/useFieldProps.js +8 -4
- package/es/ProForm/hooks/useForm.js +50 -110
- package/es/ProForm/hooks/useRules.js +17 -33
- package/es/ProForm/hooks/useShouldUpdate.js +77 -152
- package/es/ProForm/hooks/useWatch.js +58 -129
- package/es/ProForm/index.js +157 -194
- package/es/ProForm/propsType.js +15 -7
- package/es/ProForm/utils/buildFormItemProps.js +51 -58
- package/es/ProForm/utils/diffOriginal.js +43 -73
- package/es/ProForm/utils/getDefaultProps.js +18 -24
- package/es/ProForm/utils/index.js +159 -234
- package/es/ProForm/utils/processDependencies.js +21 -60
- package/es/ProForm/utils/reactiveValues.js +20 -34
- package/es/ProForm/utils/rulesCreator.js +42 -40
- package/es/ProForm/utils/transformNames.js +10 -13
- package/es/ProForm/utils/transformValue.js +16 -29
- package/es/ProForm/utils/valueType.js +96 -178
- package/es/ProIcon/config/index.js +340 -274
- package/es/ProIcon/index.js +135 -209
- package/es/ProIcon/propsTypes.js +0 -1
- package/es/ProIcon/utils/index.js +24 -39
- package/es/ProLayout/components/Layout/Header/index.js +108 -141
- package/es/ProLayout/components/Layout/Menu/FoldMenu/index.js +134 -190
- package/es/ProLayout/components/Layout/Menu/OpenMenu/index.js +111 -137
- package/es/ProLayout/components/Layout/Menu/OpenMenu/propsType.js +0 -1
- package/es/ProLayout/components/Layout/Menu/SideMenu/index.js +23 -31
- package/es/ProLayout/components/Layout/Menu/index.js +92 -89
- package/es/ProLayout/components/Layout/Notice/index.js +13 -27
- package/es/ProLayout/components/Layout/index.js +8 -3
- package/es/ProLayout/components/ProCollapse/PropTypes.js +0 -1
- package/es/ProLayout/components/ProCollapse/index.js +89 -111
- package/es/ProLayout/components/ProFooter/PropTypes.js +0 -1
- package/es/ProLayout/components/ProFooter/index.js +27 -25
- package/es/ProLayout/components/ProHeader/PropTypes.js +0 -1
- package/es/ProLayout/components/ProHeader/components/Copy/index.js +23 -21
- package/es/ProLayout/components/ProHeader/components/Describe/index.js +67 -86
- package/es/ProLayout/components/ProHeader/components/ProBackBtn/index.js +18 -21
- package/es/ProLayout/components/ProHeader/components/ProBackBtn/propsType.js +0 -1
- package/es/ProLayout/components/ProHeader/components/index.js +6 -2
- package/es/ProLayout/components/ProHeader/index.js +216 -356
- package/es/ProLayout/components/ProHeader/utils/index.js +19 -26
- package/es/ProLayout/components/TabsManager/components/TabContextMenu.js +92 -85
- package/es/ProLayout/components/TabsManager/components/TabItem.js +53 -64
- package/es/ProLayout/components/TabsManager/components/TabsContext.js +5 -5
- package/es/ProLayout/components/TabsManager/components/TabsHeader.js +42 -52
- package/es/ProLayout/components/TabsManager/hooks/useActiveTab.js +8 -9
- package/es/ProLayout/components/TabsManager/hooks/useIframeRoute.js +19 -32
- package/es/ProLayout/components/TabsManager/hooks/useProLayoutTabs.js +6 -20
- package/es/ProLayout/components/TabsManager/hooks/useTabsCache.js +25 -42
- package/es/ProLayout/components/TabsManager/hooks/useTabsState.js +290 -408
- package/es/ProLayout/components/TabsManager/hooks/useTabsUrlSync.js +132 -95
- package/es/ProLayout/components/TabsManager/index.js +406 -390
- package/es/ProLayout/components/TabsManager/propTypes.js +7 -15
- package/es/ProLayout/components/TabsManager/utils/historyObserver.js +26 -23
- package/es/ProLayout/components/TabsManager/utils/index.js +127 -184
- package/es/ProLayout/components/index.js +8 -3
- package/es/ProLayout/index.js +171 -229
- package/es/ProLayout/propTypes.js +12 -52
- package/es/ProLayout/utils/index.js +48 -128
- package/es/ProSelect/components/AdaptiveTooltip.js +26 -25
- package/es/ProSelect/index.js +184 -229
- package/es/ProSelect/propsType.js +0 -1
- package/es/ProSelect/utils/index.js +100 -146
- package/es/ProStep/components/Anchor/index.js +71 -82
- package/es/ProStep/components/Item/index.js +49 -56
- package/es/ProStep/components/LazyLoad/index.js +23 -29
- package/es/ProStep/components/Listener/index.js +20 -33
- package/es/ProStep/components/Step/index.js +31 -38
- package/es/ProStep/constants.js +4 -1
- package/es/ProStep/index.js +166 -153
- package/es/ProStep/propsType.js +0 -1
- package/es/ProStep/utils/index.js +29 -55
- package/es/ProStepTab/index.js +83 -138
- package/es/ProStepTab/propsType.js +0 -1
- package/es/ProTable/components/EditableCell/EditIcon.js +10 -14
- package/es/ProTable/components/EditableCell/index.js +37 -71
- package/es/ProTable/components/EditableCell/propsType.js +0 -1
- package/es/ProTable/components/FormatColumn/index.js +209 -340
- package/es/ProTable/components/FormatColumn/propsType.js +0 -1
- package/es/ProTable/components/RcTable/components/BaseTable/index.js +35 -39
- package/es/ProTable/components/RcTable/components/DraggableTable/components/DndWrapper/index.js +80 -107
- package/es/ProTable/components/RcTable/components/DraggableTable/components/DndWrapper/utils/index.js +54 -48
- package/es/ProTable/components/RcTable/components/DraggableTable/components/DndWrapper/utils/propsType.js +0 -1
- package/es/ProTable/components/RcTable/components/DraggableTable/index.js +47 -54
- package/es/ProTable/components/RcTable/index.js +6 -4
- package/es/ProTable/components/RenderColumn/index.js +158 -186
- package/es/ProTable/components/RenderEmptyText/index.js +12 -21
- package/es/ProTable/components/RenderFooter/index.js +15 -15
- package/es/ProTable/components/RenderSummary/index.js +33 -50
- package/es/ProTable/components/RenderTableHeader/index.js +44 -46
- package/es/ProTable/components/RenderTabs/index.js +47 -51
- package/es/ProTable/components/TableResizable/index.js +56 -72
- package/es/ProTable/components/TooltipTitle/index.js +13 -21
- package/es/ProTable/components/index.js +16 -36
- package/es/ProTable/hooks/useAntdTable.js +185 -219
- package/es/ProTable/index.js +232 -249
- package/es/ProTable/propsType.js +0 -1
- package/es/ProTable/utils/columnStorage.js +63 -88
- package/es/ProTable/utils/index.js +57 -90
- package/es/ProTabs/components/Card/index.js +20 -48
- package/es/ProTabs/components/index.js +4 -1
- package/es/ProTabs/index.js +39 -56
- package/es/ProTabs/propType.js +0 -1
- package/es/ProThemeTools/component/ProTools/index.js +106 -158
- package/es/ProThemeTools/component/index.js +4 -1
- package/es/ProThemeTools/context/ThemeContext.js +67 -146
- package/es/ProThemeTools/index.js +103 -156
- package/es/ProThemeTools/propsType.js +0 -1
- package/es/ProThemeTools/utils/index.js +60 -109
- package/es/ProTooltip/index.js +132 -165
- package/es/ProTooltip/propsType.js +0 -1
- package/es/ProTree/components/AdaptiveTooltip.js +15 -17
- package/es/ProTree/components/CloseIcon.js +18 -26
- package/es/ProTree/components/List.js +28 -47
- package/es/ProTree/components/ProTree.js +152 -211
- package/es/ProTree/components/ProTreeSelect/index.js +254 -458
- package/es/ProTree/components/ProTreeSelect/propsType.js +0 -1
- package/es/ProTree/components/SearchTitle.js +23 -42
- package/es/ProTree/components/Tree.js +147 -195
- package/es/ProTree/components/index.js +10 -5
- package/es/ProTree/index.js +12 -16
- package/es/ProTree/propsType.js +0 -1
- package/es/ProTree/utils.js +46 -118
- package/es/ProTreeModal/components/Cascader.js +56 -64
- package/es/ProTreeModal/components/CloseIcon.js +18 -26
- package/es/ProTreeModal/components/List.js +114 -180
- package/es/ProTreeModal/components/SearchTitle.js +15 -18
- package/es/ProTreeModal/components/SortableItem.js +29 -58
- package/es/ProTreeModal/components/Tree.js +99 -113
- package/es/ProTreeModal/components/Trigger.js +87 -121
- package/es/ProTreeModal/components/index.js +14 -6
- package/es/ProTreeModal/index.js +397 -435
- package/es/ProTreeModal/propsType.js +0 -1
- package/es/ProTreeModal/utils.js +52 -95
- package/es/ProUpload/components/ButtonRender.js +44 -54
- package/es/ProUpload/components/DragRender.js +94 -134
- package/es/ProUpload/components/DraggableUploadListItem.js +12 -25
- package/es/ProUpload/components/Example.js +27 -31
- package/es/ProUpload/components/FileItem.js +69 -163
- package/es/ProUpload/components/ImageRender.js +134 -170
- package/es/ProUpload/index.js +68 -100
- package/es/ProUpload/propsType.js +0 -1
- package/es/ProUpload/uitls.js +8 -4
- package/es/ProUtils/utils/index.js +17 -13
- package/es/ProViewer/index.js +154 -175
- package/es/ProViewer/propsType.js +0 -5
- package/es/ProWaterMark/index.js +9 -16
- package/es/ProWaterMark/propsType.js +0 -1
- package/es/hooks/useDraggableRow.js +25 -53
- package/es/index.js +57 -77
- package/es/locale/en_US.js +153 -142
- package/es/locale/index.js +23 -36
- package/es/locale/zh_CN.js +145 -142
- package/es/tokens.js +84 -83
- package/es/utils/index.js +24 -51
- package/package.json +4 -3
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef } from
|
|
2
|
-
import { useDeepCompareEffect, useRequest as useRequestFunc } from
|
|
3
|
-
import {
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { useDeepCompareEffect, useRequest as useRequestFunc } from "ahooks";
|
|
3
|
+
import {
|
|
4
|
+
diffCode,
|
|
5
|
+
getEnumData,
|
|
6
|
+
setEnumData,
|
|
7
|
+
removeEnumData,
|
|
8
|
+
cacheFieldNames,
|
|
9
|
+
cleanEnumResponse,
|
|
10
|
+
baseCacheKey,
|
|
11
|
+
baseStorage
|
|
12
|
+
} from "../utils";
|
|
4
13
|
import locale from "../../locale";
|
|
5
14
|
import "../utils/eventCenter";
|
|
6
15
|
const useEnumRequest = (props, dispatch) => {
|
|
16
|
+
var _a, _b;
|
|
7
17
|
const {
|
|
8
18
|
main = false,
|
|
9
19
|
share = false,
|
|
10
20
|
clear = true,
|
|
11
21
|
fieldNames = {
|
|
12
|
-
label:
|
|
13
|
-
value:
|
|
14
|
-
children:
|
|
22
|
+
label: "label",
|
|
23
|
+
value: "value",
|
|
24
|
+
children: "children"
|
|
15
25
|
},
|
|
16
26
|
cacheKey = baseCacheKey,
|
|
17
27
|
requestRefresh = false,
|
|
@@ -21,34 +31,27 @@ const useEnumRequest = (props, dispatch) => {
|
|
|
21
31
|
transformResponse,
|
|
22
32
|
dics = {}
|
|
23
33
|
} = props || {};
|
|
24
|
-
if (typeof dataSource ===
|
|
25
|
-
throw new Error(locale
|
|
34
|
+
if (typeof dataSource === "object" && dataSource === null) {
|
|
35
|
+
throw new Error((_b = (_a = locale) == null ? void 0 : _a.ProEnum) == null ? void 0 : _b.errorDataSource);
|
|
26
36
|
}
|
|
27
|
-
const logDebug = msg => {
|
|
37
|
+
const logDebug = (msg) => {
|
|
28
38
|
if (props.debugger) {
|
|
29
|
-
console.warn(
|
|
39
|
+
console.warn("proEnum:", msg);
|
|
30
40
|
}
|
|
31
41
|
};
|
|
32
|
-
|
|
33
|
-
// IndexedDB 缓存策略:包装 service,在 service 层面返回缓存数据,
|
|
34
|
-
// 而非跳过 run()。这样 enumRes.data/loading 正常变更,
|
|
35
|
-
// ProConfigProvider 的 onSuccess 回调能正常触发(修复白屏问题)。
|
|
36
42
|
const fromCacheRef = useRef(null);
|
|
37
43
|
const errorReportedRef = useRef(false);
|
|
38
|
-
const originalService = useRequest
|
|
44
|
+
const originalService = useRequest == null ? void 0 : useRequest.service;
|
|
39
45
|
const serviceForRequest = useMemo(() => {
|
|
40
|
-
if (!originalService || storage !==
|
|
46
|
+
if (!originalService || storage !== "indexedDB") {
|
|
41
47
|
return originalService;
|
|
42
48
|
}
|
|
43
49
|
return async (...args) => {
|
|
44
50
|
if (!requestRefresh) {
|
|
45
51
|
const cached = await Promise.resolve(getEnumData(storage, cacheKey));
|
|
46
|
-
if (cached
|
|
52
|
+
if ((cached == null ? void 0 : cached.data) && Object.keys(cached.data).length > 0 && (cached == null ? void 0 : cached.time) && Date.now() - cached.time <= 6e4 * 60) {
|
|
47
53
|
fromCacheRef.current = cached.data;
|
|
48
|
-
return {
|
|
49
|
-
status: 200,
|
|
50
|
-
data: cached.data
|
|
51
|
-
};
|
|
54
|
+
return { status: 200, data: cached.data };
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
fromCacheRef.current = null;
|
|
@@ -56,68 +59,64 @@ const useEnumRequest = (props, dispatch) => {
|
|
|
56
59
|
};
|
|
57
60
|
}, [originalService, storage, requestRefresh, cacheKey]);
|
|
58
61
|
const reportBackgroundError = (error, params = []) => {
|
|
62
|
+
var _a2, _b2;
|
|
59
63
|
if (errorReportedRef.current) {
|
|
60
64
|
return;
|
|
61
65
|
}
|
|
62
66
|
errorReportedRef.current = true;
|
|
63
67
|
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
64
|
-
useRequest
|
|
68
|
+
(_b2 = (_a2 = useRequest == null ? void 0 : useRequest.options) == null ? void 0 : _a2.onError) == null ? void 0 : _b2.call(_a2, normalizedError, params);
|
|
65
69
|
};
|
|
66
70
|
const enumRes = useRequestFunc(serviceForRequest, {
|
|
67
71
|
manual: true,
|
|
68
72
|
cacheKey,
|
|
69
73
|
cacheTime: -1,
|
|
70
74
|
staleTime: 6e4 * 60,
|
|
71
|
-
...useRequest
|
|
72
|
-
onBefore: params => {
|
|
75
|
+
...useRequest == null ? void 0 : useRequest.options,
|
|
76
|
+
onBefore: (params) => {
|
|
77
|
+
var _a2, _b2;
|
|
73
78
|
errorReportedRef.current = false;
|
|
74
|
-
useRequest
|
|
79
|
+
(_b2 = (_a2 = useRequest == null ? void 0 : useRequest.options) == null ? void 0 : _a2.onBefore) == null ? void 0 : _b2.call(_a2, params);
|
|
75
80
|
},
|
|
76
81
|
onError: reportBackgroundError,
|
|
77
|
-
setCache: async res => {
|
|
82
|
+
setCache: async (res) => {
|
|
83
|
+
var _a2, _b2, _c;
|
|
78
84
|
try {
|
|
79
|
-
// 缓存命中时跳过 transformResponse 和重复处理,直接 dispatch
|
|
80
85
|
if (fromCacheRef.current) {
|
|
81
86
|
const cachedData = fromCacheRef.current;
|
|
82
|
-
const
|
|
83
|
-
...dics,
|
|
84
|
-
...cachedData,
|
|
85
|
-
...dataSource
|
|
86
|
-
};
|
|
87
|
+
const mergedPayload2 = { ...dics, ...cachedData, ...dataSource };
|
|
87
88
|
dispatch({
|
|
88
|
-
type:
|
|
89
|
-
payload:
|
|
89
|
+
type: "setProEnumDic",
|
|
90
|
+
payload: mergedPayload2
|
|
90
91
|
});
|
|
91
92
|
if (main) {
|
|
92
93
|
setTimeout(() => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
var _a3, _b3, _c2;
|
|
95
|
+
(_a3 = window == null ? void 0 : window.eventCenter) == null ? void 0 : _a3.publish("pro-enum-event", cachedData);
|
|
96
|
+
logDebug((_c2 = (_b3 = locale) == null ? void 0 : _b3.ProEnum) == null ? void 0 : _c2.mainInitByCache);
|
|
97
|
+
}, 1e4);
|
|
96
98
|
}
|
|
97
99
|
fromCacheRef.current = null;
|
|
98
100
|
return res;
|
|
99
101
|
}
|
|
100
102
|
let response = res.data;
|
|
101
|
-
if (transformResponse && typeof transformResponse ===
|
|
103
|
+
if (transformResponse && typeof transformResponse === "function") {
|
|
102
104
|
response = await transformResponse(res.data);
|
|
103
|
-
if (typeof response !==
|
|
104
|
-
throw new Error(locale
|
|
105
|
+
if (typeof response !== "object" || response == null) {
|
|
106
|
+
throw new Error((_b2 = (_a2 = locale) == null ? void 0 : _a2.ProEnum) == null ? void 0 : _b2.errorMessage);
|
|
105
107
|
} else {
|
|
106
108
|
res.data = response;
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
|
-
if (typeof response !==
|
|
110
|
-
throw Error(
|
|
111
|
+
if (typeof response !== "object" || response === null) {
|
|
112
|
+
throw Error("response enum data must be object");
|
|
111
113
|
}
|
|
112
114
|
if (Object.keys(response).length === 0) {
|
|
113
|
-
throw Error(
|
|
115
|
+
throw Error("Please return valid enumeration data");
|
|
114
116
|
}
|
|
115
|
-
|
|
116
|
-
// 只返回fieldNames对象的key
|
|
117
117
|
if (clear) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
Object.keys(response).forEach(key => {
|
|
118
|
+
const ignoreCodes = ((_c = useRequest == null ? void 0 : useRequest.options) == null ? void 0 : _c.ignoreCodes) || [];
|
|
119
|
+
Object.keys(response).forEach((key) => {
|
|
121
120
|
if (!response[key] || !Array.isArray(response[key])) {
|
|
122
121
|
return;
|
|
123
122
|
}
|
|
@@ -125,43 +124,30 @@ const useEnumRequest = (props, dispatch) => {
|
|
|
125
124
|
if (ignoreCodes.includes(key)) {
|
|
126
125
|
response[key] = options;
|
|
127
126
|
} else {
|
|
128
|
-
response[key] = options.map(item => {
|
|
127
|
+
response[key] = options.map((item) => {
|
|
129
128
|
return cacheFieldNames(fieldNames, item);
|
|
130
129
|
});
|
|
131
130
|
}
|
|
132
131
|
});
|
|
133
132
|
res.data = response;
|
|
134
133
|
}
|
|
135
|
-
|
|
136
|
-
// 获取缓存数据(支持异步)
|
|
137
|
-
const cacheData = await Promise.resolve(getEnumData(storage, cacheKey) || {
|
|
138
|
-
data: {}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// 合并缓存数据
|
|
134
|
+
const cacheData = await Promise.resolve(getEnumData(storage, cacheKey) || { data: {} });
|
|
142
135
|
res.data = {
|
|
143
|
-
...cacheData
|
|
136
|
+
...cacheData == null ? void 0 : cacheData.data,
|
|
144
137
|
...res.data
|
|
145
138
|
};
|
|
146
|
-
|
|
147
|
-
// 设置缓存数据(支持异步)
|
|
148
139
|
await Promise.resolve(setEnumData(storage, cacheKey, res));
|
|
149
|
-
|
|
150
|
-
// 同步数据到全局
|
|
151
|
-
const mergedPayload = {
|
|
152
|
-
...dics,
|
|
153
|
-
...res.data,
|
|
154
|
-
...dataSource
|
|
155
|
-
};
|
|
140
|
+
const mergedPayload = { ...dics, ...res.data, ...dataSource };
|
|
156
141
|
dispatch({
|
|
157
|
-
type:
|
|
142
|
+
type: "setProEnumDic",
|
|
158
143
|
payload: mergedPayload
|
|
159
144
|
});
|
|
160
145
|
if (main) {
|
|
161
146
|
setTimeout(() => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
147
|
+
var _a3, _b3, _c2;
|
|
148
|
+
(_a3 = window == null ? void 0 : window.eventCenter) == null ? void 0 : _a3.publish("pro-enum-event", res.data);
|
|
149
|
+
logDebug((_c2 = (_b3 = locale) == null ? void 0 : _b3.ProEnum) == null ? void 0 : _c2.mainInitByRequest);
|
|
150
|
+
}, 1e4);
|
|
165
151
|
}
|
|
166
152
|
return res;
|
|
167
153
|
} catch (error) {
|
|
@@ -169,99 +155,72 @@ const useEnumRequest = (props, dispatch) => {
|
|
|
169
155
|
return res;
|
|
170
156
|
}
|
|
171
157
|
},
|
|
172
|
-
getCache: params => {
|
|
173
|
-
if (storage ===
|
|
174
|
-
return
|
|
158
|
+
getCache: (params) => {
|
|
159
|
+
if (storage === "indexedDB") {
|
|
160
|
+
return void 0;
|
|
175
161
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const res = getEnumData(storage, cacheKey) || {
|
|
179
|
-
data: {}
|
|
180
|
-
};
|
|
181
|
-
const mergedPayload = {
|
|
182
|
-
...dics,
|
|
183
|
-
...res?.data,
|
|
184
|
-
...dataSource
|
|
185
|
-
};
|
|
162
|
+
const res = getEnumData(storage, cacheKey) || { data: {} };
|
|
163
|
+
const mergedPayload = { ...dics, ...res == null ? void 0 : res.data, ...dataSource };
|
|
186
164
|
dispatch({
|
|
187
|
-
type:
|
|
165
|
+
type: "setProEnumDic",
|
|
188
166
|
payload: mergedPayload
|
|
189
167
|
});
|
|
190
168
|
if (main) {
|
|
191
169
|
setTimeout(() => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
170
|
+
var _a2, _b2, _c;
|
|
171
|
+
(_a2 = window == null ? void 0 : window.eventCenter) == null ? void 0 : _a2.publish("pro-enum-event", res.data);
|
|
172
|
+
logDebug((_c = (_b2 = locale) == null ? void 0 : _b2.ProEnum) == null ? void 0 : _c.mainInitByCache);
|
|
173
|
+
}, 1e4);
|
|
195
174
|
}
|
|
196
175
|
return res;
|
|
197
176
|
},
|
|
198
|
-
onSuccess: res => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
message: msg
|
|
202
|
-
} = res;
|
|
177
|
+
onSuccess: (res) => {
|
|
178
|
+
var _a2, _b2;
|
|
179
|
+
const { status = 200, message: msg } = res;
|
|
203
180
|
if (status !== 200) {
|
|
204
|
-
throw new Error(locale
|
|
181
|
+
throw new Error((_b2 = (_a2 = locale) == null ? void 0 : _a2.ProEnum) == null ? void 0 : _b2.requestError);
|
|
205
182
|
}
|
|
206
183
|
}
|
|
207
184
|
});
|
|
208
185
|
const mergeData = async () => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (typeof cacheData.data === 'object' && cacheData.data !== null) {
|
|
186
|
+
var _a2, _b2, _c, _d;
|
|
187
|
+
const cacheData = await Promise.resolve(getEnumData(storage, cacheKey) || { data: {} });
|
|
188
|
+
if (typeof cacheData === "object") {
|
|
189
|
+
if (typeof cacheData.data === "object" && cacheData.data !== null) {
|
|
214
190
|
const enumData = cacheData.data;
|
|
215
191
|
const cacheCodes = Object.keys(enumData);
|
|
216
|
-
const codes = useRequest
|
|
217
|
-
const ignoreCodes = useRequest
|
|
218
|
-
|
|
192
|
+
const codes = ((_a2 = useRequest == null ? void 0 : useRequest.options) == null ? void 0 : _a2.codes) || [];
|
|
193
|
+
const ignoreCodes = ((_b2 = useRequest == null ? void 0 : useRequest.options) == null ? void 0 : _b2.ignoreCodes) || [];
|
|
219
194
|
const diff = diffCode(cacheCodes, codes);
|
|
220
195
|
if (diff) {
|
|
221
196
|
let response;
|
|
222
|
-
const res = await useRequest
|
|
223
|
-
if (transformResponse && typeof transformResponse ===
|
|
197
|
+
const res = await (useRequest == null ? void 0 : useRequest.service());
|
|
198
|
+
if (transformResponse && typeof transformResponse === "function") {
|
|
224
199
|
response = await transformResponse(res);
|
|
225
|
-
if (typeof response !==
|
|
226
|
-
throw new Error(locale
|
|
200
|
+
if (typeof response !== "object" || response == null) {
|
|
201
|
+
throw new Error((_d = (_c = locale) == null ? void 0 : _c.ProEnum) == null ? void 0 : _d.errorMessage);
|
|
227
202
|
}
|
|
228
203
|
} else if (res.status === 200) {
|
|
229
204
|
response = res.data;
|
|
230
205
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
clear,
|
|
234
|
-
ignoreCodes,
|
|
235
|
-
fieldNames
|
|
236
|
-
});
|
|
237
|
-
cacheData.data = {
|
|
238
|
-
...cacheData.data,
|
|
239
|
-
...response
|
|
240
|
-
};
|
|
206
|
+
response = cleanEnumResponse(response, { clear, ignoreCodes, fieldNames });
|
|
207
|
+
cacheData.data = { ...cacheData.data, ...response };
|
|
241
208
|
await Promise.resolve(setEnumData(storage, cacheKey, cacheData));
|
|
242
|
-
// 同步数据到全局
|
|
243
209
|
dispatch({
|
|
244
|
-
type:
|
|
245
|
-
payload: {
|
|
246
|
-
...dics,
|
|
247
|
-
...cacheData.data,
|
|
248
|
-
...dataSource
|
|
249
|
-
}
|
|
210
|
+
type: "setProEnumDic",
|
|
211
|
+
payload: { ...dics, ...cacheData.data, ...dataSource }
|
|
250
212
|
});
|
|
251
213
|
} else if (dataSource && Object.keys(dataSource).length > 0) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
data: mergedPayload,
|
|
261
|
-
time: Date.now()
|
|
262
|
-
}));
|
|
214
|
+
const mergedPayload = { ...dics, ...cacheData.data, ...dataSource };
|
|
215
|
+
await Promise.resolve(
|
|
216
|
+
setEnumData(storage, cacheKey, {
|
|
217
|
+
...cacheData,
|
|
218
|
+
data: mergedPayload,
|
|
219
|
+
time: Date.now()
|
|
220
|
+
})
|
|
221
|
+
);
|
|
263
222
|
dispatch({
|
|
264
|
-
type:
|
|
223
|
+
type: "setProEnumDic",
|
|
265
224
|
payload: mergedPayload
|
|
266
225
|
});
|
|
267
226
|
}
|
|
@@ -271,79 +230,69 @@ const useEnumRequest = (props, dispatch) => {
|
|
|
271
230
|
useDeepCompareEffect(() => {
|
|
272
231
|
errorReportedRef.current = false;
|
|
273
232
|
const executeAsync = async () => {
|
|
274
|
-
if (useRequest && useRequest
|
|
275
|
-
const {
|
|
276
|
-
|
|
277
|
-
} = useRequest?.options || {};
|
|
278
|
-
const params = Array.isArray(defaultParams) ? defaultParams?.[0] : defaultParams || {};
|
|
233
|
+
if (useRequest && (useRequest == null ? void 0 : useRequest.service)) {
|
|
234
|
+
const { defaultParams } = (useRequest == null ? void 0 : useRequest.options) || {};
|
|
235
|
+
const params = Array.isArray(defaultParams) ? defaultParams == null ? void 0 : defaultParams[0] : defaultParams || {};
|
|
279
236
|
if (requestRefresh) {
|
|
280
237
|
window.localStorage.removeItem(cacheKey);
|
|
281
238
|
window.sessionStorage.removeItem(cacheKey);
|
|
282
|
-
if (storage ===
|
|
283
|
-
await removeEnumData(
|
|
239
|
+
if (storage === "indexedDB") {
|
|
240
|
+
await removeEnumData("indexedDB", cacheKey);
|
|
284
241
|
}
|
|
285
242
|
}
|
|
286
243
|
enumRes.run(params);
|
|
287
244
|
void mergeData().catch(reportBackgroundError);
|
|
288
245
|
} else if (dataSource && Object.keys(dataSource).length > 0) {
|
|
289
|
-
const res = await Promise.resolve(getEnumData(storage, cacheKey) || {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
data: mergedData,
|
|
299
|
-
time: Date.now()
|
|
300
|
-
}));
|
|
246
|
+
const res = await Promise.resolve(getEnumData(storage, cacheKey) || { data: {} });
|
|
247
|
+
const mergedData = { ...res == null ? void 0 : res.data, ...dataSource };
|
|
248
|
+
await Promise.resolve(
|
|
249
|
+
setEnumData(storage, cacheKey, {
|
|
250
|
+
...res,
|
|
251
|
+
data: mergedData,
|
|
252
|
+
time: Date.now()
|
|
253
|
+
})
|
|
254
|
+
);
|
|
301
255
|
dispatch({
|
|
302
|
-
type:
|
|
256
|
+
type: "setProEnumDic",
|
|
303
257
|
payload: mergedData
|
|
304
258
|
});
|
|
305
259
|
} else {
|
|
306
|
-
const res = await Promise.resolve(getEnumData(storage, cacheKey) || {
|
|
307
|
-
data: {}
|
|
308
|
-
});
|
|
260
|
+
const res = await Promise.resolve(getEnumData(storage, cacheKey) || { data: {} });
|
|
309
261
|
dispatch({
|
|
310
|
-
type:
|
|
311
|
-
payload: {
|
|
312
|
-
...res?.data
|
|
313
|
-
}
|
|
262
|
+
type: "setProEnumDic",
|
|
263
|
+
payload: { ...res == null ? void 0 : res.data }
|
|
314
264
|
});
|
|
315
265
|
}
|
|
316
266
|
};
|
|
317
267
|
void executeAsync().catch(reportBackgroundError);
|
|
318
|
-
}, [useRequest
|
|
319
|
-
const shareProEnumDic = async cacheData => {
|
|
268
|
+
}, [useRequest == null ? void 0 : useRequest.options]);
|
|
269
|
+
const shareProEnumDic = async (cacheData) => {
|
|
320
270
|
logDebug(cacheData);
|
|
321
|
-
const storageData = await Promise.resolve(getEnumData(storage, cacheKey) || {
|
|
322
|
-
|
|
323
|
-
});
|
|
324
|
-
const storagePayload = typeof storageData?.data === 'object' && storageData.data !== null ? storageData.data : storageData;
|
|
271
|
+
const storageData = await Promise.resolve(getEnumData(storage, cacheKey) || { data: {} });
|
|
272
|
+
const storagePayload = typeof (storageData == null ? void 0 : storageData.data) === "object" && storageData.data !== null ? storageData.data : storageData;
|
|
325
273
|
dispatch({
|
|
326
|
-
type:
|
|
327
|
-
payload: {
|
|
328
|
-
...dataSource,
|
|
329
|
-
...cacheData,
|
|
330
|
-
...storagePayload
|
|
331
|
-
}
|
|
274
|
+
type: "setProEnumDic",
|
|
275
|
+
payload: { ...dataSource, ...cacheData, ...storagePayload }
|
|
332
276
|
});
|
|
333
277
|
};
|
|
334
278
|
useEffect(() => {
|
|
279
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
335
280
|
if (main) {
|
|
336
|
-
window
|
|
337
|
-
logDebug(locale
|
|
281
|
+
(_a2 = window == null ? void 0 : window.eventCenter) == null ? void 0 : _a2.publish("pro-enum-event", {});
|
|
282
|
+
logDebug((_c = (_b2 = locale) == null ? void 0 : _b2.ProEnum) == null ? void 0 : _c.mainInitOnce);
|
|
338
283
|
}
|
|
339
284
|
if (!main && share) {
|
|
340
|
-
window
|
|
341
|
-
logDebug(locale
|
|
285
|
+
(_d = window == null ? void 0 : window.eventCenter) == null ? void 0 : _d.subscribe("pro-enum-event", shareProEnumDic);
|
|
286
|
+
logDebug((_f = (_e = locale) == null ? void 0 : _e.ProEnum) == null ? void 0 : _f.sonInitEvent);
|
|
342
287
|
}
|
|
343
288
|
return () => {
|
|
344
|
-
|
|
289
|
+
var _a3;
|
|
290
|
+
(_a3 = window == null ? void 0 : window.eventCenter) == null ? void 0 : _a3.unsubscribe("pro-enum-event", shareProEnumDic);
|
|
345
291
|
};
|
|
346
292
|
}, []);
|
|
347
293
|
return enumRes;
|
|
348
294
|
};
|
|
349
|
-
|
|
295
|
+
var useEnumRequest_default = useEnumRequest;
|
|
296
|
+
export {
|
|
297
|
+
useEnumRequest_default as default
|
|
298
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useDeepCompareEffect, useRequest as useRequestFunc } from
|
|
1
|
+
import { useDeepCompareEffect, useRequest as useRequestFunc } from "ahooks";
|
|
2
2
|
import { replaceFrequentEnumCache } from "../utils/frequentEnum";
|
|
3
3
|
import { baseCacheKey } from "../utils";
|
|
4
4
|
const useFrequentEnumRequest = (props, dispatch) => {
|
|
@@ -6,61 +6,53 @@ const useFrequentEnumRequest = (props, dispatch) => {
|
|
|
6
6
|
frequentEnums,
|
|
7
7
|
fieldNames,
|
|
8
8
|
clear = true,
|
|
9
|
-
storage =
|
|
9
|
+
storage = "localStorage",
|
|
10
10
|
cacheKey = baseCacheKey,
|
|
11
11
|
dics,
|
|
12
12
|
dataSource
|
|
13
13
|
} = props;
|
|
14
|
-
const frequentEnumRes = useRequestFunc(
|
|
15
|
-
data: {}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
response = frequentEnums.transformResponse(res);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 确保response.data存在,如果不存在则使用response本身
|
|
27
|
-
const enumData = response?.data || response;
|
|
28
|
-
|
|
29
|
-
// 替换缓存中的指定枚举(支持异步)
|
|
30
|
-
const updatedCacheData = await Promise.resolve(replaceFrequentEnumCache({
|
|
31
|
-
storage,
|
|
32
|
-
cacheKey,
|
|
33
|
-
enums: frequentEnums?.enums || [],
|
|
34
|
-
newData: enumData,
|
|
35
|
-
fieldNames,
|
|
36
|
-
clear
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
|
-
// 同步数据到全局状态
|
|
40
|
-
dispatch({
|
|
41
|
-
type: 'setProEnumDic',
|
|
42
|
-
payload: {
|
|
43
|
-
...dics,
|
|
44
|
-
...dataSource,
|
|
45
|
-
...updatedCacheData.data
|
|
14
|
+
const frequentEnumRes = useRequestFunc(
|
|
15
|
+
(frequentEnums == null ? void 0 : frequentEnums.service) || (() => Promise.resolve({ data: {} })),
|
|
16
|
+
{
|
|
17
|
+
manual: true,
|
|
18
|
+
...frequentEnums == null ? void 0 : frequentEnums.options,
|
|
19
|
+
onSuccess: async (res) => {
|
|
20
|
+
let response = res;
|
|
21
|
+
if ((frequentEnums == null ? void 0 : frequentEnums.transformResponse) && typeof frequentEnums.transformResponse === "function") {
|
|
22
|
+
response = frequentEnums.transformResponse(res);
|
|
46
23
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
const enumData = (response == null ? void 0 : response.data) || response;
|
|
25
|
+
const updatedCacheData = await Promise.resolve(
|
|
26
|
+
replaceFrequentEnumCache({
|
|
27
|
+
storage,
|
|
28
|
+
cacheKey,
|
|
29
|
+
enums: (frequentEnums == null ? void 0 : frequentEnums.enums) || [],
|
|
30
|
+
newData: enumData,
|
|
31
|
+
fieldNames,
|
|
32
|
+
clear
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
dispatch({
|
|
36
|
+
type: "setProEnumDic",
|
|
37
|
+
payload: { ...dics, ...dataSource, ...updatedCacheData.data }
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
onError: (error) => {
|
|
41
|
+
console.warn("ProEnum: Frequent enum request failed:", error);
|
|
42
|
+
}
|
|
51
43
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// 处理频繁枚举请求
|
|
44
|
+
);
|
|
55
45
|
useDeepCompareEffect(() => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const params = Array.isArray(defaultParams) ? defaultParams?.[0] : defaultParams || {};
|
|
46
|
+
var _a;
|
|
47
|
+
if (frequentEnums && (frequentEnums == null ? void 0 : frequentEnums.service) && ((_a = frequentEnums == null ? void 0 : frequentEnums.enums) == null ? void 0 : _a.length)) {
|
|
48
|
+
const { defaultParams } = (frequentEnums == null ? void 0 : frequentEnums.options) || {};
|
|
49
|
+
const params = Array.isArray(defaultParams) ? defaultParams == null ? void 0 : defaultParams[0] : defaultParams || {};
|
|
61
50
|
frequentEnumRes.run(params);
|
|
62
51
|
}
|
|
63
|
-
}, [frequentEnums
|
|
52
|
+
}, [frequentEnums == null ? void 0 : frequentEnums.options]);
|
|
64
53
|
return frequentEnumRes;
|
|
65
54
|
};
|
|
66
|
-
|
|
55
|
+
var useFrequentEnumRequest_default = useFrequentEnumRequest;
|
|
56
|
+
export {
|
|
57
|
+
useFrequentEnumRequest_default as default
|
|
58
|
+
};
|