@hw-component/form 0.0.1-bate → 0.0.1-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.js +4 -2
- package/es/Form/HFormConnect.js +10 -2
- package/es/Form/InitSet.d.ts +1 -4
- package/es/Form/InitSet.js +2 -3
- package/es/Form/config.d.ts +2 -2
- 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 +13 -7
- package/es/Input/SelectInput.d.ts +1 -1
- package/es/Input/SelectInput.js +8 -5
- package/es/Input/modal.d.ts +2 -0
- package/es/ModalForm/hooks.d.ts +12 -0
- package/es/ModalForm/hooks.js +63 -0
- package/es/ModalForm/index.d.ts +4 -0
- package/es/ModalForm/index.js +72 -0
- package/es/ModalForm/modal.d.ts +20 -0
- package/es/Select/hooks/norHooks.d.ts +1 -1
- package/es/TDPicker/RangePicker.js +10 -5
- package/es/TextArea/index.d.ts +1 -0
- package/es/index.d.ts +4 -2
- package/es/index.js +4 -1
- package/lib/CheckboxGroup/index.js +4 -2
- package/lib/Form/HFormConnect.js +10 -2
- package/lib/Form/InitSet.d.ts +1 -4
- package/lib/Form/InitSet.js +2 -3
- package/lib/Form/config.d.ts +2 -2
- 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 +13 -7
- package/lib/Input/SelectInput.d.ts +1 -1
- package/lib/Input/SelectInput.js +8 -5
- package/lib/Input/modal.d.ts +2 -0
- package/lib/ModalForm/hooks.d.ts +12 -0
- package/lib/ModalForm/hooks.js +66 -0
- package/lib/ModalForm/index.d.ts +4 -0
- package/lib/ModalForm/index.js +75 -0
- package/lib/ModalForm/modal.d.ts +20 -0
- package/lib/Select/hooks/norHooks.d.ts +1 -1
- package/lib/TDPicker/RangePicker.js +10 -5
- package/lib/TextArea/index.d.ts +1 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.js +5 -0
- package/package.json +2 -2
- package/src/components/CheckboxGroup/index.tsx +2 -2
- package/src/components/Form/FormItem/Helper.tsx +3 -4
- package/src/components/Form/HFormConnect.tsx +6 -2
- package/src/components/Form/InitSet.tsx +3 -5
- package/src/components/Form/hooks/index.ts +0 -20
- package/src/components/Form/hooks/useHForm.ts +67 -14
- package/src/components/Form/index.tsx +25 -7
- package/src/components/Form/modal.ts +15 -9
- package/src/components/Input/SelectInput.tsx +3 -2
- package/src/components/Input/modal.ts +2 -0
- package/src/components/ModalForm/hooks.ts +45 -0
- package/src/components/ModalForm/index.tsx +69 -0
- package/src/components/ModalForm/modal.ts +22 -0
- package/src/components/TDPicker/RangePicker.tsx +7 -5
- package/src/components/TDPicker/modal.ts +1 -0
- package/src/components/index.tsx +4 -0
- package/src/pages/Form/index.tsx +2 -2
- package/src/pages/ModalForm/index.tsx +127 -0
- package/src/routes.tsx +6 -1
|
@@ -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
|
);
|
|
@@ -53,18 +53,20 @@ type HelperModal = (form: HFormInstance) => React.ReactNode | string;
|
|
|
53
53
|
|
|
54
54
|
export type HideModal = (form: HFormInstance) => boolean;
|
|
55
55
|
|
|
56
|
+
export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
|
|
57
|
+
|
|
56
58
|
export interface HItemProps extends Omit<FormItemProps, "name"> {
|
|
57
59
|
type?: string;
|
|
58
60
|
itemProps?: ItemPropsType;
|
|
59
61
|
render?: RenderFun;
|
|
60
|
-
helper?: HelperModal;
|
|
62
|
+
helper?: HelperModal | string;
|
|
61
63
|
hover?: string | HoverModal;
|
|
62
64
|
// formItems?: HItemProps[]; 保留感觉没必要
|
|
63
65
|
labelWidth?: number;
|
|
64
66
|
hide?: boolean | HideModal;
|
|
65
67
|
placeholder?: string | string[];
|
|
66
|
-
formatKeys?: string[];
|
|
67
|
-
name
|
|
68
|
+
// formatKeys?: string[];
|
|
69
|
+
name?: string;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form"> {
|
|
@@ -82,7 +84,7 @@ export interface HFormItemProps extends HItemProps {
|
|
|
82
84
|
export interface FormItemWithRender extends Omit<HFormItemProps, "render"> {
|
|
83
85
|
render: (form: HFormInstance) => React.ReactNode;
|
|
84
86
|
}
|
|
85
|
-
|
|
87
|
+
export type argsFn = (...args: any[]) => void;
|
|
86
88
|
export interface FormContextProps {
|
|
87
89
|
loading?: boolean;
|
|
88
90
|
form: HFormInstance;
|
|
@@ -102,18 +104,21 @@ export interface IFormConfigContextProps {
|
|
|
102
104
|
dateRanges?: RangePickerProps["ranges"];
|
|
103
105
|
uploadProps?: ConfigUploadProps;
|
|
104
106
|
}
|
|
105
|
-
|
|
107
|
+
interface ActionModal {
|
|
108
|
+
key: string;
|
|
109
|
+
name?: string;
|
|
110
|
+
}
|
|
106
111
|
export interface HFormInstance extends FormInstance {
|
|
107
112
|
addFormat: (name: string, formats?: FormatItemModal) => void;
|
|
108
|
-
initValues:
|
|
113
|
+
initValues: VoidFunction;
|
|
109
114
|
formatValues: (
|
|
110
115
|
values?: Record<string, any>,
|
|
111
116
|
formatKey?: string
|
|
112
117
|
) => Record<string, any>;
|
|
113
|
-
dispatch: (
|
|
118
|
+
dispatch: (action: ActionModal, ...args: any[]) => void;
|
|
114
119
|
outputValues: (values?: Record<string, any>) => Record<string, any>;
|
|
115
|
-
addDispatchListener:
|
|
116
|
-
removeDispatchListener: (
|
|
120
|
+
addDispatchListener: AddDispatchListenerFn;
|
|
121
|
+
removeDispatchListener: (action?: ActionModal, fn?: argsFn) => void;
|
|
117
122
|
}
|
|
118
123
|
|
|
119
124
|
export interface ConnectConfigModal {
|
|
@@ -139,4 +144,5 @@ export interface addFormatItemModal {
|
|
|
139
144
|
|
|
140
145
|
export interface ConnectResultProps {
|
|
141
146
|
addFormat?: (format: Record<string, addFormatItemModal>) => void;
|
|
147
|
+
addDispatchListener?: (key: string, fn: argsFn) => void;
|
|
142
148
|
}
|
|
@@ -13,6 +13,7 @@ export const Index = ({
|
|
|
13
13
|
onChange,
|
|
14
14
|
valueName = defaultValueName,
|
|
15
15
|
addFormat,
|
|
16
|
+
addDispatchListener,
|
|
16
17
|
...props
|
|
17
18
|
}: HSelectInputProps) => {
|
|
18
19
|
const { input = "", select = "" } = valueName;
|
|
@@ -31,7 +32,7 @@ export const Index = ({
|
|
|
31
32
|
addFormat?.({
|
|
32
33
|
float: {
|
|
33
34
|
inputValue: (item, initValue) => {
|
|
34
|
-
const { name } = item;
|
|
35
|
+
const { name = "" } = item;
|
|
35
36
|
const resultObj = {};
|
|
36
37
|
Object.values(valueName).forEach((key) => {
|
|
37
38
|
resultObj[key] = initValue[key];
|
|
@@ -41,7 +42,7 @@ export const Index = ({
|
|
|
41
42
|
};
|
|
42
43
|
},
|
|
43
44
|
outputValue: (item, outputValue) => {
|
|
44
|
-
const { name } = item;
|
|
45
|
+
const { name = "" } = item;
|
|
45
46
|
const { [name]: itemVal = {} } = outputValue;
|
|
46
47
|
const newItemVal = { [itemVal[select]]: itemVal[input] };
|
|
47
48
|
return {
|
|
@@ -3,6 +3,7 @@ import type { HSelectProps } from "../Select/modal";
|
|
|
3
3
|
import type { SelectInputType } from "./SelectInput";
|
|
4
4
|
import type { PromiseFnResult } from "../modal";
|
|
5
5
|
import type { addFormatItemModal } from "../Form/modal";
|
|
6
|
+
import type { AddDispatchListenerFn } from "../Form/modal";
|
|
6
7
|
|
|
7
8
|
export type HInputProps = InputProps;
|
|
8
9
|
|
|
@@ -18,6 +19,7 @@ export interface HSelectInputProps
|
|
|
18
19
|
onChange?: (value: Record<string, any>, type: SelectInputType) => void;
|
|
19
20
|
valueName?: ValueNameModal;
|
|
20
21
|
addFormat?: (config: Record<string, addFormatItemModal>) => void;
|
|
22
|
+
addDispatchListener?: AddDispatchListenerFn;
|
|
21
23
|
}
|
|
22
24
|
export interface HButtonProps extends Omit<ButtonProps, "onClick"> {
|
|
23
25
|
onClick: (
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import useHForm from "../Form/hooks/useHForm";
|
|
3
|
+
import type {
|
|
4
|
+
HModalFormInstance,
|
|
5
|
+
ModifyPropsModal,
|
|
6
|
+
} from "@/components/ModalForm/modal";
|
|
7
|
+
|
|
8
|
+
export const useModifyProps = ({
|
|
9
|
+
visible,
|
|
10
|
+
configData,
|
|
11
|
+
initialValues,
|
|
12
|
+
}: ModifyPropsModal) => {
|
|
13
|
+
const [modalVisible, setModalVisible] = useState(visible);
|
|
14
|
+
const [modalFormData, setModalFormData] = useState(configData);
|
|
15
|
+
const [initValue, setInitValue] = useState(initialValues);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setModalVisible(visible);
|
|
18
|
+
}, [visible]);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
setModalFormData(configData);
|
|
21
|
+
}, [configData]);
|
|
22
|
+
return {
|
|
23
|
+
modalFormData,
|
|
24
|
+
modalVisible,
|
|
25
|
+
setModalVisible,
|
|
26
|
+
setModalFormData,
|
|
27
|
+
initValue,
|
|
28
|
+
setInitValue,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export const useHModalForm = () => {
|
|
32
|
+
const hForm = useHForm();
|
|
33
|
+
return useMemo<HModalFormInstance>(() => {
|
|
34
|
+
return {
|
|
35
|
+
...hForm,
|
|
36
|
+
show: (params) => {},
|
|
37
|
+
hide: () => {},
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const useCurrentForm = (hModalForm?: HModalFormInstance) => {
|
|
43
|
+
const defaultHModalForm = useHModalForm();
|
|
44
|
+
return hModalForm || defaultHModalForm;
|
|
45
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Modal } from "antd";
|
|
2
|
+
import type { ModalFormProps } from "@/components/ModalForm/modal";
|
|
3
|
+
import HForm from "../Form";
|
|
4
|
+
import { useCurrentForm, useModifyProps } from "./hooks";
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
export default ({
|
|
7
|
+
visible,
|
|
8
|
+
title,
|
|
9
|
+
onCancel,
|
|
10
|
+
configData,
|
|
11
|
+
infoRequest,
|
|
12
|
+
request,
|
|
13
|
+
afterClose,
|
|
14
|
+
modalForm,
|
|
15
|
+
initialValues = {},
|
|
16
|
+
...props
|
|
17
|
+
}: ModalFormProps) => {
|
|
18
|
+
const {
|
|
19
|
+
modalVisible,
|
|
20
|
+
modalFormData,
|
|
21
|
+
setModalVisible,
|
|
22
|
+
setModalFormData,
|
|
23
|
+
initValue,
|
|
24
|
+
setInitValue,
|
|
25
|
+
} = useModifyProps({ configData, visible, initialValues });
|
|
26
|
+
|
|
27
|
+
const currentForm = useCurrentForm(modalForm);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
currentForm.show = ({
|
|
30
|
+
configData: changeConfigData,
|
|
31
|
+
initialValues: changeInitialValues,
|
|
32
|
+
}) => {
|
|
33
|
+
if (!!changeConfigData) {
|
|
34
|
+
setModalFormData(changeConfigData);
|
|
35
|
+
}
|
|
36
|
+
setInitValue(changeInitialValues);
|
|
37
|
+
setModalVisible(true);
|
|
38
|
+
};
|
|
39
|
+
currentForm.hide = () => {
|
|
40
|
+
setModalVisible(false);
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
const cancel = (e) => {
|
|
44
|
+
if (onCancel) {
|
|
45
|
+
return onCancel?.(e);
|
|
46
|
+
}
|
|
47
|
+
setModalVisible(false);
|
|
48
|
+
};
|
|
49
|
+
return (
|
|
50
|
+
<Modal
|
|
51
|
+
title={title}
|
|
52
|
+
visible={modalVisible}
|
|
53
|
+
onCancel={cancel}
|
|
54
|
+
afterClose={() => {
|
|
55
|
+
currentForm.resetFields();
|
|
56
|
+
afterClose?.();
|
|
57
|
+
}}
|
|
58
|
+
{...props}
|
|
59
|
+
>
|
|
60
|
+
<HForm
|
|
61
|
+
configData={modalFormData}
|
|
62
|
+
initialValues={initValue}
|
|
63
|
+
{...props}
|
|
64
|
+
form={currentForm}
|
|
65
|
+
infoRequest={infoRequest}
|
|
66
|
+
/>
|
|
67
|
+
</Modal>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { HFormProps } from "@/components/Form/modal";
|
|
2
|
+
import type { ModalProps } from "antd";
|
|
3
|
+
import type { HFormInstance, HItemProps } from "@/components/Form/modal";
|
|
4
|
+
|
|
5
|
+
type RootProps = HFormProps & ModalProps;
|
|
6
|
+
|
|
7
|
+
export interface ModifyPropsModal {
|
|
8
|
+
configData: HItemProps[];
|
|
9
|
+
visible?: boolean;
|
|
10
|
+
initialValues?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface ShowParamsModal extends Partial<ModifyPropsModal> {
|
|
13
|
+
initialValues?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface HModalFormInstance extends HFormInstance {
|
|
17
|
+
show: (data: ShowParamsModal) => void;
|
|
18
|
+
hide: VoidFunction;
|
|
19
|
+
}
|
|
20
|
+
export interface ModalFormProps extends RootProps {
|
|
21
|
+
modalForm?: HModalFormInstance;
|
|
22
|
+
}
|
|
@@ -47,21 +47,23 @@ const HRangePicker: React.FC<HRangePickerProps> = ({
|
|
|
47
47
|
}
|
|
48
48
|
return ranges;
|
|
49
49
|
}, [ranges]); //默认
|
|
50
|
-
|
|
51
50
|
addFormat?.({
|
|
52
51
|
float: {
|
|
53
52
|
inputValue: (item, initValue) => {
|
|
54
|
-
const { name: valueName } = item;
|
|
53
|
+
const { name: valueName = "" } = item;
|
|
55
54
|
const resultObj = {};
|
|
56
55
|
Object.values(dateMapKeys).forEach((key) => {
|
|
57
|
-
|
|
56
|
+
if (initValue[key]) {
|
|
57
|
+
resultObj[key] = initValue[key];
|
|
58
|
+
}
|
|
58
59
|
});
|
|
60
|
+
const hasKeys = Object.keys(resultObj).length !== 0;
|
|
59
61
|
return {
|
|
60
|
-
[valueName]: resultObj,
|
|
62
|
+
[valueName]: hasKeys ? resultObj : null,
|
|
61
63
|
};
|
|
62
64
|
},
|
|
63
65
|
outputValue: (item, outputValue) => {
|
|
64
|
-
const { name: valueName } = item;
|
|
66
|
+
const { name: valueName = "" } = item;
|
|
65
67
|
const { [valueName]: itemVal = {} } = outputValue;
|
|
66
68
|
return {
|
|
67
69
|
...itemVal,
|
|
@@ -6,6 +6,7 @@ import type { TimePickerProps } from "antd";
|
|
|
6
6
|
import type { DurationInputArg2 } from "moment";
|
|
7
7
|
import type { DateRangePickerValueMapModal } from "../modal";
|
|
8
8
|
import type { addFormatItemModal } from "@/components/Form/modal";
|
|
9
|
+
import type { argsFn } from "@/components/Form/modal";
|
|
9
10
|
export interface HDatePickerProps
|
|
10
11
|
extends Omit<DatePickerProps, "onChange" | "format" | "ranges"> {
|
|
11
12
|
onChange?: (time?: Moment | string | number) => void;
|
package/src/components/index.tsx
CHANGED
|
@@ -3,6 +3,9 @@ import FormConfig from "./Form/config";
|
|
|
3
3
|
import PageHandler from "./PageHandler";
|
|
4
4
|
export { default as HForm } from "./Form";
|
|
5
5
|
export { default as useHForm } from "./Form/hooks/useHForm";
|
|
6
|
+
export { useHModalForm } from "./ModalForm/hooks";
|
|
7
|
+
|
|
8
|
+
import ModalForm from "./ModalForm";
|
|
6
9
|
export const HSelect = FormConfig.select;
|
|
7
10
|
export const HInput = FormConfig.input;
|
|
8
11
|
export const HSelectInput = FormConfig.selectInput;
|
|
@@ -19,3 +22,4 @@ export const HTimePicker = FormConfig.timePicker;
|
|
|
19
22
|
export const HInputNumber = FormConfig.inputNumber;
|
|
20
23
|
export const HPageHandler = PageHandler;
|
|
21
24
|
export const HFormConfigProvider = FormConfig.formConfigProvider;
|
|
25
|
+
export const HModalForm = ModalForm;
|
package/src/pages/Form/index.tsx
CHANGED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Button } from "antd";
|
|
2
|
+
import { HModalForm, useHModalForm } from "../../components";
|
|
3
|
+
const data = [
|
|
4
|
+
{
|
|
5
|
+
label: "输入框",
|
|
6
|
+
name: "name",
|
|
7
|
+
rules: [
|
|
8
|
+
() => {
|
|
9
|
+
return {
|
|
10
|
+
required: true,
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: "数字",
|
|
17
|
+
name: "sz",
|
|
18
|
+
type: "inputNumber",
|
|
19
|
+
rules: [{ required: true }],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: "下拉输入框",
|
|
23
|
+
name: "selectInput",
|
|
24
|
+
type: "selectInput",
|
|
25
|
+
rules: [{ required: true }],
|
|
26
|
+
itemProps: {
|
|
27
|
+
valueName: {
|
|
28
|
+
select: "op",
|
|
29
|
+
input: "opInput",
|
|
30
|
+
},
|
|
31
|
+
selectProps: {
|
|
32
|
+
options: [{ label: "测试", value: 1 }],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: "按钮输入框",
|
|
38
|
+
name: "buttonInput",
|
|
39
|
+
type: "buttonInput",
|
|
40
|
+
children: "点击",
|
|
41
|
+
rules: [{ required: true }],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: "选择",
|
|
45
|
+
name: "checkboxGroup",
|
|
46
|
+
type: "checkboxGroup",
|
|
47
|
+
rules: [{ required: true }],
|
|
48
|
+
helper: "帮助我",
|
|
49
|
+
options: [
|
|
50
|
+
{ label: "选择1", value: "check1" },
|
|
51
|
+
{ label: "选择2", value: "check2" },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
label: "开关",
|
|
56
|
+
name: "switch",
|
|
57
|
+
type: "switch",
|
|
58
|
+
rules: [{ required: true }],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: "时间",
|
|
62
|
+
name: "datePicker",
|
|
63
|
+
type: "datePicker",
|
|
64
|
+
hover: "时间选择",
|
|
65
|
+
helper: "帮助我",
|
|
66
|
+
rules: [{ required: true }],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
label: "时间段",
|
|
70
|
+
name: "rangePicker",
|
|
71
|
+
type: "rangePicker",
|
|
72
|
+
helper: "帮助我",
|
|
73
|
+
rules: [{ required: true }],
|
|
74
|
+
itemProps: {
|
|
75
|
+
valueMap: {
|
|
76
|
+
start: "testStart",
|
|
77
|
+
end: "testEnd",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
label: "时分秒",
|
|
83
|
+
name: "timePicker",
|
|
84
|
+
type: "timePicker",
|
|
85
|
+
rules: [{ required: true }],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
label: "文件",
|
|
89
|
+
name: "upload",
|
|
90
|
+
type: "upload",
|
|
91
|
+
rules: [{ required: true }],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
label: "地址文件",
|
|
95
|
+
name: "urlUpload",
|
|
96
|
+
type: "urlUpload",
|
|
97
|
+
rules: [{ required: true }],
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
export default () => {
|
|
101
|
+
const modalForm = useHModalForm();
|
|
102
|
+
return (
|
|
103
|
+
<>
|
|
104
|
+
<Button
|
|
105
|
+
onClick={() => {
|
|
106
|
+
modalForm.show({
|
|
107
|
+
initialValues: {
|
|
108
|
+
check1: 1,
|
|
109
|
+
testStart: "1694747960",
|
|
110
|
+
testEnd: "1693538359",
|
|
111
|
+
op: 1,
|
|
112
|
+
opInput: "12121",
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}}
|
|
116
|
+
>
|
|
117
|
+
打开
|
|
118
|
+
</Button>
|
|
119
|
+
<HModalForm
|
|
120
|
+
configData={data}
|
|
121
|
+
labelWidth={88}
|
|
122
|
+
modalForm={modalForm}
|
|
123
|
+
title="测试"
|
|
124
|
+
/>
|
|
125
|
+
</>
|
|
126
|
+
);
|
|
127
|
+
};
|
package/src/routes.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import Switch from "./pages/Switch";
|
|
|
8
8
|
import DatePicker from "./pages/DatePicker";
|
|
9
9
|
import Upload from "./pages/Upload";
|
|
10
10
|
import Form from "./pages/Form";
|
|
11
|
-
|
|
11
|
+
import ModalForm from "./pages/ModalForm";
|
|
12
12
|
export interface RouteModal {
|
|
13
13
|
path?: string;
|
|
14
14
|
name?: string;
|
|
@@ -63,6 +63,11 @@ const routes: RouteModal[] = [
|
|
|
63
63
|
name: "表单",
|
|
64
64
|
element: <Form />,
|
|
65
65
|
},
|
|
66
|
+
{
|
|
67
|
+
path: "/modalForm",
|
|
68
|
+
name: "弹窗表单",
|
|
69
|
+
element: <ModalForm />,
|
|
70
|
+
},
|
|
66
71
|
];
|
|
67
72
|
|
|
68
73
|
export default routes;
|