@hw-component/form 0.0.2-bate → 0.0.2-beta-v2
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/CheckboxGroup/index.d.ts +1 -1
- package/es/CheckboxGroup/index.js +4 -2
- package/es/DialogForm/DrawerForm/Footer.d.ts +4 -0
- package/es/DialogForm/DrawerForm/Footer.js +23 -0
- package/es/DialogForm/DrawerForm/Title.d.ts +4 -0
- package/es/DialogForm/DrawerForm/Title.js +18 -0
- package/es/DialogForm/DrawerForm/index.d.ts +4 -0
- package/es/DialogForm/DrawerForm/index.js +111 -0
- package/es/DialogForm/ModalForm.d.ts +4 -0
- package/es/DialogForm/ModalForm.js +89 -0
- package/es/DialogForm/hooks.d.ts +14 -0
- package/es/DialogForm/hooks.js +124 -0
- package/es/DialogForm/modal.d.ts +25 -0
- package/es/Form/HFormConnect.d.ts +1 -2
- package/es/Form/HFormConnect.js +17 -16
- package/es/Form/InitSet.d.ts +1 -4
- package/es/Form/InitSet.js +2 -3
- package/es/Form/config.d.ts +5 -4
- package/es/Form/config.js +6 -4
- package/es/Form/hooks/index.d.ts +0 -6
- package/es/Form/hooks/index.js +1 -33
- package/es/Form/hooks/useHForm.js +72 -15
- package/es/Form/index.js +46 -15
- package/es/Form/modal.d.ts +20 -8
- package/es/Input/SelectInput.d.ts +2 -2
- package/es/Input/SelectInput.js +8 -5
- package/es/Input/modal.d.ts +2 -0
- package/es/Select/hooks/norHooks.d.ts +1 -1
- package/es/TDPicker/RangePicker.d.ts +1 -1
- package/es/TDPicker/RangePicker.js +4 -2
- package/es/TextArea/index.js +21 -0
- package/es/Upload/UrlUpload/index.d.ts +2 -2
- package/es/Upload/UrlUpload/index.js +3 -3
- package/es/Upload/hooks/customRequest.js +99 -36
- package/es/Upload/index.d.ts +1 -2
- package/es/Upload/index.js +40 -5
- package/es/Upload/modal.d.ts +2 -0
- package/es/config.js +4 -4
- package/es/index.css +1 -1
- package/es/index.d.ts +8 -4
- package/es/index.js +7 -1
- package/lib/CheckboxGroup/index.d.ts +1 -1
- package/lib/CheckboxGroup/index.js +4 -2
- package/lib/DialogForm/DrawerForm/Footer.d.ts +4 -0
- package/lib/DialogForm/DrawerForm/Footer.js +26 -0
- package/lib/DialogForm/DrawerForm/Title.d.ts +4 -0
- package/lib/DialogForm/DrawerForm/Title.js +21 -0
- package/lib/DialogForm/DrawerForm/index.d.ts +4 -0
- package/lib/DialogForm/DrawerForm/index.js +114 -0
- package/lib/DialogForm/ModalForm.d.ts +4 -0
- package/lib/DialogForm/ModalForm.js +92 -0
- package/lib/DialogForm/hooks.d.ts +14 -0
- package/lib/DialogForm/hooks.js +128 -0
- package/lib/DialogForm/modal.d.ts +25 -0
- package/lib/Form/HFormConnect.d.ts +1 -2
- package/lib/Form/HFormConnect.js +17 -16
- package/lib/Form/InitSet.d.ts +1 -4
- package/lib/Form/InitSet.js +2 -3
- package/lib/Form/config.d.ts +5 -4
- package/lib/Form/config.js +3 -1
- package/lib/Form/hooks/index.d.ts +0 -6
- package/lib/Form/hooks/index.js +0 -33
- package/lib/Form/hooks/useHForm.js +72 -15
- package/lib/Form/index.js +53 -22
- package/lib/Form/modal.d.ts +20 -8
- package/lib/Input/SelectInput.d.ts +2 -2
- package/lib/Input/SelectInput.js +8 -5
- package/lib/Input/modal.d.ts +2 -0
- package/lib/Select/hooks/norHooks.d.ts +1 -1
- package/lib/TDPicker/RangePicker.d.ts +1 -1
- package/lib/TDPicker/RangePicker.js +4 -2
- package/lib/TextArea/index.js +24 -0
- package/lib/Upload/UrlUpload/index.d.ts +2 -2
- package/lib/Upload/UrlUpload/index.js +3 -3
- package/lib/Upload/hooks/customRequest.js +99 -36
- package/lib/Upload/index.d.ts +1 -2
- package/lib/Upload/index.js +40 -5
- package/lib/Upload/modal.d.ts +2 -0
- package/lib/config.js +4 -4
- package/lib/index.css +1 -1
- package/lib/index.d.ts +8 -4
- package/lib/index.js +10 -0
- package/package.json +1 -1
- package/src/components/CheckboxGroup/index.tsx +2 -2
- package/src/components/DialogForm/DrawerForm/Footer.tsx +19 -0
- package/src/components/DialogForm/DrawerForm/Title.tsx +12 -0
- package/src/components/DialogForm/DrawerForm/index.tsx +85 -0
- package/src/components/DialogForm/ModalForm.tsx +60 -0
- package/src/components/DialogForm/hooks.ts +87 -0
- package/src/components/DialogForm/modal.ts +27 -0
- package/src/components/Form/FormItem/Helper.tsx +3 -4
- package/src/components/Form/HFormConnect.tsx +26 -8
- package/src/components/Form/InitSet.tsx +3 -5
- package/src/components/Form/config.ts +2 -1
- package/src/components/Form/hooks/index.ts +0 -20
- package/src/components/Form/hooks/useHForm.ts +67 -14
- package/src/components/Form/index.less +1 -1
- package/src/components/Form/index.tsx +25 -7
- package/src/components/Form/modal.ts +22 -10
- package/src/components/Input/SelectInput.tsx +4 -2
- package/src/components/Input/modal.ts +2 -0
- package/src/components/TDPicker/RangePicker.tsx +5 -6
- package/src/components/Upload/UrlUpload/index.tsx +2 -2
- package/src/components/Upload/hooks/customRequest.ts +57 -14
- package/src/components/Upload/index.tsx +40 -7
- package/src/components/Upload/modal.ts +2 -0
- package/src/components/config.ts +4 -4
- package/src/components/index.tsx +6 -0
- package/src/pages/DrawerForm/index.tsx +127 -0
- package/src/pages/Form/index.tsx +3 -0
- package/src/pages/ModalForm/index.tsx +127 -0
- package/src/routes.tsx +12 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Row, Space, Button } from "antd";
|
|
2
|
+
import type { DialogFormProps } from "../modal";
|
|
3
|
+
|
|
4
|
+
export default ({
|
|
5
|
+
onCancel,
|
|
6
|
+
onOk,
|
|
7
|
+
confirmLoading,
|
|
8
|
+
}: Omit<DialogFormProps, "configData">) => {
|
|
9
|
+
return (
|
|
10
|
+
<Row justify={"end"}>
|
|
11
|
+
<Space size={"middle"}>
|
|
12
|
+
<Button onClick={onCancel}>关闭</Button>
|
|
13
|
+
<Button type={"primary"} onClick={onOk} loading={confirmLoading}>
|
|
14
|
+
确定
|
|
15
|
+
</Button>
|
|
16
|
+
</Space>
|
|
17
|
+
</Row>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ModalProps } from "antd";
|
|
2
|
+
import { Row } from "antd";
|
|
3
|
+
import { CloseOutlined } from "@ant-design/icons";
|
|
4
|
+
|
|
5
|
+
export default ({ title, closable, onCancel }: ModalProps) => {
|
|
6
|
+
return (
|
|
7
|
+
<Row justify={"space-between"}>
|
|
8
|
+
<div>{title}</div>
|
|
9
|
+
{closable && <CloseOutlined onClick={onCancel} />}
|
|
10
|
+
</Row>
|
|
11
|
+
);
|
|
12
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Drawer } from "antd";
|
|
2
|
+
import type { DialogFormProps } from "../modal";
|
|
3
|
+
import { useCurrentForm, useModifyProps, useSub } from "../hooks";
|
|
4
|
+
import HForm from "../../Form";
|
|
5
|
+
import Title from "./Title";
|
|
6
|
+
import Footer from "./Footer";
|
|
7
|
+
export default ({
|
|
8
|
+
visible,
|
|
9
|
+
title,
|
|
10
|
+
onCancel,
|
|
11
|
+
configData,
|
|
12
|
+
infoRequest,
|
|
13
|
+
request,
|
|
14
|
+
afterClose,
|
|
15
|
+
dialogForm,
|
|
16
|
+
closable = true,
|
|
17
|
+
initialValues = {},
|
|
18
|
+
labelWidth,
|
|
19
|
+
onOk,
|
|
20
|
+
onFinish,
|
|
21
|
+
size,
|
|
22
|
+
form,
|
|
23
|
+
footer,
|
|
24
|
+
...props
|
|
25
|
+
}: DialogFormProps) => {
|
|
26
|
+
const currentForm = useCurrentForm(dialogForm);
|
|
27
|
+
const {
|
|
28
|
+
modalVisible,
|
|
29
|
+
modalFormData,
|
|
30
|
+
setModalVisible,
|
|
31
|
+
initValue,
|
|
32
|
+
onAfterClose,
|
|
33
|
+
} = useModifyProps({
|
|
34
|
+
configData,
|
|
35
|
+
visible,
|
|
36
|
+
initialValues,
|
|
37
|
+
dialogForm: currentForm,
|
|
38
|
+
});
|
|
39
|
+
const cancel = (e) => {
|
|
40
|
+
onAfterClose();
|
|
41
|
+
if (onCancel) {
|
|
42
|
+
return onCancel?.(e);
|
|
43
|
+
}
|
|
44
|
+
setModalVisible(false);
|
|
45
|
+
};
|
|
46
|
+
const { loading, run } = useSub({ request, onFinish });
|
|
47
|
+
const footerComponent = () => {
|
|
48
|
+
if (footer === null) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return (
|
|
52
|
+
footer || (
|
|
53
|
+
<Footer
|
|
54
|
+
onCancel={cancel}
|
|
55
|
+
onOk={currentForm.submit}
|
|
56
|
+
confirmLoading={loading}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
return (
|
|
62
|
+
<Drawer
|
|
63
|
+
visible={modalVisible}
|
|
64
|
+
title={<Title title={title} closable={closable} onCancel={cancel} />}
|
|
65
|
+
{...props}
|
|
66
|
+
onClose={cancel}
|
|
67
|
+
closable={false}
|
|
68
|
+
destroyOnClose={true}
|
|
69
|
+
footer={footerComponent()}
|
|
70
|
+
>
|
|
71
|
+
<HForm
|
|
72
|
+
configData={modalFormData}
|
|
73
|
+
initialValues={initValue}
|
|
74
|
+
{...props}
|
|
75
|
+
form={currentForm}
|
|
76
|
+
onFinish={async (values) => {
|
|
77
|
+
await run(values);
|
|
78
|
+
setModalVisible(false);
|
|
79
|
+
}}
|
|
80
|
+
infoRequest={infoRequest}
|
|
81
|
+
labelWidth={labelWidth}
|
|
82
|
+
/>
|
|
83
|
+
</Drawer>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Modal } from "antd";
|
|
2
|
+
import type { DialogFormProps } from "./modal";
|
|
3
|
+
import HForm from "../Form";
|
|
4
|
+
import { useCurrentForm, useModifyProps, useSub } from "./hooks";
|
|
5
|
+
export default ({
|
|
6
|
+
visible,
|
|
7
|
+
title,
|
|
8
|
+
onCancel,
|
|
9
|
+
configData,
|
|
10
|
+
infoRequest,
|
|
11
|
+
request,
|
|
12
|
+
afterClose,
|
|
13
|
+
dialogForm,
|
|
14
|
+
initialValues = {},
|
|
15
|
+
onFinish,
|
|
16
|
+
...props
|
|
17
|
+
}: DialogFormProps) => {
|
|
18
|
+
const currentForm = useCurrentForm(dialogForm);
|
|
19
|
+
const { modalVisible, modalFormData, setModalVisible, initValue } =
|
|
20
|
+
useModifyProps({
|
|
21
|
+
configData,
|
|
22
|
+
visible,
|
|
23
|
+
initialValues,
|
|
24
|
+
dialogForm: currentForm,
|
|
25
|
+
});
|
|
26
|
+
const cancel = (e) => {
|
|
27
|
+
if (onCancel) {
|
|
28
|
+
return onCancel?.(e);
|
|
29
|
+
}
|
|
30
|
+
setModalVisible(false);
|
|
31
|
+
};
|
|
32
|
+
const { loading, run } = useSub({ request, onFinish });
|
|
33
|
+
return (
|
|
34
|
+
<Modal
|
|
35
|
+
title={title}
|
|
36
|
+
visible={modalVisible}
|
|
37
|
+
onCancel={cancel}
|
|
38
|
+
confirmLoading={loading}
|
|
39
|
+
afterClose={() => {
|
|
40
|
+
currentForm.resetFields();
|
|
41
|
+
afterClose?.();
|
|
42
|
+
}}
|
|
43
|
+
{...props}
|
|
44
|
+
onOk={currentForm.submit}
|
|
45
|
+
destroyOnClose={true}
|
|
46
|
+
>
|
|
47
|
+
<HForm
|
|
48
|
+
configData={modalFormData}
|
|
49
|
+
initialValues={initValue}
|
|
50
|
+
onFinish={async (values) => {
|
|
51
|
+
await run(values);
|
|
52
|
+
setModalVisible(false);
|
|
53
|
+
}}
|
|
54
|
+
{...props}
|
|
55
|
+
form={currentForm}
|
|
56
|
+
infoRequest={infoRequest}
|
|
57
|
+
/>
|
|
58
|
+
</Modal>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import useHForm from "../Form/hooks/useHForm";
|
|
3
|
+
import type {
|
|
4
|
+
DialogFormProps,
|
|
5
|
+
HDialogFormInstance,
|
|
6
|
+
ModifyPropsModal,
|
|
7
|
+
} from "./modal";
|
|
8
|
+
import { useRequest } from "ahooks";
|
|
9
|
+
|
|
10
|
+
export const useModifyProps = ({
|
|
11
|
+
visible,
|
|
12
|
+
configData,
|
|
13
|
+
initialValues,
|
|
14
|
+
dialogForm,
|
|
15
|
+
afterClose,
|
|
16
|
+
}: ModifyPropsModal) => {
|
|
17
|
+
const [modalVisible, setModalVisible] = useState(visible);
|
|
18
|
+
const [modalFormData, setModalFormData] = useState(configData);
|
|
19
|
+
const [initValue, setInitValue] = useState(initialValues);
|
|
20
|
+
const onAfterClose = () => {
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
dialogForm.resetFields();
|
|
23
|
+
afterClose?.();
|
|
24
|
+
}, 0);
|
|
25
|
+
};
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
setModalVisible(visible);
|
|
28
|
+
}, [visible]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setModalFormData(configData);
|
|
31
|
+
}, [configData]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
dialogForm.show = (params = {}) => {
|
|
34
|
+
const {
|
|
35
|
+
configData: changeConfigData,
|
|
36
|
+
initialValues: changeInitialValues,
|
|
37
|
+
} = params;
|
|
38
|
+
if (!!changeConfigData) {
|
|
39
|
+
setModalFormData(changeConfigData);
|
|
40
|
+
}
|
|
41
|
+
setInitValue(changeInitialValues);
|
|
42
|
+
setModalVisible(true);
|
|
43
|
+
};
|
|
44
|
+
dialogForm.hide = () => {
|
|
45
|
+
setModalVisible(false);
|
|
46
|
+
onAfterClose();
|
|
47
|
+
};
|
|
48
|
+
}, [afterClose]);
|
|
49
|
+
return {
|
|
50
|
+
modalFormData,
|
|
51
|
+
modalVisible,
|
|
52
|
+
setModalVisible,
|
|
53
|
+
setModalFormData,
|
|
54
|
+
initValue,
|
|
55
|
+
setInitValue,
|
|
56
|
+
onAfterClose,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export const useHDialogForm = () => {
|
|
60
|
+
const hForm = useHForm();
|
|
61
|
+
return useMemo<HDialogFormInstance>(() => {
|
|
62
|
+
return {
|
|
63
|
+
...hForm,
|
|
64
|
+
show: (params) => {},
|
|
65
|
+
hide: () => {},
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const useCurrentForm = (hDialogForm?: HDialogFormInstance) => {
|
|
71
|
+
const defaultHModalForm = useHDialogForm();
|
|
72
|
+
return hDialogForm || defaultHModalForm;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const useSub = ({ request, onFinish }: Partial<DialogFormProps>) => {
|
|
76
|
+
return useRequest(
|
|
77
|
+
async (values) => {
|
|
78
|
+
if (onFinish) {
|
|
79
|
+
return onFinish(values);
|
|
80
|
+
}
|
|
81
|
+
if (request) {
|
|
82
|
+
return request(values);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{ manual: true }
|
|
86
|
+
);
|
|
87
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ModalProps } from "antd";
|
|
2
|
+
import type { HFormInstance, HItemProps, HFormProps } from "../Form/modal";
|
|
3
|
+
import type { PromiseFnResult } from "../modal";
|
|
4
|
+
|
|
5
|
+
type RootProps = HFormProps & ModalProps;
|
|
6
|
+
|
|
7
|
+
export interface ModifyPropsModal {
|
|
8
|
+
configData: HItemProps[];
|
|
9
|
+
visible?: boolean;
|
|
10
|
+
initialValues?: Record<string, any>;
|
|
11
|
+
dialogForm: HDialogFormInstance;
|
|
12
|
+
afterClose?: VoidFunction;
|
|
13
|
+
}
|
|
14
|
+
export interface ShowParamsModal {
|
|
15
|
+
configData?: HItemProps[];
|
|
16
|
+
visible?: boolean;
|
|
17
|
+
initialValues?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface HDialogFormInstance extends HFormInstance {
|
|
21
|
+
show: (data?: ShowParamsModal) => void;
|
|
22
|
+
hide: VoidFunction;
|
|
23
|
+
}
|
|
24
|
+
export interface DialogFormProps extends Omit<RootProps, "onFinish"> {
|
|
25
|
+
dialogForm?: HDialogFormInstance;
|
|
26
|
+
onFinish?: PromiseFnResult;
|
|
27
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { HItemProps } from "@/components/Form/modal";
|
|
3
|
-
import
|
|
4
|
-
import { Typography, Row } from "antd";
|
|
2
|
+
import type { HItemProps, HFormInstance } from "@/components/Form/modal";
|
|
3
|
+
import { Typography } from "antd";
|
|
5
4
|
import { useFormContext } from "../Context";
|
|
6
5
|
|
|
7
6
|
interface HelperProps {
|
|
@@ -16,7 +15,7 @@ const Index: React.FC<HelperProps> = ({ helper }) => {
|
|
|
16
15
|
if (typeof helper === "function") {
|
|
17
16
|
return (
|
|
18
17
|
<Typography.Text type={"secondary"}>
|
|
19
|
-
{helper(form as
|
|
18
|
+
{helper(form as HFormInstance)}
|
|
20
19
|
</Typography.Text>
|
|
21
20
|
);
|
|
22
21
|
}
|
|
@@ -4,6 +4,7 @@ import React, { useEffect } from "react";
|
|
|
4
4
|
import type { ConnectConfigModal } from "@/components/Form/modal";
|
|
5
5
|
import type { addFormatItemModal } from "@/components/Form/modal";
|
|
6
6
|
import type { ConnectResultProps } from "@/components/Form/modal";
|
|
7
|
+
import type { argsFn } from "@/components/Form/modal";
|
|
7
8
|
|
|
8
9
|
const formatMaker = (
|
|
9
10
|
itemProps: HFormItemProps,
|
|
@@ -24,12 +25,18 @@ const formatMaker = (
|
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
export default (
|
|
27
|
-
|
|
28
|
+
component:
|
|
29
|
+
| React.FunctionComponent
|
|
30
|
+
| React.ComponentClass
|
|
31
|
+
| React.ForwardRefRenderFunction<any, any>,
|
|
28
32
|
config: ConnectConfigModal = {}
|
|
29
33
|
) => {
|
|
30
34
|
const { format = {} } = config;
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
const Index: React.ForwardRefRenderFunction<any, HFormItemProps> = (
|
|
36
|
+
props: HFormItemProps,
|
|
37
|
+
ref
|
|
38
|
+
) => {
|
|
39
|
+
const { name = "" } = props;
|
|
33
40
|
|
|
34
41
|
const { form, valueType = "float" } = useFormContext();
|
|
35
42
|
|
|
@@ -40,10 +47,21 @@ export default (
|
|
|
40
47
|
const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
|
|
41
48
|
form?.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
42
49
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
const addDispatchListener = (key: string, fn: argsFn) => {
|
|
51
|
+
form?.addDispatchListener({ key, name }, fn);
|
|
52
|
+
};
|
|
53
|
+
const Component = component as React.ForwardRefRenderFunction<
|
|
54
|
+
any,
|
|
55
|
+
ConnectResultProps
|
|
56
|
+
>;
|
|
57
|
+
return (
|
|
58
|
+
<Component
|
|
59
|
+
{...props}
|
|
60
|
+
addFormat={addFormat}
|
|
61
|
+
addDispatchListener={addDispatchListener}
|
|
62
|
+
ref={ref}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
48
65
|
};
|
|
66
|
+
return React.forwardRef(Index);
|
|
49
67
|
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { useFormContext } from "./Context";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export default ({ initValues }: InitSetProps) => {
|
|
3
|
+
|
|
4
|
+
export default () => {
|
|
7
5
|
const { form } = useFormContext();
|
|
8
6
|
useEffect(() => {
|
|
9
|
-
form.initValues(
|
|
7
|
+
form.initValues();
|
|
10
8
|
}, []);
|
|
11
9
|
return <></>;
|
|
12
10
|
};
|
|
@@ -14,7 +14,7 @@ import HUpload from "../Upload";
|
|
|
14
14
|
import HUrlUpload from "../Upload/UrlUpload";
|
|
15
15
|
import HSubmit from "../Submit";
|
|
16
16
|
import FormConfigProvider from "../Form/Context/FormConfigProvider";
|
|
17
|
-
|
|
17
|
+
import TextArea from "../TextArea";
|
|
18
18
|
export const placeholderConfig = {
|
|
19
19
|
inputType: ["input", "inputNumber", "selectInput", "buttonInput"],
|
|
20
20
|
selectType: ["select", "datePicker", "timePicker"],
|
|
@@ -37,4 +37,5 @@ export default {
|
|
|
37
37
|
urlUpload: HUrlUpload,
|
|
38
38
|
submit: HSubmit,
|
|
39
39
|
formConfigProvider: FormConfigProvider,
|
|
40
|
+
textArea: TextArea,
|
|
40
41
|
};
|
|
@@ -20,23 +20,3 @@ export const useSub = ({ request, onFinish, form }: ParamsModal) => {
|
|
|
20
20
|
{ manual: true }
|
|
21
21
|
);
|
|
22
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
|
-
}; //初始化
|
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { Form } from "antd";
|
|
3
3
|
import type { FormatItemModal, HFormInstance } from "../modal";
|
|
4
|
+
import type { argsFn } from "../modal";
|
|
5
|
+
|
|
6
|
+
interface DispatchItemData {
|
|
7
|
+
keysFn: Record<string, argsFn>;
|
|
8
|
+
defaultFn: argsFn[];
|
|
9
|
+
}
|
|
4
10
|
|
|
5
11
|
export default () => {
|
|
6
12
|
const [form] = Form.useForm();
|
|
7
13
|
return useMemo<HFormInstance>(() => {
|
|
8
14
|
const formatSourceData: Record<string, FormatItemModal> = {};
|
|
9
|
-
let dispatchSourceData: Record<string,
|
|
15
|
+
let dispatchSourceData: Record<string, DispatchItemData> = {};
|
|
16
|
+
let cacheValues: Record<string, any> = {};
|
|
17
|
+
const norAddItemDispatch = (name, fn) => {
|
|
18
|
+
if (!name) {
|
|
19
|
+
return {
|
|
20
|
+
keysFn: {},
|
|
21
|
+
defaultFn: [fn],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
keysFn: {
|
|
26
|
+
[name]: fn,
|
|
27
|
+
},
|
|
28
|
+
defaultFn: [],
|
|
29
|
+
};
|
|
30
|
+
};
|
|
10
31
|
return {
|
|
32
|
+
initValues() {
|
|
33
|
+
if (cacheValues) {
|
|
34
|
+
const newValue = this.formatValues(cacheValues);
|
|
35
|
+
form.setFieldsValue(newValue);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
11
38
|
addFormat(name: string, format?: FormatItemModal) {
|
|
12
39
|
if (!format) {
|
|
13
40
|
return;
|
|
@@ -39,41 +66,67 @@ export default () => {
|
|
|
39
66
|
});
|
|
40
67
|
return newValue;
|
|
41
68
|
}, //转化方法
|
|
42
|
-
dispatch(
|
|
69
|
+
dispatch(action, ...args) {
|
|
70
|
+
const { key, name } = action;
|
|
43
71
|
const items = dispatchSourceData[key];
|
|
44
72
|
if (!items) {
|
|
45
73
|
return;
|
|
46
74
|
}
|
|
47
|
-
|
|
48
|
-
|
|
75
|
+
const { keysFn, defaultFn } = items;
|
|
76
|
+
if (name) {
|
|
77
|
+
return keysFn[name]?.(...args);
|
|
78
|
+
}
|
|
79
|
+
const fnArrays = Object.keys(keysFn).map((itemKey) => {
|
|
80
|
+
return keysFn[itemKey];
|
|
81
|
+
}); //不存在name就合并
|
|
82
|
+
[...fnArrays, ...defaultFn].forEach((fn) => {
|
|
83
|
+
fn(...args);
|
|
49
84
|
});
|
|
50
85
|
},
|
|
51
|
-
addDispatchListener(
|
|
86
|
+
addDispatchListener(action, fn) {
|
|
87
|
+
const { key, name } = action;
|
|
52
88
|
const items = dispatchSourceData[key];
|
|
53
89
|
if (!items) {
|
|
54
|
-
dispatchSourceData[key] =
|
|
90
|
+
dispatchSourceData[key] = norAddItemDispatch(name, fn);
|
|
55
91
|
return;
|
|
56
92
|
}
|
|
57
|
-
items
|
|
58
|
-
|
|
93
|
+
const { keysFn, defaultFn } = items;
|
|
94
|
+
if (name) {
|
|
95
|
+
keysFn[name] = fn;
|
|
96
|
+
} else {
|
|
97
|
+
defaultFn.push(fn);
|
|
98
|
+
}
|
|
99
|
+
dispatchSourceData[key] = {
|
|
100
|
+
keysFn,
|
|
101
|
+
defaultFn,
|
|
102
|
+
};
|
|
59
103
|
},
|
|
60
|
-
removeDispatchListener(
|
|
61
|
-
if (!
|
|
104
|
+
removeDispatchListener(action) {
|
|
105
|
+
if (!action) {
|
|
62
106
|
dispatchSourceData = {};
|
|
63
107
|
return;
|
|
64
108
|
}
|
|
109
|
+
const { key, name } = action;
|
|
110
|
+
const items = dispatchSourceData[key];
|
|
111
|
+
if (!items) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (name) {
|
|
115
|
+
const { keysFn } = items;
|
|
116
|
+
Reflect.deleteProperty(keysFn, name);
|
|
117
|
+
items.keysFn = keysFn;
|
|
118
|
+
dispatchSourceData[key] = items;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
65
121
|
Reflect.deleteProperty(dispatchSourceData, key);
|
|
66
122
|
},
|
|
67
|
-
initValues(value = {}) {
|
|
68
|
-
const newValue = this.formatValues(value);
|
|
69
|
-
form.setFieldsValue(newValue);
|
|
70
|
-
},
|
|
71
123
|
outputValues(value) {
|
|
72
124
|
return this.formatValues(value, "outputValue");
|
|
73
125
|
},
|
|
74
126
|
...form,
|
|
75
127
|
setFieldsValue(values) {
|
|
76
128
|
const newValue = this.formatValues(values);
|
|
129
|
+
cacheValues = values;
|
|
77
130
|
form.setFieldsValue(newValue);
|
|
78
131
|
},
|
|
79
132
|
validateFields(nameList) {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Form } from "antd";
|
|
2
2
|
import type { HFormProps } from "./modal";
|
|
3
3
|
import Item from "./FormItem";
|
|
4
|
-
import { useCurrentForm,
|
|
4
|
+
import { useCurrentForm, useSub } from "./hooks";
|
|
5
5
|
import { FormContext } from "./Context";
|
|
6
6
|
import PageHandler from "../PageHandler";
|
|
7
7
|
import useInitConfigData from "./hooks/useInitConfigData";
|
|
8
|
+
import { useEffect } from "react";
|
|
9
|
+
import { useRequest } from "ahooks";
|
|
8
10
|
import InitSet from "./InitSet";
|
|
11
|
+
|
|
9
12
|
export default ({
|
|
10
13
|
configData,
|
|
11
14
|
labelWidth,
|
|
@@ -28,12 +31,27 @@ export default ({
|
|
|
28
31
|
valueType,
|
|
29
32
|
form: hForm,
|
|
30
33
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const {
|
|
35
|
+
run: infoRun,
|
|
36
|
+
loading: infoLoading,
|
|
37
|
+
error: infoErr,
|
|
38
|
+
data: infoData,
|
|
39
|
+
} = useRequest(async () => {
|
|
40
|
+
let setValue = initialValues;
|
|
41
|
+
if (!initialValues && !infoRequest) {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
if (infoRequest) {
|
|
45
|
+
setValue = await infoRequest();
|
|
46
|
+
}
|
|
47
|
+
hForm.setFieldsValue(setValue);
|
|
48
|
+
return setValue;
|
|
35
49
|
});
|
|
36
|
-
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
return () => {
|
|
52
|
+
hForm.removeDispatchListener();
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
37
55
|
return (
|
|
38
56
|
<PageHandler
|
|
39
57
|
loading={infoLoading}
|
|
@@ -53,8 +71,8 @@ export default ({
|
|
|
53
71
|
/>
|
|
54
72
|
);
|
|
55
73
|
})}
|
|
74
|
+
<InitSet />
|
|
56
75
|
</Form>
|
|
57
|
-
<InitSet initValues={infoData} />
|
|
58
76
|
</FormContext.Provider>
|
|
59
77
|
</PageHandler>
|
|
60
78
|
);
|