@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.
Files changed (116) hide show
  1. package/.eslintcache +1 -0
  2. package/.idea/hw-component-form.iml +12 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +7 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/vcs.xml +6 -0
  7. package/es/Select/modal.d.ts +1 -3
  8. package/lib/Select/modal.d.ts +1 -3
  9. package/package.json +1 -1
  10. package/public/index.html +0 -19
  11. package/scripts/rollup.config.js +0 -90
  12. package/scripts/webpack.config.js +0 -76
  13. package/src/Layout.tsx +0 -61
  14. package/src/app.tsx +0 -33
  15. package/src/components/Cascader/index.tsx +0 -31
  16. package/src/components/CheckboxGroup/CheckBox/index.tsx +0 -38
  17. package/src/components/CheckboxGroup/hooks.ts +0 -105
  18. package/src/components/CheckboxGroup/index.tsx +0 -85
  19. package/src/components/CheckboxGroup/modal.ts +0 -17
  20. package/src/components/DialogForm/DrawerForm/Footer.tsx +0 -20
  21. package/src/components/DialogForm/DrawerForm/Title.tsx +0 -12
  22. package/src/components/DialogForm/DrawerForm/index.tsx +0 -110
  23. package/src/components/DialogForm/ModalForm.tsx +0 -91
  24. package/src/components/DialogForm/hooks.ts +0 -122
  25. package/src/components/DialogForm/modal.ts +0 -44
  26. package/src/components/Form/Context/FormConfigProvider.tsx +0 -38
  27. package/src/components/Form/Context/index.tsx +0 -14
  28. package/src/components/Form/FormItem/BasicItem.tsx +0 -95
  29. package/src/components/Form/FormItem/Helper.tsx +0 -25
  30. package/src/components/Form/FormItem/RegularFormItem.tsx +0 -13
  31. package/src/components/Form/FormItem/UpFormItem.tsx +0 -21
  32. package/src/components/Form/FormItem/hooks.tsx +0 -54
  33. package/src/components/Form/FormItem/index.tsx +0 -8
  34. package/src/components/Form/HFormConnect.tsx +0 -74
  35. package/src/components/Form/InitSet.tsx +0 -10
  36. package/src/components/Form/Label.tsx +0 -50
  37. package/src/components/Form/config.ts +0 -58
  38. package/src/components/Form/hooks/index.ts +0 -114
  39. package/src/components/Form/hooks/useDefaultRender.tsx +0 -45
  40. package/src/components/Form/hooks/useHForm.ts +0 -182
  41. package/src/components/Form/hooks/useInitConfigData.tsx +0 -194
  42. package/src/components/Form/index.less +0 -54
  43. package/src/components/Form/index.tsx +0 -113
  44. package/src/components/Form/modal.ts +0 -206
  45. package/src/components/Input/ButtonInput.tsx +0 -47
  46. package/src/components/Input/ColorInput/Picker.tsx +0 -18
  47. package/src/components/Input/ColorInput/data.ts +0 -102
  48. package/src/components/Input/ColorInput/index.less +0 -10
  49. package/src/components/Input/ColorInput/index.tsx +0 -58
  50. package/src/components/Input/InputNumber.tsx +0 -5
  51. package/src/components/Input/SelectInput.tsx +0 -75
  52. package/src/components/Input/TrimInput.tsx +0 -26
  53. package/src/components/Input/VerificationCodeInput.tsx +0 -74
  54. package/src/components/Input/defaultConfig.ts +0 -8
  55. package/src/components/Input/index.tsx +0 -26
  56. package/src/components/Input/modal.ts +0 -40
  57. package/src/components/PageHandler/ErrorComponent.tsx +0 -20
  58. package/src/components/PageHandler/LoadingComponent.tsx +0 -9
  59. package/src/components/PageHandler/index.tsx +0 -14
  60. package/src/components/PageHandler/modal.ts +0 -6
  61. package/src/components/RadioGroup/index.tsx +0 -45
  62. package/src/components/Select/components/AllSelect.tsx +0 -54
  63. package/src/components/Select/components/CheckBoxOption.tsx +0 -14
  64. package/src/components/Select/components/DropdownComponent.tsx +0 -36
  65. package/src/components/Select/components/NoFindItem.tsx +0 -7
  66. package/src/components/Select/components/NotFoundContent.tsx +0 -25
  67. package/src/components/Select/defaultConfig.tsx +0 -23
  68. package/src/components/Select/hooks/changeHooks.tsx +0 -159
  69. package/src/components/Select/hooks/norHooks.ts +0 -85
  70. package/src/components/Select/index.less +0 -22
  71. package/src/components/Select/index.tsx +0 -126
  72. package/src/components/Select/modal.ts +0 -38
  73. package/src/components/Select/utils.ts +0 -18
  74. package/src/components/Submit/components.tsx +0 -57
  75. package/src/components/Submit/hooks.ts +0 -31
  76. package/src/components/Submit/index.tsx +0 -33
  77. package/src/components/Switch/index.tsx +0 -77
  78. package/src/components/TDPicker/RangePicker.tsx +0 -109
  79. package/src/components/TDPicker/TimePicker.tsx +0 -29
  80. package/src/components/TDPicker/hooks.ts +0 -150
  81. package/src/components/TDPicker/index.tsx +0 -33
  82. package/src/components/TDPicker/modal.ts +0 -48
  83. package/src/components/TextArea/TrimTextArea.tsx +0 -30
  84. package/src/components/TextArea/index.tsx +0 -8
  85. package/src/components/Upload/Btn.tsx +0 -24
  86. package/src/components/Upload/MediaTypeEle/TypeEle.tsx +0 -26
  87. package/src/components/Upload/MediaTypeEle/index.tsx +0 -34
  88. package/src/components/Upload/Preview/index.tsx +0 -14
  89. package/src/components/Upload/UrlUpload/index.tsx +0 -104
  90. package/src/components/Upload/enums.ts +0 -5
  91. package/src/components/Upload/hooks/change.ts +0 -79
  92. package/src/components/Upload/hooks/customRequest.ts +0 -87
  93. package/src/components/Upload/hooks/propsMaker.ts +0 -20
  94. package/src/components/Upload/index.tsx +0 -119
  95. package/src/components/Upload/modal.ts +0 -33
  96. package/src/components/Upload/util.ts +0 -27
  97. package/src/components/config.ts +0 -47
  98. package/src/components/hooks/index.ts +0 -53
  99. package/src/components/index.tsx +0 -37
  100. package/src/components/modal.ts +0 -20
  101. package/src/components/styles/index.less +0 -3
  102. package/src/components/styles/local.less +0 -1
  103. package/src/components/typings.d.ts +0 -11
  104. package/src/index.less +0 -20
  105. package/src/index.tsx +0 -12
  106. package/src/pages/Checkbox/index.tsx +0 -14
  107. package/src/pages/DatePicker/index.tsx +0 -33
  108. package/src/pages/DrawerForm/index.tsx +0 -145
  109. package/src/pages/Form/index.tsx +0 -172
  110. package/src/pages/Input/index.tsx +0 -30
  111. package/src/pages/ModalForm/index.tsx +0 -191
  112. package/src/pages/Radio/index.tsx +0 -18
  113. package/src/pages/Select/index.tsx +0 -63
  114. package/src/pages/Switch/index.tsx +0 -18
  115. package/src/pages/Upload/index.tsx +0 -14
  116. package/src/routes.tsx +0 -80
@@ -1,38 +0,0 @@
1
- import { Checkbox } from "antd";
2
- import React, { useMemo } from "react";
3
- import type { CheckboxChangeEvent } from "antd/es/checkbox";
4
- import type { HCheckboxProps } from "@/components/CheckboxGroup/modal";
5
- import { useMatchConfigProps } from "../../hooks";
6
-
7
- const Index: React.FC<HCheckboxProps> = ({
8
- value,
9
- onChange,
10
- children,
11
- valueMap: propsValueCheckMap,
12
- }) => {
13
- const { valueCheckMap = {} } = useMatchConfigProps({
14
- valueCheckMap: propsValueCheckMap,
15
- }); //匹配全局
16
- const checkedVal = useMemo(() => {
17
- const { checked } = valueCheckMap;
18
- if (value === checked) {
19
- return true;
20
- }
21
- return false;
22
- }, [value]);
23
- const change = (e: CheckboxChangeEvent) => {
24
- const { checked, noChecked } = valueCheckMap;
25
- const val = e.target.checked;
26
- let subVal = checked;
27
- if (!val) {
28
- subVal = noChecked;
29
- }
30
- onChange?.(subVal);
31
- };
32
- return (
33
- <Checkbox checked={checkedVal} onChange={change}>
34
- {children}
35
- </Checkbox>
36
- );
37
- };
38
- export default Index;
@@ -1,105 +0,0 @@
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, noChecked } = 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
- Object.keys(newVal).forEach((key) => {
72
- newVal[key] = noChecked;
73
- });
74
- value.forEach((itemVal) => {
75
- newVal[itemVal] = checked;
76
- });
77
- return newVal;
78
- });
79
- }, [value]);
80
-
81
- const change = (key: any, changeVal: any) => {
82
- const { checked, noChecked } = valueMap;
83
- const newVal = { ...val };
84
- newVal[key] = noChecked;
85
- if (changeVal === checked) {
86
- newVal[key] = checked;
87
- }
88
- if (!onChange) {
89
- setVal(newVal);
90
- return;
91
- }
92
- if (keyInValue) {
93
- onChange(newVal);
94
- return;
95
- }
96
- const subVal = Object.keys(newVal).filter((valKey) => {
97
- return newVal[valKey] === checked;
98
- });
99
- onChange(subVal);
100
- };
101
- return {
102
- val,
103
- change,
104
- };
105
- };
@@ -1,85 +0,0 @@
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
- direction,
19
- }: HCheckboxProps) => {
20
- const { valueCheckMap: resultValueCheckMap, fieldNames: resultFieldNames } =
21
- useMatchConfigProps({ fieldNames, valueCheckMap: valueMap }); //匹配全局
22
- const checkOptions = useChangeOptions({
23
- options,
24
- fieldNames: resultFieldNames,
25
- });
26
- const { val, change } = useValueProvider({
27
- options: checkOptions,
28
- onChange,
29
- valueMap: resultValueCheckMap,
30
- keyInValue,
31
- value,
32
- });
33
- addFormat?.({
34
- float: {
35
- inputValue: (item, initValue) => {
36
- const { name = "" } = item;
37
- const keys = checkOptions?.map((optItem) => {
38
- return optItem.value;
39
- });
40
- const resultObj = {};
41
- keys?.forEach((key) => {
42
- resultObj[key] = initValue[key];
43
- });
44
- return {
45
- [name]: resultObj,
46
- };
47
- },
48
- outputValue: (item, outputValue) => {
49
- const { name = "" } = item;
50
- const { [name]: itemVal = {} } = outputValue;
51
- if (Array.isArray(itemVal)) {
52
- return {
53
- [name]: itemVal,
54
- };
55
- }
56
- return {
57
- ...itemVal,
58
- };
59
- },
60
- },
61
- });
62
- return (
63
- <Space direction={direction}>
64
- {checkOptions?.map((item) => {
65
- const { label, value: itemVal } = item;
66
- const checked = val[itemVal];
67
- return (
68
- <Checkbox
69
- value={checked}
70
- key={itemVal}
71
- onChange={(changeVal) => {
72
- change(itemVal, changeVal);
73
- }}
74
- valueMap={valueMap}
75
- disabled={disabled}
76
- >
77
- {label}
78
- </Checkbox>
79
- );
80
- })}
81
- </Space>
82
- );
83
- };
84
-
85
- export default HFormConnect(Index);
@@ -1,17 +0,0 @@
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
- subParams?: (formatValue: Record<string, any>, sourceValue: any[]) => any;
16
- direction?: "horizontal" | "vertical";
17
- }
@@ -1,20 +0,0 @@
1
- import { Row, Space, Button } from "antd";
2
-
3
- interface IProps {
4
- onOk?: VoidFunction;
5
- onCancel?: VoidFunction;
6
- confirmLoading?: boolean;
7
- }
8
-
9
- export default ({ onCancel, onOk, confirmLoading }: IProps) => {
10
- return (
11
- <Row justify={"end"}>
12
- <Space size={"middle"}>
13
- <Button onClick={onCancel}>关闭</Button>
14
- <Button type={"primary"} onClick={onOk} loading={confirmLoading}>
15
- 确定
16
- </Button>
17
- </Space>
18
- </Row>
19
- );
20
- };
@@ -1,12 +0,0 @@
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
- };
@@ -1,110 +0,0 @@
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
- import FormConfigProvider, {
8
- useFormConfigContext,
9
- } from "../../Form/Context/FormConfigProvider";
10
- export default ({
11
- visible,
12
- title,
13
- onCancel,
14
- configData,
15
- infoRequest,
16
- request,
17
- afterClose,
18
- dialogForm,
19
- closable = true,
20
- initialValues,
21
- labelWidth,
22
- onOk,
23
- onFinish,
24
- size,
25
- form,
26
- footer,
27
- params,
28
- onValuesChange,
29
- autoClear = true,
30
- contentRender,
31
- ...props
32
- }: DialogFormProps) => {
33
- const currentForm = useCurrentForm(dialogForm);
34
- const providerConfig = useFormConfigContext();
35
- const {
36
- modalVisible,
37
- modalFormData,
38
- setModalVisible,
39
- initValue,
40
- onAfterClose,
41
- formParams,
42
- title: modalTitle,
43
- } = useModifyProps({
44
- configData,
45
- visible,
46
- initialValues,
47
- dialogForm: currentForm,
48
- params,
49
- title,
50
- onCancel,
51
- autoClear,
52
- });
53
- const cancel = () => {
54
- onAfterClose();
55
- if (onCancel) {
56
- return onCancel?.();
57
- }
58
- setModalVisible(false);
59
- };
60
- const { loading, run } = useSub({ request, onFinish });
61
- const footerComponent = () => {
62
- if (footer === null) {
63
- return null;
64
- }
65
- return (
66
- footer || (
67
- <Footer
68
- onCancel={cancel}
69
- onOk={currentForm.submit}
70
- confirmLoading={loading}
71
- />
72
- )
73
- );
74
- };
75
- const node = (
76
- <HForm
77
- configData={modalFormData}
78
- initialValues={initValue}
79
- onValuesChange={onValuesChange}
80
- {...props}
81
- form={currentForm}
82
- params={formParams}
83
- onFinish={async (values, subParams) => {
84
- const result = await run(values, subParams);
85
- const close = onOk?.(result, subParams);
86
- if (close === false) {
87
- return;
88
- }
89
- cancel();
90
- }}
91
- infoRequest={infoRequest}
92
- labelWidth={labelWidth}
93
- />
94
- );
95
- return (
96
- <Drawer
97
- visible={modalVisible}
98
- title={<Title title={modalTitle} closable={closable} onCancel={cancel} />}
99
- {...props}
100
- onClose={cancel}
101
- closable={false}
102
- destroyOnClose={true}
103
- footer={footerComponent()}
104
- >
105
- <FormConfigProvider {...providerConfig}>
106
- {contentRender ? contentRender(node, currentForm) : node}
107
- </FormConfigProvider>
108
- </Drawer>
109
- );
110
- };
@@ -1,91 +0,0 @@
1
- import { Modal } from "antd";
2
- import type { DialogFormProps } from "./modal";
3
- import HForm from "../Form";
4
- import FormConfigProvider, {
5
- useFormConfigContext,
6
- } from "../Form/Context/FormConfigProvider";
7
- import { useCurrentForm, useModifyProps, useSub } from "./hooks";
8
- export default ({
9
- visible,
10
- title,
11
- onCancel,
12
- configData,
13
- infoRequest,
14
- request,
15
- afterClose,
16
- dialogForm,
17
- initialValues,
18
- onFinish,
19
- params,
20
- onOk,
21
- onValuesChange,
22
- autoClear = true,
23
- contentRender,
24
- ...props
25
- }: DialogFormProps) => {
26
- const currentForm = useCurrentForm(dialogForm);
27
- const providerConfig = useFormConfigContext();
28
- const {
29
- modalVisible,
30
- modalFormData,
31
- setModalVisible,
32
- initValue,
33
- formParams,
34
- title: modalTitle,
35
- } = useModifyProps({
36
- configData,
37
- visible,
38
- initialValues,
39
- dialogForm: currentForm,
40
- params,
41
- title,
42
- onCancel,
43
- });
44
- const cancel = () => {
45
- if (onCancel) {
46
- return onCancel?.();
47
- }
48
- setModalVisible(false);
49
- };
50
- const { loading, run } = useSub({ request, onFinish });
51
- const node = (
52
- <HForm
53
- configData={modalFormData}
54
- initialValues={initValue}
55
- onValuesChange={onValuesChange}
56
- onFinish={async (values, outParams) => {
57
- const result = await run(values, outParams);
58
- const close = onOk?.(result, outParams);
59
- if (close === false) {
60
- return;
61
- }
62
- cancel();
63
- }}
64
- {...props}
65
- params={formParams}
66
- form={currentForm}
67
- infoRequest={infoRequest}
68
- />
69
- );
70
- return (
71
- <Modal
72
- title={modalTitle}
73
- visible={modalVisible}
74
- onCancel={cancel}
75
- confirmLoading={loading}
76
- afterClose={() => {
77
- if (autoClear) {
78
- currentForm.clear();
79
- }
80
- afterClose?.();
81
- }}
82
- {...props}
83
- onOk={currentForm.submit}
84
- destroyOnClose={true}
85
- >
86
- <FormConfigProvider {...providerConfig}>
87
- {contentRender ? contentRender?.(node, currentForm) : node}
88
- </FormConfigProvider>
89
- </Modal>
90
- );
91
- };
@@ -1,122 +0,0 @@
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
- params,
17
- title,
18
- onCancel,
19
- autoClear,
20
- }: ModifyPropsModal) => {
21
- const [modalVisible, setModalVisible] = useState(visible);
22
- const [modalFormData, setModalFormData] = useState(configData);
23
- const [initValue, setInitValue] = useState(initialValues);
24
- const [formParams, setFormParams] = useState(params);
25
- const [modalTitle, setModalTitle] = useState(title);
26
- const saveOldParamsObj = useMemo(() => {
27
- return {
28
- old: {},
29
- };
30
- }, []);
31
- const onAfterClose = () => {
32
- onCancel?.();
33
- saveOldParamsObj.old = dialogForm.outputValues();
34
- setTimeout(() => {
35
- dialogForm.clear();
36
- afterClose?.();
37
- }, 100);
38
- };
39
-
40
- useEffect(() => {
41
- setModalVisible(visible);
42
- }, [visible]);
43
-
44
- useEffect(() => {
45
- setModalFormData(configData);
46
- }, [configData]);
47
- useEffect(() => {
48
- setFormParams(params);
49
- }, [params]);
50
- useEffect(() => {
51
- setModalTitle(title);
52
- }, [title]);
53
- useEffect(() => {
54
- setInitValue(initialValues);
55
- }, [initialValues]);
56
- useEffect(() => {
57
- dialogForm.show = (showParams = {}) => {
58
- const {
59
- configData: changeConfigData,
60
- initialValues: changeInitialValues = {},
61
- params: changeParams = {},
62
- title: changeTitle,
63
- } = showParams;
64
- if (!!changeConfigData) {
65
- setModalFormData(changeConfigData);
66
- }
67
- setFormParams(changeParams);
68
- if (!!changeTitle) {
69
- setModalTitle(changeTitle);
70
- }
71
- const relChangeInitVal = autoClear
72
- ? changeInitialValues
73
- : { ...saveOldParamsObj.old, ...changeInitialValues };
74
- setInitValue(relChangeInitVal);
75
- setModalVisible(true);
76
- };
77
- dialogForm.hide = () => {
78
- setModalVisible(false);
79
- onAfterClose();
80
- };
81
- }, [afterClose, autoClear]);
82
- return {
83
- modalFormData,
84
- modalVisible,
85
- setModalVisible,
86
- setModalFormData,
87
- initValue,
88
- setInitValue,
89
- onAfterClose,
90
- formParams,
91
- title: modalTitle,
92
- };
93
- };
94
- export const useHDialogForm = () => {
95
- const hForm = useHForm();
96
- return useMemo<HDialogFormInstance>(() => {
97
- return {
98
- ...hForm,
99
- show: (params) => {},
100
- hide: () => {},
101
- };
102
- }, []);
103
- };
104
-
105
- export const useCurrentForm = (hDialogForm?: HDialogFormInstance) => {
106
- const defaultHModalForm = useHDialogForm();
107
- return hDialogForm || defaultHModalForm;
108
- };
109
-
110
- export const useSub = ({ request, onFinish }: Partial<DialogFormProps>) => {
111
- return useRequest(
112
- async (values, params) => {
113
- if (onFinish) {
114
- return onFinish(values, params);
115
- }
116
- if (request) {
117
- return request(values, params);
118
- }
119
- },
120
- { manual: true }
121
- );
122
- };
@@ -1,44 +0,0 @@
1
- import type { ModalProps } from "antd";
2
- import type { HFormInstance, HItemProps, HFormProps } from "../Form/modal";
3
- import type { PromiseFnResult } from "../modal";
4
- import type React from "react";
5
-
6
- type RootProps = HFormProps & ModalProps;
7
-
8
- export interface ModifyPropsModal<P = any> {
9
- configData: HItemProps[];
10
- visible?: boolean;
11
- initialValues?: Record<string, any>;
12
- dialogForm: HDialogFormInstance;
13
- afterClose?: VoidFunction;
14
- params?: P;
15
- title?: DialogFormProps["title"];
16
- onCancel?: VoidFunction;
17
- autoClear?: boolean;
18
- }
19
- export interface ShowParamsModal<P = any, T = any> {
20
- configData?: HItemProps[];
21
- visible?: boolean;
22
- initialValues?: Record<string, any>;
23
- infoRequest?: PromiseFnResult<P, T>;
24
- params?: P;
25
- title?: DialogFormProps["title"];
26
- }
27
-
28
- export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
29
- show: (data?: ShowParamsModal<P, T>) => void;
30
- hide: VoidFunction;
31
- }
32
- export interface DialogFormProps<P = any, T = any>
33
- extends Omit<RootProps, "onFinish" | "onCancel" | "onOk" | "infoRequest"> {
34
- dialogForm?: HDialogFormInstance;
35
- onFinish?: (values: T, params: P) => Promise<any>;
36
- onCancel?: VoidFunction;
37
- onOk?: (data: T, params: P) => boolean | void;
38
- infoRequest?: (params: P) => Promise<T>;
39
- autoClear?: boolean;
40
- contentRender?: (
41
- dom: React.ReactNode,
42
- form: HDialogFormInstance
43
- ) => React.ReactNode;
44
- }
@@ -1,38 +0,0 @@
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;
@@ -1,14 +0,0 @@
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
- );