@hw-component/form 0.0.1-bate
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/.babelrc +23 -0
- package/.eslintrc.js +8 -0
- package/.husky/pre-commit +4 -0
- package/.stylelintrc.js +5 -0
- package/LICENSE +201 -0
- package/es/CheckboxGroup/CheckBox/index.d.ts +4 -0
- package/es/CheckboxGroup/CheckBox/index.js +40 -0
- package/es/CheckboxGroup/hooks.d.ts +5 -0
- package/es/CheckboxGroup/hooks.js +123 -0
- package/es/CheckboxGroup/index.d.ts +3 -0
- package/es/CheckboxGroup/index.js +89 -0
- package/es/CheckboxGroup/modal.d.ts +13 -0
- package/es/Form/Context/FormConfigProvider.d.ts +5 -0
- package/es/Form/Context/FormConfigProvider.js +47 -0
- package/es/Form/Context/index.d.ts +5 -0
- package/es/Form/Context/index.js +11 -0
- package/es/Form/FormItem/BasicItem.d.ts +4 -0
- package/es/Form/FormItem/BasicItem.js +73 -0
- package/es/Form/FormItem/Helper.d.ts +7 -0
- package/es/Form/FormItem/Helper.js +24 -0
- package/es/Form/FormItem/RegularFormItem.d.ts +4 -0
- package/es/Form/FormItem/RegularFormItem.js +15 -0
- package/es/Form/FormItem/UpFormItem.d.ts +4 -0
- package/es/Form/FormItem/UpFormItem.js +31 -0
- package/es/Form/FormItem/hooks.d.ts +10 -0
- package/es/Form/FormItem/hooks.js +38 -0
- package/es/Form/FormItem/index.d.ts +4 -0
- package/es/Form/FormItem/index.js +11 -0
- package/es/Form/HFormConnect.d.ts +6 -0
- package/es/Form/HFormConnect.js +54 -0
- package/es/Form/InitSet.d.ts +6 -0
- package/es/Form/InitSet.js +16 -0
- package/es/Form/Label.d.ts +10 -0
- package/es/Form/Label.js +46 -0
- package/es/Form/config.d.ts +28 -0
- package/es/Form/config.js +43 -0
- package/es/Form/hooks/index.d.ts +12 -0
- package/es/Form/hooks/index.js +77 -0
- package/es/Form/hooks/useHForm.d.ts +3 -0
- package/es/Form/hooks/useHForm.js +111 -0
- package/es/Form/hooks/useInitConfigData.d.ts +4 -0
- package/es/Form/hooks/useInitConfigData.js +124 -0
- package/es/Form/index.d.ts +4 -0
- package/es/Form/index.js +73 -0
- package/es/Form/modal.d.ts +92 -0
- package/es/Input/ButtonInput.d.ts +4 -0
- package/es/Input/ButtonInput.js +80 -0
- package/es/Input/InputNumber.d.ts +4 -0
- package/es/Input/InputNumber.js +20 -0
- package/es/Input/SelectInput.d.ts +9 -0
- package/es/Input/SelectInput.js +94 -0
- package/es/Input/defaultConfig.d.ts +7 -0
- package/es/Input/defaultConfig.js +11 -0
- package/es/Input/index.d.ts +4 -0
- package/es/Input/index.js +13 -0
- package/es/Input/modal.d.ts +25 -0
- package/es/PageHandler/ErrorComponent.d.ts +4 -0
- package/es/PageHandler/ErrorComponent.js +33 -0
- package/es/PageHandler/LoadingComponent.d.ts +3 -0
- package/es/PageHandler/LoadingComponent.js +18 -0
- package/es/PageHandler/index.d.ts +4 -0
- package/es/PageHandler/index.js +24 -0
- package/es/PageHandler/modal.d.ts +6 -0
- package/es/RadioGroup/index.d.ts +9 -0
- package/es/RadioGroup/index.js +48 -0
- package/es/Select/components/AllSelect.d.ts +7 -0
- package/es/Select/components/AllSelect.js +50 -0
- package/es/Select/components/CheckBoxOption.d.ts +7 -0
- package/es/Select/components/CheckBoxOption.js +14 -0
- package/es/Select/components/DropdownComponent.d.ts +9 -0
- package/es/Select/components/DropdownComponent.js +39 -0
- package/es/Select/components/NoFindItem.d.ts +6 -0
- package/es/Select/components/NoFindItem.js +13 -0
- package/es/Select/components/NotFoundContent.d.ts +7 -0
- package/es/Select/components/NotFoundContent.js +38 -0
- package/es/Select/defaultConfig.d.ts +6 -0
- package/es/Select/defaultConfig.js +33 -0
- package/es/Select/hooks/changeHooks.d.ts +5 -0
- package/es/Select/hooks/changeHooks.js +194 -0
- package/es/Select/hooks/norHooks.d.ts +10 -0
- package/es/Select/hooks/norHooks.js +85 -0
- package/es/Select/index.d.ts +4 -0
- package/es/Select/index.js +128 -0
- package/es/Select/modal.d.ts +30 -0
- package/es/Select/utils.d.ts +2 -0
- package/es/Select/utils.js +39 -0
- package/es/Submit/index.d.ts +8 -0
- package/es/Submit/index.js +28 -0
- package/es/Switch/index.d.ts +11 -0
- package/es/Switch/index.js +45 -0
- package/es/TDPicker/RangePicker.d.ts +8 -0
- package/es/TDPicker/RangePicker.js +116 -0
- package/es/TDPicker/TimePicker.d.ts +4 -0
- package/es/TDPicker/TimePicker.js +31 -0
- package/es/TDPicker/hooks.d.ts +33 -0
- package/es/TDPicker/hooks.js +132 -0
- package/es/TDPicker/index.d.ts +4 -0
- package/es/TDPicker/index.js +33 -0
- package/es/TDPicker/modal.d.ts +28 -0
- package/es/TextArea/index.d.ts +3 -0
- package/es/Upload/Btn.d.ts +4 -0
- package/es/Upload/Btn.js +31 -0
- package/es/Upload/MediaTypeEle/TypeEle.d.ts +10 -0
- package/es/Upload/MediaTypeEle/TypeEle.js +40 -0
- package/es/Upload/MediaTypeEle/index.d.ts +4 -0
- package/es/Upload/MediaTypeEle/index.js +36 -0
- package/es/Upload/Preview/index.d.ts +6 -0
- package/es/Upload/Preview/index.js +21 -0
- package/es/Upload/UrlUpload/index.d.ts +4 -0
- package/es/Upload/UrlUpload/index.js +119 -0
- package/es/Upload/enums.d.ts +5 -0
- package/es/Upload/enums.js +10 -0
- package/es/Upload/hooks/change.d.ts +3 -0
- package/es/Upload/hooks/change.js +109 -0
- package/es/Upload/hooks/customRequest.d.ts +3 -0
- package/es/Upload/hooks/customRequest.js +69 -0
- package/es/Upload/hooks/propsMaker.d.ts +2 -0
- package/es/Upload/hooks/propsMaker.js +37 -0
- package/es/Upload/index.d.ts +4 -0
- package/es/Upload/index.js +106 -0
- package/es/Upload/modal.d.ts +28 -0
- package/es/Upload/util.d.ts +5 -0
- package/es/Upload/util.js +34 -0
- package/es/config.d.ts +2 -0
- package/es/config.js +64 -0
- package/es/hooks/index.d.ts +13 -0
- package/es/hooks/index.js +75 -0
- package/es/index.css +35 -0
- package/es/index.d.ts +20 -0
- package/es/index.js +25 -0
- package/es/modal.d.ts +15 -0
- package/lib/CheckboxGroup/CheckBox/index.d.ts +4 -0
- package/lib/CheckboxGroup/CheckBox/index.js +43 -0
- package/lib/CheckboxGroup/hooks.d.ts +5 -0
- package/lib/CheckboxGroup/hooks.js +124 -0
- package/lib/CheckboxGroup/index.d.ts +3 -0
- package/lib/CheckboxGroup/index.js +92 -0
- package/lib/CheckboxGroup/modal.d.ts +13 -0
- package/lib/Form/Context/FormConfigProvider.d.ts +5 -0
- package/lib/Form/Context/FormConfigProvider.js +51 -0
- package/lib/Form/Context/index.d.ts +5 -0
- package/lib/Form/Context/index.js +14 -0
- package/lib/Form/FormItem/BasicItem.d.ts +4 -0
- package/lib/Form/FormItem/BasicItem.js +76 -0
- package/lib/Form/FormItem/Helper.d.ts +7 -0
- package/lib/Form/FormItem/Helper.js +27 -0
- package/lib/Form/FormItem/RegularFormItem.d.ts +4 -0
- package/lib/Form/FormItem/RegularFormItem.js +18 -0
- package/lib/Form/FormItem/UpFormItem.d.ts +4 -0
- package/lib/Form/FormItem/UpFormItem.js +34 -0
- package/lib/Form/FormItem/hooks.d.ts +10 -0
- package/lib/Form/FormItem/hooks.js +41 -0
- package/lib/Form/FormItem/index.d.ts +4 -0
- package/lib/Form/FormItem/index.js +14 -0
- package/lib/Form/HFormConnect.d.ts +6 -0
- package/lib/Form/HFormConnect.js +57 -0
- package/lib/Form/InitSet.d.ts +6 -0
- package/lib/Form/InitSet.js +19 -0
- package/lib/Form/Label.d.ts +10 -0
- package/lib/Form/Label.js +49 -0
- package/lib/Form/config.d.ts +28 -0
- package/lib/Form/config.js +47 -0
- package/lib/Form/hooks/index.d.ts +12 -0
- package/lib/Form/hooks/index.js +80 -0
- package/lib/Form/hooks/useHForm.d.ts +3 -0
- package/lib/Form/hooks/useHForm.js +114 -0
- package/lib/Form/hooks/useInitConfigData.d.ts +4 -0
- package/lib/Form/hooks/useInitConfigData.js +127 -0
- package/lib/Form/index.d.ts +4 -0
- package/lib/Form/index.js +76 -0
- package/lib/Form/modal.d.ts +92 -0
- package/lib/Input/ButtonInput.d.ts +4 -0
- package/lib/Input/ButtonInput.js +83 -0
- package/lib/Input/InputNumber.d.ts +4 -0
- package/lib/Input/InputNumber.js +23 -0
- package/lib/Input/SelectInput.d.ts +9 -0
- package/lib/Input/SelectInput.js +98 -0
- package/lib/Input/defaultConfig.d.ts +7 -0
- package/lib/Input/defaultConfig.js +13 -0
- package/lib/Input/index.d.ts +4 -0
- package/lib/Input/index.js +16 -0
- package/lib/Input/modal.d.ts +25 -0
- package/lib/PageHandler/ErrorComponent.d.ts +4 -0
- package/lib/PageHandler/ErrorComponent.js +36 -0
- package/lib/PageHandler/LoadingComponent.d.ts +3 -0
- package/lib/PageHandler/LoadingComponent.js +21 -0
- package/lib/PageHandler/index.d.ts +4 -0
- package/lib/PageHandler/index.js +27 -0
- package/lib/PageHandler/modal.d.ts +6 -0
- package/lib/RadioGroup/index.d.ts +9 -0
- package/lib/RadioGroup/index.js +51 -0
- package/lib/Select/components/AllSelect.d.ts +7 -0
- package/lib/Select/components/AllSelect.js +53 -0
- package/lib/Select/components/CheckBoxOption.d.ts +7 -0
- package/lib/Select/components/CheckBoxOption.js +17 -0
- package/lib/Select/components/DropdownComponent.d.ts +9 -0
- package/lib/Select/components/DropdownComponent.js +42 -0
- package/lib/Select/components/NoFindItem.d.ts +6 -0
- package/lib/Select/components/NoFindItem.js +16 -0
- package/lib/Select/components/NotFoundContent.d.ts +7 -0
- package/lib/Select/components/NotFoundContent.js +41 -0
- package/lib/Select/defaultConfig.d.ts +6 -0
- package/lib/Select/defaultConfig.js +35 -0
- package/lib/Select/hooks/changeHooks.d.ts +5 -0
- package/lib/Select/hooks/changeHooks.js +195 -0
- package/lib/Select/hooks/norHooks.d.ts +10 -0
- package/lib/Select/hooks/norHooks.js +87 -0
- package/lib/Select/index.d.ts +4 -0
- package/lib/Select/index.js +131 -0
- package/lib/Select/modal.d.ts +30 -0
- package/lib/Select/utils.d.ts +2 -0
- package/lib/Select/utils.js +41 -0
- package/lib/Submit/index.d.ts +8 -0
- package/lib/Submit/index.js +31 -0
- package/lib/Switch/index.d.ts +11 -0
- package/lib/Switch/index.js +48 -0
- package/lib/TDPicker/RangePicker.d.ts +8 -0
- package/lib/TDPicker/RangePicker.js +119 -0
- package/lib/TDPicker/TimePicker.d.ts +4 -0
- package/lib/TDPicker/TimePicker.js +34 -0
- package/lib/TDPicker/hooks.d.ts +33 -0
- package/lib/TDPicker/hooks.js +139 -0
- package/lib/TDPicker/index.d.ts +4 -0
- package/lib/TDPicker/index.js +36 -0
- package/lib/TDPicker/modal.d.ts +28 -0
- package/lib/TextArea/index.d.ts +3 -0
- package/lib/Upload/Btn.d.ts +4 -0
- package/lib/Upload/Btn.js +34 -0
- package/lib/Upload/MediaTypeEle/TypeEle.d.ts +10 -0
- package/lib/Upload/MediaTypeEle/TypeEle.js +43 -0
- package/lib/Upload/MediaTypeEle/index.d.ts +4 -0
- package/lib/Upload/MediaTypeEle/index.js +39 -0
- package/lib/Upload/Preview/index.d.ts +6 -0
- package/lib/Upload/Preview/index.js +24 -0
- package/lib/Upload/UrlUpload/index.d.ts +4 -0
- package/lib/Upload/UrlUpload/index.js +122 -0
- package/lib/Upload/enums.d.ts +5 -0
- package/lib/Upload/enums.js +9 -0
- package/lib/Upload/hooks/change.d.ts +3 -0
- package/lib/Upload/hooks/change.js +110 -0
- package/lib/Upload/hooks/customRequest.d.ts +3 -0
- package/lib/Upload/hooks/customRequest.js +70 -0
- package/lib/Upload/hooks/propsMaker.d.ts +2 -0
- package/lib/Upload/hooks/propsMaker.js +38 -0
- package/lib/Upload/index.d.ts +4 -0
- package/lib/Upload/index.js +109 -0
- package/lib/Upload/modal.d.ts +28 -0
- package/lib/Upload/util.d.ts +5 -0
- package/lib/Upload/util.js +38 -0
- package/lib/config.d.ts +2 -0
- package/lib/config.js +65 -0
- package/lib/hooks/index.d.ts +13 -0
- package/lib/hooks/index.js +78 -0
- package/lib/index.css +35 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +43 -0
- package/lib/modal.d.ts +15 -0
- package/package.json +81 -0
- package/public/index.html +19 -0
- package/scripts/rollup.config.js +75 -0
- package/scripts/webpack.config.js +76 -0
- package/src/Layout.tsx +61 -0
- package/src/app.tsx +33 -0
- package/src/components/CheckboxGroup/CheckBox/index.tsx +38 -0
- package/src/components/CheckboxGroup/hooks.ts +102 -0
- package/src/components/CheckboxGroup/index.tsx +79 -0
- package/src/components/CheckboxGroup/modal.ts +15 -0
- package/src/components/Form/Context/FormConfigProvider.tsx +38 -0
- package/src/components/Form/Context/index.tsx +14 -0
- package/src/components/Form/FormItem/BasicItem.tsx +70 -0
- package/src/components/Form/FormItem/Helper.tsx +26 -0
- package/src/components/Form/FormItem/RegularFormItem.tsx +7 -0
- package/src/components/Form/FormItem/UpFormItem.tsx +20 -0
- package/src/components/Form/FormItem/hooks.tsx +44 -0
- package/src/components/Form/FormItem/index.tsx +8 -0
- package/src/components/Form/HFormConnect.tsx +49 -0
- package/src/components/Form/InitSet.tsx +12 -0
- package/src/components/Form/Label.tsx +50 -0
- package/src/components/Form/config.ts +40 -0
- package/src/components/Form/hooks/index.ts +42 -0
- package/src/components/Form/hooks/useHForm.ts +89 -0
- package/src/components/Form/hooks/useInitConfigData.tsx +100 -0
- package/src/components/Form/index.less +22 -0
- package/src/components/Form/index.tsx +61 -0
- package/src/components/Form/modal.ts +142 -0
- package/src/components/Input/ButtonInput.tsx +41 -0
- package/src/components/Input/InputNumber.tsx +5 -0
- package/src/components/Input/SelectInput.tsx +74 -0
- package/src/components/Input/defaultConfig.ts +8 -0
- package/src/components/Input/index.tsx +6 -0
- package/src/components/Input/modal.ts +31 -0
- package/src/components/PageHandler/ErrorComponent.tsx +20 -0
- package/src/components/PageHandler/LoadingComponent.tsx +9 -0
- package/src/components/PageHandler/index.tsx +14 -0
- package/src/components/PageHandler/modal.ts +6 -0
- package/src/components/RadioGroup/index.tsx +45 -0
- package/src/components/Select/components/AllSelect.tsx +54 -0
- package/src/components/Select/components/CheckBoxOption.tsx +14 -0
- package/src/components/Select/components/DropdownComponent.tsx +36 -0
- package/src/components/Select/components/NoFindItem.tsx +7 -0
- package/src/components/Select/components/NotFoundContent.tsx +25 -0
- package/src/components/Select/defaultConfig.tsx +23 -0
- package/src/components/Select/hooks/changeHooks.tsx +151 -0
- package/src/components/Select/hooks/norHooks.ts +63 -0
- package/src/components/Select/index.less +22 -0
- package/src/components/Select/index.tsx +120 -0
- package/src/components/Select/modal.ts +30 -0
- package/src/components/Select/utils.ts +18 -0
- package/src/components/Submit/index.tsx +28 -0
- package/src/components/Switch/index.tsx +52 -0
- package/src/components/TDPicker/RangePicker.tsx +103 -0
- package/src/components/TDPicker/TimePicker.tsx +15 -0
- package/src/components/TDPicker/hooks.ts +150 -0
- package/src/components/TDPicker/index.tsx +22 -0
- package/src/components/TDPicker/modal.ts +30 -0
- package/src/components/TextArea/index.tsx +8 -0
- package/src/components/Upload/Btn.tsx +24 -0
- package/src/components/Upload/MediaTypeEle/TypeEle.tsx +26 -0
- package/src/components/Upload/MediaTypeEle/index.tsx +34 -0
- package/src/components/Upload/Preview/index.tsx +14 -0
- package/src/components/Upload/UrlUpload/index.tsx +91 -0
- package/src/components/Upload/enums.ts +5 -0
- package/src/components/Upload/hooks/change.ts +79 -0
- package/src/components/Upload/hooks/customRequest.ts +44 -0
- package/src/components/Upload/hooks/propsMaker.ts +20 -0
- package/src/components/Upload/index.tsx +85 -0
- package/src/components/Upload/modal.ts +31 -0
- package/src/components/Upload/util.ts +27 -0
- package/src/components/config.ts +40 -0
- package/src/components/hooks/index.ts +53 -0
- package/src/components/index.tsx +21 -0
- package/src/components/modal.ts +15 -0
- package/src/components/styles/index.less +2 -0
- package/src/components/styles/local.less +1 -0
- package/src/components/typings.d.ts +11 -0
- package/src/index.less +20 -0
- package/src/index.tsx +12 -0
- package/src/pages/Checkbox/index.tsx +15 -0
- package/src/pages/DatePicker/index.tsx +33 -0
- package/src/pages/Form/index.tsx +146 -0
- package/src/pages/Input/index.tsx +22 -0
- package/src/pages/Radio/index.tsx +18 -0
- package/src/pages/Select/index.tsx +57 -0
- package/src/pages/Switch/index.tsx +18 -0
- package/src/pages/Upload/index.tsx +14 -0
- package/src/routes.tsx +68 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import type { HCheckboxProps } from "@/components/CheckboxGroup/modal";
|
|
3
|
+
|
|
4
|
+
const changValProvider = ({
|
|
5
|
+
value,
|
|
6
|
+
options,
|
|
7
|
+
valueMap = {},
|
|
8
|
+
}: HCheckboxProps) => {
|
|
9
|
+
const newVal = { ...value };
|
|
10
|
+
const { checked, noChecked } = valueMap;
|
|
11
|
+
options?.forEach((item) => {
|
|
12
|
+
const { value: itemVal } = item;
|
|
13
|
+
if (newVal[itemVal] !== checked) {
|
|
14
|
+
newVal[itemVal] = noChecked;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return newVal;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const useValueProvider = ({
|
|
21
|
+
value,
|
|
22
|
+
valueMap = {},
|
|
23
|
+
keyInValue = true,
|
|
24
|
+
onChange,
|
|
25
|
+
options,
|
|
26
|
+
}: HCheckboxProps) => {
|
|
27
|
+
const [val, setVal] = useState<Record<any, any>>({});
|
|
28
|
+
const oldValueCheckMap = useMemo(() => {
|
|
29
|
+
return {
|
|
30
|
+
valueMap,
|
|
31
|
+
};
|
|
32
|
+
}, []); //存储老的map
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
setVal((oldVal) => {
|
|
35
|
+
return changValProvider({
|
|
36
|
+
value: oldVal,
|
|
37
|
+
options,
|
|
38
|
+
valueMap: oldValueCheckMap.valueMap,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}, [options]); //初始化数据
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const { checked: oldChecked } = oldValueCheckMap.valueMap;
|
|
44
|
+
const { checked, noChecked } = valueMap;
|
|
45
|
+
setVal((oldVal) => {
|
|
46
|
+
const newVal = { ...oldVal };
|
|
47
|
+
const keys = Object.keys(newVal);
|
|
48
|
+
keys.forEach((key) => {
|
|
49
|
+
if (newVal[key] === oldChecked) {
|
|
50
|
+
newVal[key] = checked;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
newVal[key] = noChecked;
|
|
54
|
+
});
|
|
55
|
+
oldValueCheckMap.valueMap = valueMap;
|
|
56
|
+
return newVal;
|
|
57
|
+
});
|
|
58
|
+
}, [valueMap]);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const { checked } = oldValueCheckMap.valueMap;
|
|
62
|
+
if (!value) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!Array.isArray(value)) {
|
|
66
|
+
setVal(value);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setVal((oldVal) => {
|
|
70
|
+
const newVal = { ...oldVal };
|
|
71
|
+
value.forEach((itemVal) => {
|
|
72
|
+
newVal[itemVal] = checked;
|
|
73
|
+
});
|
|
74
|
+
return newVal;
|
|
75
|
+
});
|
|
76
|
+
}, [value]);
|
|
77
|
+
|
|
78
|
+
const change = (key: any, changeVal: any) => {
|
|
79
|
+
const { checked, noChecked } = valueMap;
|
|
80
|
+
const newVal = { ...val };
|
|
81
|
+
newVal[key] = noChecked;
|
|
82
|
+
if (changeVal === checked) {
|
|
83
|
+
newVal[key] = checked;
|
|
84
|
+
}
|
|
85
|
+
if (!onChange) {
|
|
86
|
+
setVal(newVal);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (keyInValue) {
|
|
90
|
+
onChange(newVal);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const subVal = Object.keys(newVal).filter((valKey) => {
|
|
94
|
+
return newVal[valKey] === checked;
|
|
95
|
+
});
|
|
96
|
+
onChange(subVal);
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
val,
|
|
100
|
+
change,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Space } from "antd";
|
|
2
|
+
import type { HCheckboxProps } from "@/components/CheckboxGroup/modal";
|
|
3
|
+
import { useValueProvider } from "./hooks";
|
|
4
|
+
import Checkbox from "./CheckBox";
|
|
5
|
+
import { useMatchConfigProps, useChangeOptions } from "../hooks";
|
|
6
|
+
import HFormConnect from "../Form/HFormConnect";
|
|
7
|
+
import React from "react";
|
|
8
|
+
|
|
9
|
+
const Index = ({
|
|
10
|
+
options,
|
|
11
|
+
fieldNames,
|
|
12
|
+
onChange,
|
|
13
|
+
valueMap,
|
|
14
|
+
value,
|
|
15
|
+
disabled,
|
|
16
|
+
keyInValue = true,
|
|
17
|
+
addFormat,
|
|
18
|
+
}: HCheckboxProps) => {
|
|
19
|
+
const { valueCheckMap: resultValueCheckMap, fieldNames: resultFieldNames } =
|
|
20
|
+
useMatchConfigProps({ fieldNames, valueCheckMap: valueMap }); //匹配全局
|
|
21
|
+
const checkOptions = useChangeOptions({
|
|
22
|
+
options,
|
|
23
|
+
fieldNames: resultFieldNames,
|
|
24
|
+
});
|
|
25
|
+
const { val, change } = useValueProvider({
|
|
26
|
+
options: checkOptions,
|
|
27
|
+
onChange,
|
|
28
|
+
valueMap: resultValueCheckMap,
|
|
29
|
+
keyInValue,
|
|
30
|
+
value,
|
|
31
|
+
});
|
|
32
|
+
addFormat?.({
|
|
33
|
+
float: {
|
|
34
|
+
inputValue: (item, initValue) => {
|
|
35
|
+
const { name } = item;
|
|
36
|
+
const keys = checkOptions?.map((optItem) => {
|
|
37
|
+
return optItem.value;
|
|
38
|
+
});
|
|
39
|
+
const resultObj = {};
|
|
40
|
+
keys?.forEach((key) => {
|
|
41
|
+
resultObj[key] = initValue[key];
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
[name]: resultObj,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
outputValue: (item, outputValue) => {
|
|
48
|
+
const { name } = item;
|
|
49
|
+
const { [name]: itemVal = {} } = outputValue;
|
|
50
|
+
return {
|
|
51
|
+
...itemVal,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return (
|
|
57
|
+
<Space>
|
|
58
|
+
{checkOptions?.map((item) => {
|
|
59
|
+
const { label, value: itemVal } = item;
|
|
60
|
+
const checked = val[itemVal];
|
|
61
|
+
return (
|
|
62
|
+
<Checkbox
|
|
63
|
+
value={checked}
|
|
64
|
+
key={itemVal}
|
|
65
|
+
onChange={(changeVal) => {
|
|
66
|
+
change(itemVal, changeVal);
|
|
67
|
+
}}
|
|
68
|
+
valueMap={valueMap}
|
|
69
|
+
disabled={disabled}
|
|
70
|
+
>
|
|
71
|
+
{label}
|
|
72
|
+
</Checkbox>
|
|
73
|
+
);
|
|
74
|
+
})}
|
|
75
|
+
</Space>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default HFormConnect(Index);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CheckboxProps } from "antd/lib/checkbox/Checkbox";
|
|
2
|
+
import type { SelectProps } from "antd";
|
|
3
|
+
import type { addFormatItemModal } from "../Form/modal";
|
|
4
|
+
import type { ValueCheckMapModal } from "../modal";
|
|
5
|
+
|
|
6
|
+
export interface HCheckboxProps
|
|
7
|
+
extends Omit<CheckboxProps, "value" | "onChange"> {
|
|
8
|
+
options?: Record<string, any>[];
|
|
9
|
+
fieldNames?: SelectProps["fieldNames"];
|
|
10
|
+
valueMap?: ValueCheckMapModal;
|
|
11
|
+
keyInValue?: boolean;
|
|
12
|
+
value?: Record<string, any> | any[];
|
|
13
|
+
onChange?: (value: Record<string, any> | any[]) => void;
|
|
14
|
+
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FormConfigContext } from "./index";
|
|
2
|
+
import React, { useContext } from "react";
|
|
3
|
+
import { baseConfig } from "../../config";
|
|
4
|
+
import type { IFormConfigContextProps } from "../modal";
|
|
5
|
+
|
|
6
|
+
export const useFormConfigContext = (key?: string) => {
|
|
7
|
+
const defaultProps = useContext(FormConfigContext);
|
|
8
|
+
if (!key) {
|
|
9
|
+
return Object.keys(defaultProps).length === 0
|
|
10
|
+
? { ...baseConfig }
|
|
11
|
+
: defaultProps;
|
|
12
|
+
}
|
|
13
|
+
return defaultProps[key] || { ...baseConfig[key] };
|
|
14
|
+
}; //获取配置
|
|
15
|
+
const mergeProps = (props: IFormConfigContextProps) => {
|
|
16
|
+
const newProps = { ...baseConfig };
|
|
17
|
+
const keys = Object.keys(props);
|
|
18
|
+
keys.forEach((key) => {
|
|
19
|
+
const defaultItem = newProps[key];
|
|
20
|
+
if (!defaultItem) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
newProps[key] = {
|
|
24
|
+
...defaultItem,
|
|
25
|
+
...props[key],
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
return newProps;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const Index: React.FC<IFormConfigContextProps> = ({ children, ...props }) => {
|
|
32
|
+
return (
|
|
33
|
+
<FormConfigContext.Provider value={mergeProps(props)}>
|
|
34
|
+
{children}
|
|
35
|
+
</FormConfigContext.Provider>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
export default Index;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { useContext } from "react";
|
|
2
|
+
import type {
|
|
3
|
+
IFormConfigContextProps,
|
|
4
|
+
FormContextProps,
|
|
5
|
+
} from "@/components/Form/modal";
|
|
6
|
+
|
|
7
|
+
export const FormContext = React.createContext<Partial<FormContextProps>>({});
|
|
8
|
+
export const useFormContext = (): FormContextProps => {
|
|
9
|
+
return useContext(FormContext) as FormContextProps;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const FormConfigContext = React.createContext<IFormConfigContextProps>(
|
|
13
|
+
{}
|
|
14
|
+
);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import Label from "../Label";
|
|
2
|
+
import { Form, Space } from "antd";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import Helper from "./Helper";
|
|
5
|
+
import { useClassName } from "../../hooks";
|
|
6
|
+
import { useHide } from "./hooks";
|
|
7
|
+
import { useFormContext } from "../Context";
|
|
8
|
+
import type { FormItemWithRender, HItemProps } from "../modal";
|
|
9
|
+
|
|
10
|
+
interface ContentProps extends Omit<HItemProps, "name"> {
|
|
11
|
+
value?: any;
|
|
12
|
+
onChange?: (val: any) => void;
|
|
13
|
+
}
|
|
14
|
+
const Content: React.FC<ContentProps> = ({
|
|
15
|
+
children,
|
|
16
|
+
helper,
|
|
17
|
+
value,
|
|
18
|
+
onChange,
|
|
19
|
+
}) => {
|
|
20
|
+
const className = useClassName("hw-form-base-item");
|
|
21
|
+
const relChild =
|
|
22
|
+
children && React.cloneElement(children as any, { value, onChange });
|
|
23
|
+
return (
|
|
24
|
+
<Space direction={"vertical"} size={4} style={{ width: "100%" }}>
|
|
25
|
+
<div className={className}>{relChild}</div>
|
|
26
|
+
<Helper helper={helper} />
|
|
27
|
+
</Space>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const Index: React.FC<FormItemWithRender> = ({
|
|
32
|
+
hover,
|
|
33
|
+
labelWidth,
|
|
34
|
+
required,
|
|
35
|
+
colon = true,
|
|
36
|
+
label,
|
|
37
|
+
itemProps,
|
|
38
|
+
children,
|
|
39
|
+
helper,
|
|
40
|
+
hide,
|
|
41
|
+
render,
|
|
42
|
+
...props
|
|
43
|
+
}) => {
|
|
44
|
+
const { form } = useFormContext();
|
|
45
|
+
const hideItem = useHide({ hide, form });
|
|
46
|
+
if (hideItem) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return (
|
|
50
|
+
<Form.Item
|
|
51
|
+
label={
|
|
52
|
+
<Label
|
|
53
|
+
hover={hover}
|
|
54
|
+
labelWidth={labelWidth}
|
|
55
|
+
required={required}
|
|
56
|
+
colon={colon}
|
|
57
|
+
>
|
|
58
|
+
{label}
|
|
59
|
+
</Label>
|
|
60
|
+
}
|
|
61
|
+
{...props}
|
|
62
|
+
colon={false}
|
|
63
|
+
required={false}
|
|
64
|
+
>
|
|
65
|
+
<Content helper={helper}>{render(form)}</Content>
|
|
66
|
+
</Form.Item>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default Index;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { HItemProps } from "@/components/Form/modal";
|
|
3
|
+
import type { FormInstance } from "antd";
|
|
4
|
+
import { Typography, Row } from "antd";
|
|
5
|
+
import { useFormContext } from "../Context";
|
|
6
|
+
|
|
7
|
+
interface HelperProps {
|
|
8
|
+
helper?: HItemProps["helper"];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Index: React.FC<HelperProps> = ({ helper }) => {
|
|
12
|
+
const { form } = useFormContext();
|
|
13
|
+
if (!helper) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (typeof helper === "function") {
|
|
17
|
+
return (
|
|
18
|
+
<Typography.Text type={"secondary"}>
|
|
19
|
+
{helper(form as FormInstance)}
|
|
20
|
+
</Typography.Text>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return <Typography.Text type={"secondary"}>{helper}</Typography.Text>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default Index;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Form } from "antd";
|
|
2
|
+
import type { FormItemWithRender } from "../modal";
|
|
3
|
+
import BasicItem from "./BasicItem";
|
|
4
|
+
import { useShouldUpdate } from "./hooks";
|
|
5
|
+
const { Item } = Form;
|
|
6
|
+
export default ({
|
|
7
|
+
shouldUpdate,
|
|
8
|
+
dependencies,
|
|
9
|
+
hide,
|
|
10
|
+
...props
|
|
11
|
+
}: FormItemWithRender) => {
|
|
12
|
+
const resultShouldUpdate = useShouldUpdate({ shouldUpdate, hide });
|
|
13
|
+
return (
|
|
14
|
+
<Item shouldUpdate={resultShouldUpdate} dependencies={dependencies}>
|
|
15
|
+
{() => {
|
|
16
|
+
return <BasicItem hide={hide} {...props} />;
|
|
17
|
+
}}
|
|
18
|
+
</Item>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import UpFormItem from "./UpFormItem";
|
|
2
|
+
import RegularFormItem from "./RegularFormItem";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import type {
|
|
5
|
+
FormItemWithRender,
|
|
6
|
+
HFormInstance,
|
|
7
|
+
} from "@/components/Form/modal";
|
|
8
|
+
import type { HItemProps } from "@/components/Form/modal";
|
|
9
|
+
|
|
10
|
+
export const useFormItemDomControl = ({
|
|
11
|
+
shouldUpdate,
|
|
12
|
+
hide,
|
|
13
|
+
dependencies,
|
|
14
|
+
}: FormItemWithRender) => {
|
|
15
|
+
return useMemo(() => {
|
|
16
|
+
if (shouldUpdate || typeof hide === "function" || dependencies) {
|
|
17
|
+
return UpFormItem;
|
|
18
|
+
}
|
|
19
|
+
return RegularFormItem;
|
|
20
|
+
}, [shouldUpdate, hide]);
|
|
21
|
+
}; //更新或者不更新组件
|
|
22
|
+
|
|
23
|
+
interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
|
|
24
|
+
form: HFormInstance;
|
|
25
|
+
}
|
|
26
|
+
export const useShouldUpdate = ({
|
|
27
|
+
hide,
|
|
28
|
+
shouldUpdate,
|
|
29
|
+
}: Omit<HItemProps, "name">) => {
|
|
30
|
+
if (typeof hide === "function" && !shouldUpdate) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return shouldUpdate;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const useHide = ({ hide, form }: UseHideUpItemModal) => {
|
|
37
|
+
if (hide === true) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (typeof hide === "function") {
|
|
41
|
+
return hide(form);
|
|
42
|
+
}
|
|
43
|
+
return !!hide;
|
|
44
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useFormItemDomControl } from "./hooks";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import type { FormItemWithRender } from "../modal";
|
|
4
|
+
|
|
5
|
+
export default (props: FormItemWithRender) => {
|
|
6
|
+
const Component = useFormItemDomControl(props);
|
|
7
|
+
return <Component {...props} />;
|
|
8
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useFormContext } from "./Context";
|
|
2
|
+
import type { HFormItemProps } from "@/components/Form/modal";
|
|
3
|
+
import React, { useEffect } from "react";
|
|
4
|
+
import type { ConnectConfigModal } from "@/components/Form/modal";
|
|
5
|
+
import type { addFormatItemModal } from "@/components/Form/modal";
|
|
6
|
+
import type { ConnectResultProps } from "@/components/Form/modal";
|
|
7
|
+
|
|
8
|
+
const formatMaker = (
|
|
9
|
+
itemProps: HFormItemProps,
|
|
10
|
+
formats?: addFormatItemModal
|
|
11
|
+
) => {
|
|
12
|
+
if (!formats) {
|
|
13
|
+
return formats;
|
|
14
|
+
}
|
|
15
|
+
const { inputValue, outputValue } = formats;
|
|
16
|
+
return {
|
|
17
|
+
inputValue: (value) => {
|
|
18
|
+
return inputValue(itemProps, value);
|
|
19
|
+
},
|
|
20
|
+
outputValue: (value) => {
|
|
21
|
+
return outputValue(itemProps, value);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default (
|
|
27
|
+
Component: React.FunctionComponent | React.ComponentClass,
|
|
28
|
+
config: ConnectConfigModal = {}
|
|
29
|
+
) => {
|
|
30
|
+
const { format = {} } = config;
|
|
31
|
+
return (props: HFormItemProps) => {
|
|
32
|
+
const { name } = props;
|
|
33
|
+
|
|
34
|
+
const { form, valueType = "float" } = useFormContext();
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
form?.addFormat(name, formatMaker(props, format[valueType]));
|
|
38
|
+
}, [valueType, props]);
|
|
39
|
+
|
|
40
|
+
const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
|
|
41
|
+
form?.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return React.createElement<ConnectResultProps>(Component, {
|
|
45
|
+
...props,
|
|
46
|
+
addFormat,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useFormContext } from "./Context";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
interface InitSetProps {
|
|
4
|
+
initValues?: Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
export default ({ initValues }: InitSetProps) => {
|
|
7
|
+
const { form } = useFormContext();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
form.initValues(initValues);
|
|
10
|
+
}, []);
|
|
11
|
+
return <></>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { HoverModal } from "./modal";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { QuestionCircleOutlined } from "@ant-design/icons";
|
|
4
|
+
import { Tooltip } from "antd";
|
|
5
|
+
import { useClassName } from "../hooks";
|
|
6
|
+
|
|
7
|
+
interface IProps {
|
|
8
|
+
labelWidth?: number;
|
|
9
|
+
hover?: string | HoverModal;
|
|
10
|
+
colon?: boolean;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
}
|
|
13
|
+
const useHover = ({ hover }: IProps) => {
|
|
14
|
+
if (!hover || typeof hover === "string") {
|
|
15
|
+
return {
|
|
16
|
+
text: hover,
|
|
17
|
+
icon: <QuestionCircleOutlined />,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return hover;
|
|
21
|
+
};
|
|
22
|
+
const Index: React.FC<IProps> = ({
|
|
23
|
+
labelWidth,
|
|
24
|
+
children,
|
|
25
|
+
colon,
|
|
26
|
+
required,
|
|
27
|
+
hover,
|
|
28
|
+
}) => {
|
|
29
|
+
const { text, icon } = useHover({ hover });
|
|
30
|
+
const array = [
|
|
31
|
+
colon ? "hw-form-item-colon" : "",
|
|
32
|
+
required ? "hw-form-item-required" : "",
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const className = useClassName(array);
|
|
36
|
+
return (
|
|
37
|
+
<div style={{ width: labelWidth }} className={className}>
|
|
38
|
+
{children}
|
|
39
|
+
{text && (
|
|
40
|
+
<span style={{ marginLeft: 4 }}>
|
|
41
|
+
<Tooltip placement="top" title={text}>
|
|
42
|
+
{icon}
|
|
43
|
+
</Tooltip>
|
|
44
|
+
</span>
|
|
45
|
+
)}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default Index;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import HSelect from "../Select";
|
|
2
|
+
import HInput from "../Input";
|
|
3
|
+
import HInputNumber from "../Input/InputNumber";
|
|
4
|
+
import HSelectInput from "../Input/SelectInput";
|
|
5
|
+
import HButtonInput from "../Input/ButtonInput";
|
|
6
|
+
import HCheckboxGroup from "../CheckboxGroup";
|
|
7
|
+
import HCheckBox from "../CheckboxGroup/CheckBox";
|
|
8
|
+
import HRadioGroup from "../RadioGroup";
|
|
9
|
+
import HSwitch from "../Switch";
|
|
10
|
+
import HDatePicker from "../TDPicker";
|
|
11
|
+
import HRangePicker from "../TDPicker/RangePicker";
|
|
12
|
+
import HTimePicker from "../TDPicker/TimePicker";
|
|
13
|
+
import HUpload from "../Upload";
|
|
14
|
+
import HUrlUpload from "../Upload/UrlUpload";
|
|
15
|
+
import HSubmit from "../Submit";
|
|
16
|
+
import FormConfigProvider from "../Form/Context/FormConfigProvider";
|
|
17
|
+
|
|
18
|
+
export const placeholderConfig = {
|
|
19
|
+
inputType: ["input", "inputNumber", "selectInput", "buttonInput"],
|
|
20
|
+
selectType: ["select", "datePicker", "timePicker"],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
select: HSelect,
|
|
25
|
+
inputNumber: HInputNumber,
|
|
26
|
+
selectInput: HSelectInput,
|
|
27
|
+
buttonInput: HButtonInput,
|
|
28
|
+
checkboxGroup: HCheckboxGroup,
|
|
29
|
+
checkBox: HCheckBox,
|
|
30
|
+
radioGroup: HRadioGroup,
|
|
31
|
+
switch: HSwitch,
|
|
32
|
+
datePicker: HDatePicker,
|
|
33
|
+
rangePicker: HRangePicker,
|
|
34
|
+
timePicker: HTimePicker,
|
|
35
|
+
input: HInput,
|
|
36
|
+
upload: HUpload,
|
|
37
|
+
urlUpload: HUrlUpload,
|
|
38
|
+
submit: HSubmit,
|
|
39
|
+
formConfigProvider: FormConfigProvider,
|
|
40
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useRequest } from "ahooks";
|
|
2
|
+
import type { HFormProps } from "@/components/Form/modal";
|
|
3
|
+
import useHForm from "./useHForm";
|
|
4
|
+
import type { HFormInstance } from "@/components/Form/modal";
|
|
5
|
+
export const useCurrentForm = (form?: HFormInstance) => {
|
|
6
|
+
const selfForm = useHForm();
|
|
7
|
+
return form || selfForm;
|
|
8
|
+
};
|
|
9
|
+
type ParamsModal = Omit<HFormProps, "configData">;
|
|
10
|
+
|
|
11
|
+
export const useSub = ({ request, onFinish, form }: ParamsModal) => {
|
|
12
|
+
return useRequest(
|
|
13
|
+
async (value) => {
|
|
14
|
+
const subVal = form?.outputValues(value);
|
|
15
|
+
if (request) {
|
|
16
|
+
await request(subVal);
|
|
17
|
+
}
|
|
18
|
+
onFinish?.(subVal);
|
|
19
|
+
},
|
|
20
|
+
{ manual: true }
|
|
21
|
+
);
|
|
22
|
+
}; //提交
|
|
23
|
+
|
|
24
|
+
export const useInit = ({ infoRequest, initialValues = {} }: ParamsModal) => {
|
|
25
|
+
const {
|
|
26
|
+
run: infoRun,
|
|
27
|
+
loading: infoLoading,
|
|
28
|
+
error: infoErr,
|
|
29
|
+
data: infoData,
|
|
30
|
+
} = useRequest(async () => {
|
|
31
|
+
if (infoRequest) {
|
|
32
|
+
return infoRequest();
|
|
33
|
+
}
|
|
34
|
+
return initialValues;
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
infoRun,
|
|
38
|
+
infoLoading,
|
|
39
|
+
infoErr,
|
|
40
|
+
infoData,
|
|
41
|
+
};
|
|
42
|
+
}; //初始化
|