@zat-design/sisyphus-react 4.5.9 → 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/dist/index.esm.css +1 -1
- package/dist/less.esm.css +1 -1
- 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.d.ts +2 -1
- package/es/ProDownload/index.js +74 -69
- package/es/ProDownload/propsType.js +0 -1
- package/es/ProDownload/utils.d.ts +10 -5
- package/es/ProDownload/utils.js +63 -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 +154 -235
- 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 +182 -212
- 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 -102
- package/es/ProForm/components/combination/FormList/components/Empty.js +28 -55
- 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/style/index.less +6 -0
- 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 +106 -213
- package/es/ProForm/components/combination/Group/hooks/index.js +69 -129
- 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 +72 -70
- package/es/ProForm/components/combination/ProModalSelect/index.js +309 -347
- 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 +62 -134
- 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 +160 -235
- 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 +113 -139
- 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 -24
- 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 -84
- 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 -63
- 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 +320 -350
- package/es/ProLayout/components/TabsManager/hooks/useTabsUrlSync.d.ts +19 -0
- package/es/ProLayout/components/TabsManager/hooks/useTabsUrlSync.js +332 -0
- package/es/ProLayout/components/TabsManager/index.js +407 -351
- package/es/ProLayout/components/TabsManager/propTypes.d.ts +4 -0
- package/es/ProLayout/components/TabsManager/propTypes.js +7 -15
- package/es/ProLayout/components/TabsManager/style/index.less +1 -1
- package/es/ProLayout/components/TabsManager/utils/historyObserver.d.ts +7 -0
- package/es/ProLayout/components/TabsManager/utils/historyObserver.js +65 -0
- package/es/ProLayout/components/TabsManager/utils/index.d.ts +15 -2
- package/es/ProLayout/components/TabsManager/utils/index.js +156 -159
- package/es/ProLayout/components/index.js +8 -3
- package/es/ProLayout/index.js +173 -228
- package/es/ProLayout/propTypes.d.ts +28 -1
- 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 +187 -223
- package/es/ProSelect/propsType.js +0 -1
- package/es/ProSelect/style/index.less +13 -0
- 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/style/index.less +1 -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 +191 -224
- 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 +41 -58
- 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 -168
- 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 +255 -459
- 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 -438
- 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 -148
- 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 -2
- package/es/ProConfigProvider/demo/locale.js +0 -58
package/es/ProDownload/index.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSetState } from "ahooks";
|
|
3
|
+
import { Button } from "antd";
|
|
4
|
+
import classNames from "classnames";
|
|
5
|
+
import isBoolean from "lodash/isBoolean";
|
|
6
|
+
import isFunction from "lodash/isFunction";
|
|
6
7
|
import { BlobMakeFile, DownloadRequest } from "./utils";
|
|
7
8
|
import { useProConfig } from "../ProConfigProvider";
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const normalizeError = (error) => {
|
|
10
|
+
if (error !== null && typeof error === "object") {
|
|
11
|
+
return error;
|
|
12
|
+
}
|
|
13
|
+
return new Error(error == null ? "Download request failed" : String(error));
|
|
14
|
+
};
|
|
15
|
+
const ProDownload = (props) => {
|
|
10
16
|
const {
|
|
11
17
|
source,
|
|
12
18
|
action,
|
|
@@ -22,44 +28,37 @@ const ProDownload = props => {
|
|
|
22
28
|
onError,
|
|
23
29
|
...defaultProps
|
|
24
30
|
} = props;
|
|
25
|
-
const [{
|
|
26
|
-
loading
|
|
27
|
-
}, setState] = useSetState({
|
|
31
|
+
const [{ loading }, setState] = useSetState({
|
|
28
32
|
loading: false
|
|
29
33
|
});
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} = useProConfig('ProDownload') || {};
|
|
34
|
-
defaultProps.headers = {
|
|
35
|
-
...headers,
|
|
36
|
-
...defaultProps.headers
|
|
37
|
-
};
|
|
34
|
+
const { headers, onError: onErrorConfig } = useProConfig("ProDownload") || {};
|
|
35
|
+
const reportError = onError || onErrorConfig;
|
|
36
|
+
defaultProps.headers = { ...headers, ...defaultProps.headers };
|
|
38
37
|
const handDownload = async (_params = params) => {
|
|
39
|
-
if (source ===
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
} catch (error) {
|
|
54
|
-
Promise.reject(error);
|
|
55
|
-
}
|
|
38
|
+
if (source === "url") {
|
|
39
|
+
fetch(url || action).then((response) => {
|
|
40
|
+
if (response.status > 400) {
|
|
41
|
+
return Promise.reject(new Error(`Service exception: ${response.status}`));
|
|
42
|
+
}
|
|
43
|
+
return response.blob();
|
|
44
|
+
}).then((res) => {
|
|
45
|
+
const blob = new Blob([res]);
|
|
46
|
+
BlobMakeFile({ blob, fileName });
|
|
47
|
+
}).catch((error) => {
|
|
48
|
+
reportError == null ? void 0 : reportError(normalizeError(error));
|
|
49
|
+
});
|
|
56
50
|
return;
|
|
57
51
|
}
|
|
58
|
-
setState({
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
setState({ loading: true });
|
|
53
|
+
let errorReported = false;
|
|
54
|
+
const requestOnError = (error) => {
|
|
55
|
+
if (errorReported) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
errorReported = true;
|
|
59
|
+
reportError == null ? void 0 : reportError(normalizeError(error));
|
|
60
|
+
};
|
|
61
61
|
try {
|
|
62
|
-
// 发起请求
|
|
63
62
|
await DownloadRequest({
|
|
64
63
|
url: url || action,
|
|
65
64
|
method,
|
|
@@ -68,43 +67,49 @@ const ProDownload = props => {
|
|
|
68
67
|
transformResponse,
|
|
69
68
|
fileName,
|
|
70
69
|
onFinish,
|
|
71
|
-
onError:
|
|
70
|
+
onError: requestOnError
|
|
72
71
|
});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
requestOnError(error);
|
|
73
74
|
} finally {
|
|
74
|
-
setState({
|
|
75
|
-
loading: false
|
|
76
|
-
});
|
|
75
|
+
setState({ loading: false });
|
|
77
76
|
}
|
|
78
77
|
};
|
|
79
78
|
const cls = classNames(className, {
|
|
80
|
-
|
|
79
|
+
"pro-download": true
|
|
81
80
|
});
|
|
82
|
-
return
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const res = await Promise.resolve(beforeDownload());
|
|
92
|
-
if (res === false) {
|
|
93
|
-
return;
|
|
81
|
+
return /* @__PURE__ */ jsx(
|
|
82
|
+
Button,
|
|
83
|
+
{
|
|
84
|
+
className: cls,
|
|
85
|
+
onClick: async () => {
|
|
86
|
+
let resolvedParams = params;
|
|
87
|
+
try {
|
|
88
|
+
if (isBoolean(beforeDownload) && !beforeDownload) {
|
|
89
|
+
return false;
|
|
94
90
|
}
|
|
91
|
+
if (beforeDownload) {
|
|
92
|
+
const res = await Promise.resolve(beforeDownload());
|
|
93
|
+
if (res === false) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (source !== "url" && isFunction(params)) {
|
|
98
|
+
resolvedParams = await Promise.resolve(params());
|
|
99
|
+
}
|
|
100
|
+
} catch {
|
|
101
|
+
return false;
|
|
95
102
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
},
|
|
104
|
-
...defaultProps,
|
|
105
|
-
loading: loading,
|
|
106
|
-
children: children
|
|
107
|
-
});
|
|
103
|
+
return handDownload(resolvedParams);
|
|
104
|
+
},
|
|
105
|
+
...defaultProps,
|
|
106
|
+
loading,
|
|
107
|
+
children
|
|
108
|
+
}
|
|
109
|
+
);
|
|
108
110
|
};
|
|
109
111
|
ProDownload.downLoadRequest = DownloadRequest;
|
|
110
|
-
|
|
112
|
+
var ProDownload_default = ProDownload;
|
|
113
|
+
export {
|
|
114
|
+
ProDownload_default as default
|
|
115
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -3,7 +3,7 @@ export interface PropsWithMakeFilePropsType {
|
|
|
3
3
|
fileName: string;
|
|
4
4
|
url?: string;
|
|
5
5
|
}
|
|
6
|
-
export interface IDownloadRequestPropsType {
|
|
6
|
+
export interface IDownloadRequestPropsType<TResult = Response> {
|
|
7
7
|
/**
|
|
8
8
|
* @description 下载请求的地址
|
|
9
9
|
* @default (必选)
|
|
@@ -21,12 +21,12 @@ export interface IDownloadRequestPropsType {
|
|
|
21
21
|
params?: any;
|
|
22
22
|
headers?: any;
|
|
23
23
|
/** 格式化数据 */
|
|
24
|
-
transformResponse?: (data: any) =>
|
|
24
|
+
transformResponse?: (data: any) => TResult | Promise<TResult>;
|
|
25
25
|
/**
|
|
26
26
|
* @description service 执行完成时触发
|
|
27
27
|
* @default -
|
|
28
28
|
*/
|
|
29
|
-
onFinish?: (response:
|
|
29
|
+
onFinish?: (response: Awaited<TResult>, params: object) => void;
|
|
30
30
|
/**
|
|
31
31
|
* @description 下载保存的文件名
|
|
32
32
|
* @default (必选)
|
|
@@ -47,7 +47,6 @@ export interface IDownloadRequestPropsType {
|
|
|
47
47
|
* @constructor
|
|
48
48
|
*/
|
|
49
49
|
export declare function BlobMakeFile({ blob, fileName, url }: PropsWithMakeFilePropsType): void;
|
|
50
|
-
export type DownloadRequestProps = (props: IDownloadRequestPropsType) => Promise<Response>;
|
|
51
50
|
type convertBase64ToBlobType = (base64: string, fileType?: string, slice?: number) => Blob;
|
|
52
51
|
export declare const convertBase64ToBlob: convertBase64ToBlobType;
|
|
53
52
|
/**
|
|
@@ -56,5 +55,11 @@ export declare const convertBase64ToBlob: convertBase64ToBlobType;
|
|
|
56
55
|
* @returns string
|
|
57
56
|
*/
|
|
58
57
|
export declare function getFilenameFromContentDisposition(contentDisposition: any): string;
|
|
59
|
-
export declare
|
|
58
|
+
export declare function DownloadRequest<TResult>(props: IDownloadRequestPropsType<TResult> & {
|
|
59
|
+
transformResponse: (data: any) => TResult | Promise<TResult>;
|
|
60
|
+
}): Promise<Awaited<TResult>>;
|
|
61
|
+
export declare function DownloadRequest(props: IDownloadRequestPropsType<Response> & {
|
|
62
|
+
transformResponse?: undefined;
|
|
63
|
+
}): Promise<Response>;
|
|
64
|
+
export type DownloadRequestProps = typeof DownloadRequest;
|
|
60
65
|
export {};
|
package/es/ProDownload/utils.js
CHANGED
|
@@ -1,168 +1,136 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
/* eslint-disable prefer-promise-reject-errors */
|
|
5
|
-
import { message } from 'antd';
|
|
1
|
+
import { message } from "antd";
|
|
2
|
+
import isFunction from "lodash/isFunction";
|
|
3
|
+
import get from "lodash/get";
|
|
6
4
|
import locale from "../locale";
|
|
7
|
-
const stringify = data => {
|
|
8
|
-
let result =
|
|
5
|
+
const stringify = (data) => {
|
|
6
|
+
let result = "";
|
|
9
7
|
if (data && Object.keys(data).length) {
|
|
10
|
-
Object.entries(data).forEach(item => {
|
|
8
|
+
Object.entries(data).forEach((item) => {
|
|
11
9
|
result += `&${item[0]}=${item[1]}`;
|
|
12
10
|
});
|
|
13
11
|
}
|
|
14
|
-
return result ? result.substr(1) :
|
|
12
|
+
return result ? result.substr(1) : "";
|
|
15
13
|
};
|
|
16
|
-
|
|
17
|
-
* 下载Blob
|
|
18
|
-
*
|
|
19
|
-
* @param response
|
|
20
|
-
* @param fileName
|
|
21
|
-
* @param extendName
|
|
22
|
-
* @constructor
|
|
23
|
-
*/
|
|
24
|
-
export function BlobMakeFile({
|
|
25
|
-
blob,
|
|
26
|
-
fileName,
|
|
27
|
-
url
|
|
28
|
-
}) {
|
|
14
|
+
function BlobMakeFile({ blob, fileName, url }) {
|
|
29
15
|
let blobUrl = url;
|
|
30
16
|
if (blob) {
|
|
31
17
|
blobUrl = window.URL.createObjectURL(blob);
|
|
32
18
|
}
|
|
33
19
|
const doc = document;
|
|
34
|
-
const ele = doc.createElement(
|
|
20
|
+
const ele = doc.createElement("a");
|
|
35
21
|
doc.body.appendChild(ele);
|
|
36
|
-
ele.style.display =
|
|
37
|
-
ele.setAttribute(
|
|
22
|
+
ele.style.display = "none";
|
|
23
|
+
ele.setAttribute("target", "");
|
|
38
24
|
ele.href = blobUrl;
|
|
39
25
|
ele.download = `${fileName}`;
|
|
40
26
|
ele.click();
|
|
41
27
|
doc.body.removeChild(ele);
|
|
42
28
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
29
|
+
const convertBase64ToBlob = (base64, fileType, slice = 1024) => {
|
|
30
|
+
var _a;
|
|
31
|
+
return new Blob(
|
|
32
|
+
(_a = atob(base64).match(new RegExp(`([\\s\\S]{${slice}})|([\\s\\S]{1,${slice}})`, "g"))) == null ? void 0 : _a.map((item) => {
|
|
33
|
+
return new Uint8Array(
|
|
34
|
+
item.split("").map((s, i) => {
|
|
35
|
+
return item.charCodeAt(i);
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
}),
|
|
39
|
+
{ type: fileType }
|
|
40
|
+
);
|
|
54
41
|
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 从Content-Disposition获取filename
|
|
58
|
-
* @param contentDisposition string
|
|
59
|
-
* @returns string
|
|
60
|
-
*/
|
|
61
|
-
export function getFilenameFromContentDisposition(contentDisposition) {
|
|
42
|
+
function getFilenameFromContentDisposition(contentDisposition) {
|
|
62
43
|
const pattern = /filename=([^;]+)/i;
|
|
63
44
|
const matches = pattern.exec(contentDisposition);
|
|
64
45
|
if (matches && matches[1]) {
|
|
65
|
-
// remove double quotes if filename is quoted
|
|
66
|
-
// 解码
|
|
67
46
|
const decodeFilename = decodeURIComponent(matches[1]);
|
|
68
|
-
return decodeFilename.replace(/^"?(.+?)"?$/,
|
|
47
|
+
return decodeFilename.replace(/^"?(.+?)"?$/, "$1");
|
|
69
48
|
}
|
|
70
49
|
return null;
|
|
71
50
|
}
|
|
72
|
-
|
|
73
|
-
// 发起请求获取下载文件
|
|
74
|
-
export const DownloadRequest = async ({
|
|
51
|
+
async function DownloadRequest({
|
|
75
52
|
url,
|
|
76
|
-
method =
|
|
53
|
+
method = "post",
|
|
77
54
|
params,
|
|
78
55
|
headers,
|
|
79
56
|
transformResponse,
|
|
80
57
|
fileName,
|
|
81
58
|
onFinish,
|
|
82
59
|
onError
|
|
83
|
-
})
|
|
60
|
+
}) {
|
|
84
61
|
const config = {
|
|
85
62
|
method,
|
|
86
|
-
credentials:
|
|
63
|
+
credentials: "include",
|
|
87
64
|
headers: {
|
|
88
|
-
|
|
89
|
-
accept:
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
accept: "application/json;charset=UTF-8"
|
|
90
67
|
},
|
|
91
68
|
body: null
|
|
92
69
|
};
|
|
93
|
-
|
|
94
|
-
if (method === 'post' && params) {
|
|
70
|
+
if (method === "post" && params) {
|
|
95
71
|
config.body = JSON.stringify(params);
|
|
96
72
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
url = `${url}${url.indexOf('?') !== -1 ? '&' : '?'}${stringify(params)}`;
|
|
73
|
+
if (method === "get" && params) {
|
|
74
|
+
url = `${url}${url.indexOf("?") !== -1 ? "&" : "?"}${stringify(params)}`;
|
|
100
75
|
}
|
|
101
|
-
|
|
102
|
-
if (headers && typeof headers === 'object' && Object.keys(headers).length > 0) {
|
|
76
|
+
if (headers && typeof headers === "object" && Object.keys(headers).length > 0) {
|
|
103
77
|
config.headers = {
|
|
104
78
|
...config.headers,
|
|
105
79
|
...headers
|
|
106
80
|
};
|
|
107
81
|
}
|
|
108
82
|
const response = await fetch(url, config);
|
|
109
|
-
const {
|
|
110
|
-
res,
|
|
111
|
-
responseData
|
|
112
|
-
} = await (async () => {
|
|
83
|
+
const { res, responseData } = await (async () => {
|
|
113
84
|
try {
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
85
|
+
const data2 = await response.clone().json();
|
|
86
|
+
if (!data2) {
|
|
116
87
|
message.error(`${locale.ProDownload.errorMessage}`);
|
|
117
88
|
return Promise.reject(`${locale.ProDownload.errorMessage}`);
|
|
118
89
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const errorMsg = data?.message || data?.msg;
|
|
90
|
+
if ((data2 == null ? void 0 : data2.status) > 200 || (data2 == null ? void 0 : data2.code) === 401) {
|
|
91
|
+
const errorMsg = (data2 == null ? void 0 : data2.message) || (data2 == null ? void 0 : data2.msg);
|
|
122
92
|
errorMsg && message.error(errorMsg);
|
|
123
|
-
onError && onError(
|
|
93
|
+
onError && onError(data2);
|
|
124
94
|
return Promise.reject(errorMsg);
|
|
125
95
|
}
|
|
126
|
-
if (
|
|
127
|
-
return Promise.resolve(transformResponse(
|
|
96
|
+
if (isFunction(transformResponse)) {
|
|
97
|
+
return Promise.resolve(transformResponse(data2)).then((transformedData) => ({
|
|
128
98
|
res: transformedData,
|
|
129
|
-
responseData:
|
|
99
|
+
responseData: data2
|
|
130
100
|
}));
|
|
131
101
|
}
|
|
132
|
-
return Promise.resolve({
|
|
133
|
-
res: response,
|
|
134
|
-
responseData: data
|
|
135
|
-
});
|
|
102
|
+
return Promise.resolve({ res: response, responseData: data2 });
|
|
136
103
|
} catch (error) {
|
|
137
104
|
if (response.ok) {
|
|
138
|
-
return Promise.resolve({
|
|
139
|
-
res: response,
|
|
140
|
-
responseData: null
|
|
141
|
-
});
|
|
105
|
+
return Promise.resolve({ res: response, responseData: null });
|
|
142
106
|
}
|
|
143
107
|
}
|
|
144
108
|
return Promise.reject(`${locale.ProDownload.errorMessage}`);
|
|
145
109
|
})();
|
|
146
110
|
let fileBlob;
|
|
147
111
|
let data = null;
|
|
148
|
-
let contentFileName =
|
|
149
|
-
if (
|
|
112
|
+
let contentFileName = "";
|
|
113
|
+
if (isFunction(transformResponse)) {
|
|
150
114
|
data = res;
|
|
151
115
|
} else {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
116
|
+
contentFileName = getFilenameFromContentDisposition(
|
|
117
|
+
response.headers.get("Content-Disposition")
|
|
118
|
+
);
|
|
119
|
+
data = get(responseData, "data");
|
|
155
120
|
}
|
|
156
121
|
if (data) {
|
|
157
122
|
fileBlob = convertBase64ToBlob(data);
|
|
158
123
|
} else {
|
|
159
124
|
fileBlob = await response.blob();
|
|
160
125
|
}
|
|
161
|
-
|
|
162
|
-
onFinish
|
|
163
|
-
BlobMakeFile({
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
126
|
+
const result = isFunction(transformResponse) ? res : response;
|
|
127
|
+
onFinish == null ? void 0 : onFinish(result, params);
|
|
128
|
+
BlobMakeFile({ blob: fileBlob, fileName: fileName || contentFileName });
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
BlobMakeFile,
|
|
133
|
+
DownloadRequest,
|
|
134
|
+
convertBase64ToBlob,
|
|
135
|
+
getFilenameFromContentDisposition
|
|
136
|
+
};
|