@hw-component/form 0.0.9-beta-v19 → 0.0.9-beta-v21
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/.eslintcache +1 -0
- package/.idea/hw-component-form.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/es/Select/modal.d.ts +1 -3
- package/lib/Select/modal.d.ts +1 -3
- package/package.json +1 -1
- package/public/index.html +0 -19
- package/scripts/rollup.config.js +0 -90
- package/scripts/webpack.config.js +0 -76
- package/src/Layout.tsx +0 -61
- package/src/app.tsx +0 -33
- package/src/components/Cascader/index.tsx +0 -31
- package/src/components/CheckboxGroup/CheckBox/index.tsx +0 -38
- package/src/components/CheckboxGroup/hooks.ts +0 -105
- package/src/components/CheckboxGroup/index.tsx +0 -85
- package/src/components/CheckboxGroup/modal.ts +0 -17
- package/src/components/DialogForm/DrawerForm/Footer.tsx +0 -20
- package/src/components/DialogForm/DrawerForm/Title.tsx +0 -12
- package/src/components/DialogForm/DrawerForm/index.tsx +0 -110
- package/src/components/DialogForm/ModalForm.tsx +0 -91
- package/src/components/DialogForm/hooks.ts +0 -122
- package/src/components/DialogForm/modal.ts +0 -44
- package/src/components/Form/Context/FormConfigProvider.tsx +0 -38
- package/src/components/Form/Context/index.tsx +0 -14
- package/src/components/Form/FormItem/BasicItem.tsx +0 -95
- package/src/components/Form/FormItem/Helper.tsx +0 -25
- package/src/components/Form/FormItem/RegularFormItem.tsx +0 -13
- package/src/components/Form/FormItem/UpFormItem.tsx +0 -21
- package/src/components/Form/FormItem/hooks.tsx +0 -54
- package/src/components/Form/FormItem/index.tsx +0 -8
- package/src/components/Form/HFormConnect.tsx +0 -74
- package/src/components/Form/InitSet.tsx +0 -10
- package/src/components/Form/Label.tsx +0 -50
- package/src/components/Form/config.ts +0 -58
- package/src/components/Form/hooks/index.ts +0 -114
- package/src/components/Form/hooks/useDefaultRender.tsx +0 -45
- package/src/components/Form/hooks/useHForm.ts +0 -182
- package/src/components/Form/hooks/useInitConfigData.tsx +0 -194
- package/src/components/Form/index.less +0 -54
- package/src/components/Form/index.tsx +0 -113
- package/src/components/Form/modal.ts +0 -206
- package/src/components/Input/ButtonInput.tsx +0 -47
- package/src/components/Input/ColorInput/Picker.tsx +0 -18
- package/src/components/Input/ColorInput/data.ts +0 -102
- package/src/components/Input/ColorInput/index.less +0 -10
- package/src/components/Input/ColorInput/index.tsx +0 -58
- package/src/components/Input/InputNumber.tsx +0 -5
- package/src/components/Input/SelectInput.tsx +0 -75
- package/src/components/Input/TrimInput.tsx +0 -26
- package/src/components/Input/VerificationCodeInput.tsx +0 -74
- package/src/components/Input/defaultConfig.ts +0 -8
- package/src/components/Input/index.tsx +0 -26
- package/src/components/Input/modal.ts +0 -40
- package/src/components/PageHandler/ErrorComponent.tsx +0 -20
- package/src/components/PageHandler/LoadingComponent.tsx +0 -9
- package/src/components/PageHandler/index.tsx +0 -14
- package/src/components/PageHandler/modal.ts +0 -6
- package/src/components/RadioGroup/index.tsx +0 -45
- package/src/components/Select/components/AllSelect.tsx +0 -54
- package/src/components/Select/components/CheckBoxOption.tsx +0 -14
- package/src/components/Select/components/DropdownComponent.tsx +0 -36
- package/src/components/Select/components/NoFindItem.tsx +0 -7
- package/src/components/Select/components/NotFoundContent.tsx +0 -25
- package/src/components/Select/defaultConfig.tsx +0 -23
- package/src/components/Select/hooks/changeHooks.tsx +0 -159
- package/src/components/Select/hooks/norHooks.ts +0 -85
- package/src/components/Select/index.less +0 -22
- package/src/components/Select/index.tsx +0 -126
- package/src/components/Select/modal.ts +0 -38
- package/src/components/Select/utils.ts +0 -18
- package/src/components/Submit/components.tsx +0 -57
- package/src/components/Submit/hooks.ts +0 -31
- package/src/components/Submit/index.tsx +0 -33
- package/src/components/Switch/index.tsx +0 -77
- package/src/components/TDPicker/RangePicker.tsx +0 -109
- package/src/components/TDPicker/TimePicker.tsx +0 -29
- package/src/components/TDPicker/hooks.ts +0 -150
- package/src/components/TDPicker/index.tsx +0 -33
- package/src/components/TDPicker/modal.ts +0 -48
- package/src/components/TextArea/TrimTextArea.tsx +0 -30
- package/src/components/TextArea/index.tsx +0 -8
- package/src/components/Upload/Btn.tsx +0 -24
- package/src/components/Upload/MediaTypeEle/TypeEle.tsx +0 -26
- package/src/components/Upload/MediaTypeEle/index.tsx +0 -34
- package/src/components/Upload/Preview/index.tsx +0 -14
- package/src/components/Upload/UrlUpload/index.tsx +0 -104
- package/src/components/Upload/enums.ts +0 -5
- package/src/components/Upload/hooks/change.ts +0 -79
- package/src/components/Upload/hooks/customRequest.ts +0 -87
- package/src/components/Upload/hooks/propsMaker.ts +0 -20
- package/src/components/Upload/index.tsx +0 -119
- package/src/components/Upload/modal.ts +0 -33
- package/src/components/Upload/util.ts +0 -27
- package/src/components/config.ts +0 -47
- package/src/components/hooks/index.ts +0 -53
- package/src/components/index.tsx +0 -37
- package/src/components/modal.ts +0 -20
- package/src/components/styles/index.less +0 -3
- package/src/components/styles/local.less +0 -1
- package/src/components/typings.d.ts +0 -11
- package/src/index.less +0 -20
- package/src/index.tsx +0 -12
- package/src/pages/Checkbox/index.tsx +0 -14
- package/src/pages/DatePicker/index.tsx +0 -33
- package/src/pages/DrawerForm/index.tsx +0 -145
- package/src/pages/Form/index.tsx +0 -172
- package/src/pages/Input/index.tsx +0 -30
- package/src/pages/ModalForm/index.tsx +0 -191
- package/src/pages/Radio/index.tsx +0 -18
- package/src/pages/Select/index.tsx +0 -63
- package/src/pages/Switch/index.tsx +0 -18
- package/src/pages/Upload/index.tsx +0 -14
- package/src/routes.tsx +0 -80
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import Label from "../Label";
|
|
2
|
-
import { Form, Space, Col } from "antd";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import Helper from "./Helper";
|
|
5
|
-
import { useClassName } from "../../hooks";
|
|
6
|
-
import { useHide, usePositionClassName } from "./hooks";
|
|
7
|
-
import { useFormContext } from "../Context";
|
|
8
|
-
import type { HItemProps } from "../modal";
|
|
9
|
-
import { useDefaultRender } from "../hooks/useDefaultRender";
|
|
10
|
-
import type { HFormItemProps } from "../modal";
|
|
11
|
-
import { useDefaultComponents } from "../hooks";
|
|
12
|
-
import {useFormConfigContext} from "../Context/FormConfigProvider";
|
|
13
|
-
|
|
14
|
-
interface ContentProps extends Omit<HItemProps, "name"> {
|
|
15
|
-
value?: any;
|
|
16
|
-
onChange?: (val: any) => void;
|
|
17
|
-
}
|
|
18
|
-
const Content: React.FC<ContentProps> = ({
|
|
19
|
-
children,
|
|
20
|
-
helper,
|
|
21
|
-
value,
|
|
22
|
-
onChange,
|
|
23
|
-
}) => {
|
|
24
|
-
const className = useClassName("hw-form-base-item");
|
|
25
|
-
const relChild =
|
|
26
|
-
children && React.cloneElement(children as any, { value, onChange });
|
|
27
|
-
return (
|
|
28
|
-
<Space direction={"vertical"} size={4} style={{ width: "100%" }}>
|
|
29
|
-
<div className={className}>{relChild}</div>
|
|
30
|
-
<Helper helper={helper} />
|
|
31
|
-
</Space>
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
const Index: React.FC<HFormItemProps> = (props) => {
|
|
35
|
-
const {
|
|
36
|
-
hover,
|
|
37
|
-
labelWidth,
|
|
38
|
-
required,
|
|
39
|
-
colon = true,
|
|
40
|
-
label,
|
|
41
|
-
itemProps:colItemProps,
|
|
42
|
-
children,
|
|
43
|
-
helper,
|
|
44
|
-
hide,
|
|
45
|
-
render,
|
|
46
|
-
itemSpan = { span: 24 },
|
|
47
|
-
hideLabel = false,
|
|
48
|
-
labelAlign,
|
|
49
|
-
style,
|
|
50
|
-
className:colClassName,
|
|
51
|
-
...oProps
|
|
52
|
-
} = props;
|
|
53
|
-
const { labelAlign: align = "right",itemProps, ...inProps } = props;
|
|
54
|
-
const { form } = useFormContext();
|
|
55
|
-
const defaultComponent = useDefaultComponents();
|
|
56
|
-
const formItemStyle = useFormConfigContext("formItemStyle");
|
|
57
|
-
const ctxItemProps = useFormConfigContext("itemProps");
|
|
58
|
-
const defaultItemProps={
|
|
59
|
-
...ctxItemProps,
|
|
60
|
-
...itemProps
|
|
61
|
-
}
|
|
62
|
-
const defaultRender = useDefaultRender({...inProps,itemProps:defaultItemProps}, defaultComponent);
|
|
63
|
-
const className = usePositionClassName(align);
|
|
64
|
-
const hideItem = useHide({ hide, form });
|
|
65
|
-
if (hideItem) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return (
|
|
69
|
-
<Col {...itemSpan} className={colClassName}>
|
|
70
|
-
<Form.Item
|
|
71
|
-
className={className}
|
|
72
|
-
label={
|
|
73
|
-
!hideLabel && (
|
|
74
|
-
<Label
|
|
75
|
-
hover={hover}
|
|
76
|
-
labelWidth={labelWidth}
|
|
77
|
-
required={required}
|
|
78
|
-
colon={colon}
|
|
79
|
-
>
|
|
80
|
-
{label}
|
|
81
|
-
</Label>
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
{...oProps}
|
|
85
|
-
style={style||formItemStyle}
|
|
86
|
-
colon={false}
|
|
87
|
-
required={false}
|
|
88
|
-
>
|
|
89
|
-
<Content helper={helper}>{defaultRender(form)}</Content>
|
|
90
|
-
</Form.Item>
|
|
91
|
-
</Col>
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export default Index;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type { HItemProps, HFormInstance } from "@/components/Form/modal";
|
|
3
|
-
import { Typography } from "antd";
|
|
4
|
-
import { useFormContext } from "../Context";
|
|
5
|
-
|
|
6
|
-
interface HelperProps {
|
|
7
|
-
helper?: HItemProps["helper"];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const Index: React.FC<HelperProps> = ({ helper }) => {
|
|
11
|
-
const { form } = useFormContext();
|
|
12
|
-
if (!helper) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
if (typeof helper === "function") {
|
|
16
|
-
return (
|
|
17
|
-
<Typography.Text type={"secondary"}>
|
|
18
|
-
{helper(form as HFormInstance)}
|
|
19
|
-
</Typography.Text>
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return <Typography.Text type={"secondary"}>{helper}</Typography.Text>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default Index;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import BasicItem from "./BasicItem";
|
|
2
|
-
import type { HItemProps } from "../modal";
|
|
3
|
-
|
|
4
|
-
export default (props: HItemProps) => {
|
|
5
|
-
const { type, colon, itemSpan } = props;
|
|
6
|
-
return (
|
|
7
|
-
<BasicItem
|
|
8
|
-
{...props}
|
|
9
|
-
itemSpan={itemSpan}
|
|
10
|
-
colon={type === "submit" ? false : colon}
|
|
11
|
-
/>
|
|
12
|
-
);
|
|
13
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Form } from "antd";
|
|
2
|
-
import BasicItem from "./BasicItem";
|
|
3
|
-
import { useShouldUpdate } from "./hooks";
|
|
4
|
-
import type { HFormItemProps } from "../modal";
|
|
5
|
-
const { Item } = Form;
|
|
6
|
-
export default ({
|
|
7
|
-
shouldUpdate,
|
|
8
|
-
dependencies,
|
|
9
|
-
hide,
|
|
10
|
-
itemSpan,
|
|
11
|
-
...props
|
|
12
|
-
}: HFormItemProps) => {
|
|
13
|
-
const resultShouldUpdate = useShouldUpdate({ shouldUpdate, hide });
|
|
14
|
-
return (
|
|
15
|
-
<Item shouldUpdate={resultShouldUpdate} dependencies={dependencies} noStyle>
|
|
16
|
-
{() => {
|
|
17
|
-
return <BasicItem hide={hide} itemSpan={itemSpan} {...props} />;
|
|
18
|
-
}}
|
|
19
|
-
</Item>
|
|
20
|
-
);
|
|
21
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import UpFormItem from "./UpFormItem";
|
|
2
|
-
import RegularFormItem from "./RegularFormItem";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
|
-
import type { HFormInstance, HItemProps } from "../modal";
|
|
5
|
-
import type { LabelAlignModal } from "../modal";
|
|
6
|
-
import { useClassName } from "../../hooks";
|
|
7
|
-
|
|
8
|
-
export const useFormItemDomControl = ({
|
|
9
|
-
shouldUpdate,
|
|
10
|
-
hide,
|
|
11
|
-
dependencies,
|
|
12
|
-
}: HItemProps) => {
|
|
13
|
-
return useMemo(() => {
|
|
14
|
-
if (shouldUpdate || typeof hide === "function" || dependencies) {
|
|
15
|
-
return UpFormItem;
|
|
16
|
-
}
|
|
17
|
-
return RegularFormItem;
|
|
18
|
-
}, [shouldUpdate, hide]);
|
|
19
|
-
}; //更新或者不更新组件
|
|
20
|
-
|
|
21
|
-
interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
|
|
22
|
-
form: HFormInstance;
|
|
23
|
-
}
|
|
24
|
-
export const useShouldUpdate = ({
|
|
25
|
-
hide,
|
|
26
|
-
shouldUpdate,
|
|
27
|
-
}: Omit<HItemProps, "name">) => {
|
|
28
|
-
if (typeof hide === "function" && !shouldUpdate) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
return shouldUpdate;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const useHide = ({ hide, form }: UseHideUpItemModal) => {
|
|
35
|
-
if (hide === true) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
if (typeof hide === "function") {
|
|
39
|
-
return hide(form);
|
|
40
|
-
}
|
|
41
|
-
return !!hide;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const classNameData = {
|
|
45
|
-
top: "hw-form-base-item-top",
|
|
46
|
-
left: "hw-form-base-item-left",
|
|
47
|
-
right: "hw-form-base-item-right",
|
|
48
|
-
topRight: "hw-form-base-item-top-right",
|
|
49
|
-
topLeft: "hw-form-base-item-top-left",
|
|
50
|
-
};
|
|
51
|
-
export const usePositionClassName = (position: LabelAlignModal) => {
|
|
52
|
-
const className = classNameData[position];
|
|
53
|
-
return useClassName(className);
|
|
54
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
import type { argsFn } from "@/components/Form/modal";
|
|
8
|
-
interface ResultModal {
|
|
9
|
-
inputValue?: (value: Record<string, any>) => Record<string, any>;
|
|
10
|
-
outputValue?: (value: Record<string, any>) => Record<string, any>;
|
|
11
|
-
}
|
|
12
|
-
const formatMaker = (
|
|
13
|
-
itemProps: HFormItemProps,
|
|
14
|
-
formats?: addFormatItemModal
|
|
15
|
-
) => {
|
|
16
|
-
const { inputValue, outputValue } = formats || {};
|
|
17
|
-
const { initValueProvider = inputValue, subProvider = outputValue } =
|
|
18
|
-
itemProps;
|
|
19
|
-
const resultObj: ResultModal = {};
|
|
20
|
-
if (initValueProvider) {
|
|
21
|
-
resultObj.inputValue = (value) => {
|
|
22
|
-
return initValueProvider(itemProps, value);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
if (subProvider) {
|
|
26
|
-
resultObj.outputValue = (value) => {
|
|
27
|
-
return subProvider(itemProps, value);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const keysLen = Object.keys(resultObj).length;
|
|
31
|
-
return keysLen === 0 ? undefined : resultObj;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default (
|
|
35
|
-
component:
|
|
36
|
-
| React.FunctionComponent
|
|
37
|
-
| React.ComponentClass
|
|
38
|
-
| React.ForwardRefRenderFunction<any, any>,
|
|
39
|
-
config: ConnectConfigModal = {}
|
|
40
|
-
) => {
|
|
41
|
-
const { format = {} } = config;
|
|
42
|
-
const Index: React.ForwardRefRenderFunction<any, HFormItemProps> = (
|
|
43
|
-
props: HFormItemProps,
|
|
44
|
-
ref
|
|
45
|
-
) => {
|
|
46
|
-
const { name = "", dispatch } = props;
|
|
47
|
-
|
|
48
|
-
const { form, valueType = "float" } = useFormContext();
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
form?.addFormat(name, formatMaker(props, format[valueType]));
|
|
52
|
-
}, [valueType, props]);
|
|
53
|
-
|
|
54
|
-
const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
|
|
55
|
-
form?.addFormat(name, formatMaker(props, aFormat[valueType]));
|
|
56
|
-
};
|
|
57
|
-
const addDispatchListener = (key: string, fn: argsFn) => {
|
|
58
|
-
form?.addDispatchListener({ key, name, dispatch }, fn);
|
|
59
|
-
};
|
|
60
|
-
const Component = component as React.ForwardRefRenderFunction<
|
|
61
|
-
any,
|
|
62
|
-
ConnectResultProps
|
|
63
|
-
>;
|
|
64
|
-
return (
|
|
65
|
-
<Component
|
|
66
|
-
{...props}
|
|
67
|
-
addFormat={addFormat}
|
|
68
|
-
addDispatchListener={addDispatchListener}
|
|
69
|
-
ref={ref}
|
|
70
|
-
/>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
return React.forwardRef(Index);
|
|
74
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
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;
|
|
@@ -1,58 +0,0 @@
|
|
|
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 TextArea from "../TextArea";
|
|
17
|
-
import ColorInput from "../Input/ColorInput";
|
|
18
|
-
import Cascader from "../Cascader";
|
|
19
|
-
import VerificationCodeInput from "../Input/VerificationCodeInput";
|
|
20
|
-
import TrimInput from "../Input/TrimInput";
|
|
21
|
-
import TrimTextArea from "../TextArea/TrimTextArea";
|
|
22
|
-
export const placeholderConfig = {
|
|
23
|
-
inputType: [
|
|
24
|
-
"input",
|
|
25
|
-
"inputNumber",
|
|
26
|
-
"selectInput",
|
|
27
|
-
"buttonInput",
|
|
28
|
-
"verificationCodeInput",
|
|
29
|
-
"trimInput",
|
|
30
|
-
"",
|
|
31
|
-
],
|
|
32
|
-
selectType: ["select", "datePicker", "timePicker", "colorInput"],
|
|
33
|
-
};
|
|
34
|
-
const componentConfig = {
|
|
35
|
-
select: HSelect,
|
|
36
|
-
inputNumber: HInputNumber,
|
|
37
|
-
selectInput: HSelectInput,
|
|
38
|
-
buttonInput: HButtonInput,
|
|
39
|
-
checkboxGroup: HCheckboxGroup,
|
|
40
|
-
checkBox: HCheckBox,
|
|
41
|
-
radioGroup: HRadioGroup,
|
|
42
|
-
switch: HSwitch,
|
|
43
|
-
datePicker: HDatePicker,
|
|
44
|
-
rangePicker: HRangePicker,
|
|
45
|
-
timePicker: HTimePicker,
|
|
46
|
-
input: HInput,
|
|
47
|
-
upload: HUpload,
|
|
48
|
-
urlUpload: HUrlUpload,
|
|
49
|
-
submit: HSubmit,
|
|
50
|
-
textArea: TextArea,
|
|
51
|
-
colorInput: ColorInput,
|
|
52
|
-
cascader: Cascader,
|
|
53
|
-
verificationCodeInput: VerificationCodeInput,
|
|
54
|
-
trimInput: TrimInput,
|
|
55
|
-
trimTextArea: TrimTextArea,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export default componentConfig;
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { useRequest } from "ahooks";
|
|
2
|
-
import type { HFormProps, HFormInstance } from "../modal";
|
|
3
|
-
import useHForm from "./useHForm";
|
|
4
|
-
import { useEffect, useMemo } from "react";
|
|
5
|
-
import FormConfig from "../config";
|
|
6
|
-
import { useFormConfigContext } from "../Context/FormConfigProvider";
|
|
7
|
-
import type { DispatchModal } from "../modal";
|
|
8
|
-
|
|
9
|
-
interface UseValuesChangeModal {
|
|
10
|
-
onValuesChange: HFormProps["onValuesChange"];
|
|
11
|
-
dispatch: DispatchModal;
|
|
12
|
-
form: HFormInstance;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const useCurrentForm = (form?: HFormInstance) => {
|
|
16
|
-
const selfForm = useHForm();
|
|
17
|
-
return form || selfForm;
|
|
18
|
-
};
|
|
19
|
-
type ParamsModal = Omit<HFormProps, "configData">;
|
|
20
|
-
|
|
21
|
-
export const useInfoReq = ({
|
|
22
|
-
initialValues,
|
|
23
|
-
infoRequest,
|
|
24
|
-
form,
|
|
25
|
-
params,
|
|
26
|
-
request,
|
|
27
|
-
onFinish,
|
|
28
|
-
}: ParamsModal) => {
|
|
29
|
-
const reqData = useMemo(() => {
|
|
30
|
-
const saveParams = params || {};
|
|
31
|
-
return {
|
|
32
|
-
params: saveParams,
|
|
33
|
-
};
|
|
34
|
-
}, [params]);
|
|
35
|
-
|
|
36
|
-
const subControl = useRequest(
|
|
37
|
-
async (value) => {
|
|
38
|
-
const subVal = form?.outputValues(value);
|
|
39
|
-
if (request) {
|
|
40
|
-
await request(subVal, reqData.params);
|
|
41
|
-
}
|
|
42
|
-
onFinish?.(subVal, reqData.params);
|
|
43
|
-
},
|
|
44
|
-
{ manual: true }
|
|
45
|
-
);
|
|
46
|
-
const infoControl = useRequest(async (reqParams = reqData.params) => {
|
|
47
|
-
reqData.params = reqParams;
|
|
48
|
-
if (infoRequest) {
|
|
49
|
-
const result = await infoRequest(reqParams);
|
|
50
|
-
form?.setFieldsValue(result);
|
|
51
|
-
return result || {};
|
|
52
|
-
}
|
|
53
|
-
const setValue = initialValues || {};
|
|
54
|
-
form?.setFieldsValue(setValue);
|
|
55
|
-
return setValue;
|
|
56
|
-
});
|
|
57
|
-
const { run, mutate } = infoControl;
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (form) {
|
|
60
|
-
form.reload = (reloadParams) => {
|
|
61
|
-
mutate(undefined);
|
|
62
|
-
return run(reloadParams);
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}, []);
|
|
66
|
-
return {
|
|
67
|
-
subControl,
|
|
68
|
-
infoControl,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const useDefaultComponents = () => {
|
|
73
|
-
const defaultComponent = useFormConfigContext("defaultComponent");
|
|
74
|
-
return { ...FormConfig, ...defaultComponent };
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const dispatchControl = (
|
|
78
|
-
form: HFormInstance,
|
|
79
|
-
params,
|
|
80
|
-
dispatch?: Record<string, DispatchModal>
|
|
81
|
-
) => {
|
|
82
|
-
if (!dispatch) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const dispatchKey = Object.keys(dispatch);
|
|
86
|
-
dispatchKey.forEach((name) => {
|
|
87
|
-
const { fnKey, reset } = dispatch[name];
|
|
88
|
-
if (reset) {
|
|
89
|
-
form.setFields([{ name, value: null, errors: [] }]);
|
|
90
|
-
}
|
|
91
|
-
if (!fnKey) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
form.dispatch(
|
|
95
|
-
{
|
|
96
|
-
key: fnKey,
|
|
97
|
-
name,
|
|
98
|
-
},
|
|
99
|
-
params
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
}; //触发
|
|
103
|
-
export const useValuesChange = ({
|
|
104
|
-
onValuesChange,
|
|
105
|
-
dispatch,
|
|
106
|
-
form,
|
|
107
|
-
}: UseValuesChangeModal) => {
|
|
108
|
-
return (changedValues: any, values: any) => {
|
|
109
|
-
const changeKey = Object.keys(changedValues)[0];
|
|
110
|
-
const dispatchItem = dispatch[changeKey];
|
|
111
|
-
dispatchControl(form, { changedValues, oldValues: values }, dispatchItem);
|
|
112
|
-
onValuesChange?.(changedValues, values);
|
|
113
|
-
};
|
|
114
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DefaultComponentModal,
|
|
3
|
-
HFormItemProps,
|
|
4
|
-
ConfigComponentModal,
|
|
5
|
-
} from "../modal";
|
|
6
|
-
import FormConfig from "../config";
|
|
7
|
-
import type { FormInstance } from "antd";
|
|
8
|
-
import React from "react";
|
|
9
|
-
|
|
10
|
-
export const useDefaultRender = (
|
|
11
|
-
props: HFormItemProps,
|
|
12
|
-
defaultComponents: DefaultComponentModal
|
|
13
|
-
) => {
|
|
14
|
-
const {
|
|
15
|
-
render,
|
|
16
|
-
labelWidth,
|
|
17
|
-
colon,
|
|
18
|
-
type = "input",
|
|
19
|
-
itemProps = {},
|
|
20
|
-
itemSpan,
|
|
21
|
-
hideLabel,
|
|
22
|
-
style,
|
|
23
|
-
...componentProps
|
|
24
|
-
} = props;
|
|
25
|
-
const mergeComponent = { ...FormConfig, ...defaultComponents };
|
|
26
|
-
const dom = mergeComponent[type];
|
|
27
|
-
return (form: FormInstance) => {
|
|
28
|
-
let Component = dom;
|
|
29
|
-
if ((dom as ConfigComponentModal)?.Component) {
|
|
30
|
-
Component = (dom as ConfigComponentModal).Component;
|
|
31
|
-
}
|
|
32
|
-
const node = Component && (
|
|
33
|
-
<Component {...componentProps} {...itemProps} form={form} />
|
|
34
|
-
);
|
|
35
|
-
if (render) {
|
|
36
|
-
const resultNode = render(props, node, form);
|
|
37
|
-
return React.cloneElement<any>(resultNode as any, {
|
|
38
|
-
...componentProps,
|
|
39
|
-
...itemProps,
|
|
40
|
-
form,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return node;
|
|
44
|
-
};
|
|
45
|
-
};
|