@hw-component/form 0.0.9-beta-v21 → 1.0.0

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 (113) hide show
  1. package/es/DialogForm/modal.d.ts +4 -3
  2. package/lib/DialogForm/modal.d.ts +4 -3
  3. package/package.json +1 -1
  4. package/src/Layout.tsx +61 -0
  5. package/src/app.tsx +33 -0
  6. package/src/components/Cascader/index.tsx +31 -0
  7. package/src/components/CheckboxGroup/CheckBox/index.tsx +38 -0
  8. package/src/components/CheckboxGroup/hooks.ts +105 -0
  9. package/src/components/CheckboxGroup/index.tsx +85 -0
  10. package/src/components/CheckboxGroup/modal.ts +17 -0
  11. package/src/components/DialogForm/DrawerForm/Footer.tsx +20 -0
  12. package/src/components/DialogForm/DrawerForm/Title.tsx +12 -0
  13. package/src/components/DialogForm/DrawerForm/index.tsx +110 -0
  14. package/src/components/DialogForm/ModalForm.tsx +91 -0
  15. package/src/components/DialogForm/hooks.ts +122 -0
  16. package/src/components/DialogForm/modal.ts +45 -0
  17. package/src/components/Form/Context/FormConfigProvider.tsx +38 -0
  18. package/src/components/Form/Context/index.tsx +14 -0
  19. package/src/components/Form/FormItem/BasicItem.tsx +95 -0
  20. package/src/components/Form/FormItem/Helper.tsx +25 -0
  21. package/src/components/Form/FormItem/RegularFormItem.tsx +13 -0
  22. package/src/components/Form/FormItem/UpFormItem.tsx +21 -0
  23. package/src/components/Form/FormItem/hooks.tsx +54 -0
  24. package/src/components/Form/FormItem/index.tsx +8 -0
  25. package/src/components/Form/HFormConnect.tsx +74 -0
  26. package/src/components/Form/InitSet.tsx +10 -0
  27. package/src/components/Form/Label.tsx +50 -0
  28. package/src/components/Form/config.ts +58 -0
  29. package/src/components/Form/hooks/index.ts +114 -0
  30. package/src/components/Form/hooks/useDefaultRender.tsx +45 -0
  31. package/src/components/Form/hooks/useHForm.ts +182 -0
  32. package/src/components/Form/hooks/useInitConfigData.tsx +194 -0
  33. package/src/components/Form/index.less +54 -0
  34. package/src/components/Form/index.tsx +113 -0
  35. package/src/components/Form/modal.ts +206 -0
  36. package/src/components/Input/ButtonInput.tsx +47 -0
  37. package/src/components/Input/ColorInput/Picker.tsx +18 -0
  38. package/src/components/Input/ColorInput/data.ts +102 -0
  39. package/src/components/Input/ColorInput/index.less +10 -0
  40. package/src/components/Input/ColorInput/index.tsx +58 -0
  41. package/src/components/Input/InputNumber.tsx +5 -0
  42. package/src/components/Input/SelectInput.tsx +75 -0
  43. package/src/components/Input/TrimInput.tsx +26 -0
  44. package/src/components/Input/VerificationCodeInput.tsx +74 -0
  45. package/src/components/Input/defaultConfig.ts +8 -0
  46. package/src/components/Input/index.tsx +26 -0
  47. package/src/components/Input/modal.ts +40 -0
  48. package/src/components/PageHandler/ErrorComponent.tsx +20 -0
  49. package/src/components/PageHandler/LoadingComponent.tsx +9 -0
  50. package/src/components/PageHandler/index.tsx +14 -0
  51. package/src/components/PageHandler/modal.ts +6 -0
  52. package/src/components/RadioGroup/index.tsx +45 -0
  53. package/src/components/Select/components/AllSelect.tsx +54 -0
  54. package/src/components/Select/components/CheckBoxOption.tsx +14 -0
  55. package/src/components/Select/components/DropdownComponent.tsx +36 -0
  56. package/src/components/Select/components/NoFindItem.tsx +7 -0
  57. package/src/components/Select/components/NotFoundContent.tsx +25 -0
  58. package/src/components/Select/defaultConfig.tsx +23 -0
  59. package/src/components/Select/hooks/changeHooks.tsx +159 -0
  60. package/src/components/Select/hooks/norHooks.ts +85 -0
  61. package/src/components/Select/index.less +22 -0
  62. package/src/components/Select/index.tsx +126 -0
  63. package/src/components/Select/modal.ts +36 -0
  64. package/src/components/Select/utils.ts +18 -0
  65. package/src/components/Submit/components.tsx +57 -0
  66. package/src/components/Submit/hooks.ts +31 -0
  67. package/src/components/Submit/index.tsx +33 -0
  68. package/src/components/Switch/index.tsx +77 -0
  69. package/src/components/TDPicker/RangePicker.tsx +109 -0
  70. package/src/components/TDPicker/TimePicker.tsx +29 -0
  71. package/src/components/TDPicker/hooks.ts +150 -0
  72. package/src/components/TDPicker/index.tsx +33 -0
  73. package/src/components/TDPicker/modal.ts +48 -0
  74. package/src/components/TextArea/TrimTextArea.tsx +30 -0
  75. package/src/components/TextArea/index.tsx +8 -0
  76. package/src/components/Upload/Btn.tsx +24 -0
  77. package/src/components/Upload/MediaTypeEle/TypeEle.tsx +26 -0
  78. package/src/components/Upload/MediaTypeEle/index.tsx +34 -0
  79. package/src/components/Upload/Preview/index.tsx +14 -0
  80. package/src/components/Upload/UrlUpload/index.tsx +104 -0
  81. package/src/components/Upload/enums.ts +5 -0
  82. package/src/components/Upload/hooks/change.ts +79 -0
  83. package/src/components/Upload/hooks/customRequest.ts +87 -0
  84. package/src/components/Upload/hooks/propsMaker.ts +20 -0
  85. package/src/components/Upload/index.tsx +119 -0
  86. package/src/components/Upload/modal.ts +33 -0
  87. package/src/components/Upload/util.ts +27 -0
  88. package/src/components/config.ts +47 -0
  89. package/src/components/hooks/index.ts +53 -0
  90. package/src/components/index.tsx +37 -0
  91. package/src/components/modal.ts +20 -0
  92. package/src/components/styles/index.less +3 -0
  93. package/src/components/styles/local.less +1 -0
  94. package/src/components/typings.d.ts +11 -0
  95. package/src/index.less +20 -0
  96. package/src/index.tsx +12 -0
  97. package/src/pages/Checkbox/index.tsx +14 -0
  98. package/src/pages/DatePicker/index.tsx +33 -0
  99. package/src/pages/DrawerForm/index.tsx +145 -0
  100. package/src/pages/Form/index.tsx +172 -0
  101. package/src/pages/Input/index.tsx +30 -0
  102. package/src/pages/ModalForm/index.tsx +195 -0
  103. package/src/pages/Radio/index.tsx +18 -0
  104. package/src/pages/Select/index.tsx +63 -0
  105. package/src/pages/Switch/index.tsx +18 -0
  106. package/src/pages/Upload/index.tsx +14 -0
  107. package/src/routes.tsx +80 -0
  108. package/.husky/pre-commit +0 -4
  109. package/.idea/hw-component-form.iml +0 -12
  110. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  111. package/.idea/misc.xml +0 -6
  112. package/.idea/modules.xml +0 -8
  113. package/.idea/vcs.xml +0 -6
@@ -0,0 +1,114 @@
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
+ };
@@ -0,0 +1,45 @@
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
+ };
@@ -0,0 +1,182 @@
1
+ import { useMemo } from "react";
2
+ import { Form } from "antd";
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
+ }
10
+
11
+ export default () => {
12
+ const [form] = Form.useForm();
13
+ return useMemo<HFormInstance>(() => {
14
+ const formatSourceData: Record<string, FormatItemModal> = {};
15
+ let dispatchSourceData: Record<string, DispatchItemData> = {};
16
+ const initDispatch: Record<string, argsFn> = {};
17
+ let cacheValues: Record<string, any> = {};
18
+ let isLoading = false;
19
+ let initSaveValue = {};
20
+ const norAddItemDispatch = (name, manual, fn) => {
21
+ if (manual === false && name) {
22
+ initDispatch[name] = fn;
23
+ }
24
+ if (!name) {
25
+ return {
26
+ keysFn: {},
27
+ defaultFn: [fn],
28
+ };
29
+ }
30
+ return {
31
+ keysFn: {
32
+ [name]: fn,
33
+ },
34
+ defaultFn: [],
35
+ };
36
+ };
37
+ return {
38
+ reload: (params) => {
39
+ return Promise.resolve(params);
40
+ },
41
+ initValues() {
42
+ let newValue = {};
43
+ if (cacheValues) {
44
+ newValue = this.formatValues(cacheValues);
45
+ initSaveValue = newValue;
46
+ form.setFieldsValue(newValue);
47
+ }
48
+ const initKeys = Object.keys(initDispatch);
49
+ initKeys.forEach((key) => {
50
+ initDispatch[key]({ changedValues: newValue, oldValues: newValue });
51
+ });
52
+ isLoading = true;
53
+ },
54
+ addFormat(name: string, format?: FormatItemModal) {
55
+ if (!format) {
56
+ return;
57
+ }
58
+ const { inputValue, outputValue } = format;
59
+ formatSourceData[name] = {
60
+ inputValue,
61
+ outputValue,
62
+ };
63
+ }, //注册转化方法
64
+ formatValues(value = {}, formatKey = "inputValue") {
65
+ const valKeys = Object.keys(value).length;
66
+ if (!valKeys) {
67
+ return {};
68
+ }
69
+ let newValue = { ...value };
70
+ const keys = Object.keys(formatSourceData);
71
+ keys.forEach((key) => {
72
+ const format = formatSourceData[key]?.[formatKey];
73
+ if (!format) {
74
+ return;
75
+ }
76
+ const resultValue = format(value);
77
+ Reflect.deleteProperty(newValue, key);
78
+ newValue = {
79
+ ...newValue,
80
+ ...resultValue,
81
+ };
82
+ });
83
+ return newValue;
84
+ }, //转化方法
85
+ dispatch(action, ...args) {
86
+ const { key, name } = action;
87
+ const items = dispatchSourceData[key];
88
+ if (!items) {
89
+ return;
90
+ }
91
+ const { keysFn, defaultFn } = items;
92
+ if (name) {
93
+ return keysFn[name]?.(...args);
94
+ }
95
+ const fnArrays = Object.keys(keysFn).map((itemKey) => {
96
+ return keysFn[itemKey];
97
+ }); //不存在name就合并
98
+ [...fnArrays, ...defaultFn].forEach((fn) => {
99
+ fn(...args);
100
+ });
101
+ },
102
+ addDispatchListener(action, fn) {
103
+ const { key, name, dispatch = {} } = action;
104
+ const { manual } = dispatch;
105
+ const items = dispatchSourceData[key];
106
+ if (!items) {
107
+ dispatchSourceData[key] = norAddItemDispatch(name, manual, fn);
108
+ return;
109
+ }
110
+ const { keysFn, defaultFn } = items;
111
+ if (name) {
112
+ keysFn[name] = fn;
113
+ } else {
114
+ defaultFn.push(fn);
115
+ }
116
+ if (manual === false && name) {
117
+ initDispatch[name] = fn;
118
+ }
119
+ dispatchSourceData[key] = {
120
+ keysFn,
121
+ defaultFn,
122
+ };
123
+ },
124
+ removeDispatchListener(action) {
125
+ if (!action) {
126
+ dispatchSourceData = {};
127
+ return;
128
+ }
129
+ const { key, name } = action;
130
+ const items = dispatchSourceData[key];
131
+ if (!items) {
132
+ return;
133
+ }
134
+ if (name) {
135
+ const { keysFn } = items;
136
+ Reflect.deleteProperty(keysFn, name);
137
+ items.keysFn = keysFn;
138
+ dispatchSourceData[key] = items;
139
+ return;
140
+ }
141
+ Reflect.deleteProperty(dispatchSourceData, key);
142
+ },
143
+ outputValues(value) {
144
+ const val = value || form.getFieldsValue();
145
+ return this.formatValues(val, "outputValue");
146
+ },
147
+ ...form,
148
+ setFieldsValue(values) {
149
+ if (!isLoading) {
150
+ cacheValues = values;
151
+ return;
152
+ }
153
+ const newValue = this.formatValues(values);
154
+ form.setFieldsValue(newValue);
155
+ },
156
+ validateFields(nameList) {
157
+ return new Promise((resolve) => {
158
+ form.validateFields(nameList).then((value) => {
159
+ const result = this.formatValues(value, "outputValue");
160
+ return resolve(result);
161
+ });
162
+ });
163
+ },
164
+ resetFieldsInitValue: () => {
165
+ const oldValue = form.getFieldsValue();
166
+ const keys = Object.keys(oldValue);
167
+ const newVale = {};
168
+ keys.forEach((key) => {
169
+ newVale[key] = undefined;
170
+ });
171
+ form.setFieldsValue({
172
+ ...newVale,
173
+ ...initSaveValue,
174
+ });
175
+ },
176
+ clear: () => {
177
+ form.resetFields();
178
+ isLoading = false;
179
+ },
180
+ };
181
+ }, []);
182
+ };
@@ -0,0 +1,194 @@
1
+ import React, { useMemo } from "react";
2
+ import type {
3
+ HFormItemProps,
4
+ HFormProps,
5
+ HItemProps,
6
+ DefaultComponentModal,
7
+ } from "../modal";
8
+ import { placeholderConfig } from "../config";
9
+ import type { Rule } from "rc-field-form/lib/interface";
10
+ import type { FormInstance } from "antd";
11
+ import { useDefaultComponents } from "../hooks";
12
+ import type { ConfigComponentModal } from "../modal";
13
+ import type { DispatchSourceDataModal } from "../modal";
14
+ import type { DispatchModal } from "../modal";
15
+
16
+ const mathRequired = (
17
+ configItem: HFormItemProps,
18
+ form: FormInstance,
19
+ defaultComponents: DefaultComponentModal
20
+ ) => {
21
+ const { required, placeholder, rules, type = "input" } = configItem;
22
+ let resultRequired = false;
23
+ const dom = defaultComponents[type];
24
+ const resultRules = rules?.map((item) => {
25
+ let eachItem = item;
26
+ if (typeof item === "function") {
27
+ eachItem = item(form);
28
+ }
29
+
30
+ const { required: itemRequired, message } = eachItem as any;
31
+ if (itemRequired) {
32
+ resultRequired = itemRequired;
33
+ }
34
+ if (itemRequired && !message) {
35
+ let msg = placeholder;
36
+ const itemDom = dom as ConfigComponentModal;
37
+ if (itemDom?.requiredErrMsg) {
38
+ msg = itemDom.requiredErrMsg(configItem);
39
+ }
40
+ return {
41
+ ...eachItem,
42
+ required: itemRequired,
43
+ message: msg,
44
+ };
45
+ }
46
+ return eachItem;
47
+ });
48
+ return {
49
+ required: typeof required === "boolean" ? required : resultRequired,
50
+ rules: resultRules as Rule[],
51
+ };
52
+ }; //是否必填
53
+ const matchDefaultPlaceholder = (
54
+ props: HFormItemProps,
55
+ defaultComponents: DefaultComponentModal
56
+ ) => {
57
+ const { label, placeholder, type = "input" } = props;
58
+ const dom = defaultComponents[type];
59
+ if (placeholder) {
60
+ return placeholder;
61
+ }
62
+ const itemDom = dom as ConfigComponentModal;
63
+ if (itemDom?.placeholder) {
64
+ return itemDom.placeholder(props);
65
+ }
66
+ if (placeholderConfig.inputType.indexOf(type) !== -1) {
67
+ return `请输入${label}`;
68
+ }
69
+ return `请选择${label}`;
70
+ }; //自动构建
71
+
72
+ const defaultPlaceholderPropsMaker = (
73
+ props: HFormItemProps,
74
+ defaultComponents: DefaultComponentModal
75
+ ) => {
76
+ const placeholder = matchDefaultPlaceholder(props, defaultComponents);
77
+ return {
78
+ ...props,
79
+ placeholder,
80
+ };
81
+ }; //组装参数
82
+ const itemControl = (
83
+ item: HItemProps,
84
+ form: FormInstance,
85
+ defaultComponents: DefaultComponentModal
86
+ ): HFormItemProps => {
87
+ const { render, ...defaultProps } = defaultPlaceholderPropsMaker(
88
+ item,
89
+ defaultComponents
90
+ );
91
+ const { rules, required } = mathRequired(
92
+ defaultProps,
93
+ form,
94
+ defaultComponents
95
+ );
96
+ return {
97
+ ...defaultProps,
98
+ required,
99
+ rules,
100
+ render,
101
+ };
102
+ };
103
+ const itemDispatchProvider = (
104
+ name: string,
105
+ config: Required<DispatchModal<string>>,
106
+ dispatchSourceData: DispatchSourceDataModal
107
+ ) => {
108
+ const { dependencies, fnKey, reset } = config;
109
+ const itemDispatch = dispatchSourceData[dependencies as string];
110
+ if (!itemDispatch) {
111
+ return {
112
+ [dependencies]: {
113
+ [name]: {
114
+ fnKey,
115
+ reset,
116
+ },
117
+ },
118
+ };
119
+ }
120
+ const itemNameDispatch = {
121
+ [name]: {
122
+ fnKey,
123
+ reset,
124
+ },
125
+ };
126
+ return {
127
+ [dependencies]: {
128
+ ...itemDispatch,
129
+ ...itemNameDispatch,
130
+ },
131
+ };
132
+ };
133
+ const dispatchProvider = (
134
+ item: HItemProps,
135
+ dispatchSourceData: DispatchSourceDataModal
136
+ ) => {
137
+ const { name = "", dispatch = {}, dependencies = "allDependencies" } = item;
138
+ const {
139
+ fnKey,
140
+ dependencies: dispatchDependencies = dependencies as string | string[],
141
+ manual = true,
142
+ reset = true,
143
+ } = dispatch;
144
+ if (!fnKey) {
145
+ return {};
146
+ }
147
+ if (Array.isArray(dispatchDependencies)) {
148
+ let allDispatch: DispatchSourceDataModal = {
149
+ ...dispatchSourceData,
150
+ };
151
+ dispatchDependencies.forEach((key) => {
152
+ const itemDispatch = itemDispatchProvider(
153
+ name,
154
+ { dependencies: key, fnKey, manual, reset },
155
+ dispatchSourceData
156
+ );
157
+ allDispatch = {
158
+ ...allDispatch,
159
+ ...itemDispatch,
160
+ };
161
+ });
162
+ return allDispatch;
163
+ }
164
+ const itemDispatch = itemDispatchProvider(
165
+ name,
166
+ { dependencies: dispatchDependencies, fnKey, manual, reset },
167
+ dispatchSourceData
168
+ );
169
+ return {
170
+ ...dispatchSourceData,
171
+ ...itemDispatch,
172
+ };
173
+ };
174
+ type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
175
+
176
+ export default ({ configData, form }: InitConfigModal) => {
177
+ const defaultComponents = useDefaultComponents();
178
+ return useMemo(() => {
179
+ const newConfigData: HItemProps[] = [];
180
+ let dispatchSourceData: DispatchSourceDataModal = {};
181
+ configData.forEach((item) => {
182
+ const itemDispatch = dispatchProvider(item, dispatchSourceData);
183
+ dispatchSourceData = {
184
+ ...dispatchSourceData,
185
+ ...itemDispatch,
186
+ };
187
+ newConfigData.push(itemControl(item, form, defaultComponents));
188
+ });
189
+ return {
190
+ newConfigData,
191
+ dispatchSourceData,
192
+ };
193
+ }, [configData]);
194
+ };
@@ -0,0 +1,54 @@
1
+ @import "../styles/local.less";
2
+ .@{ant-prefix}-hw-form-item-colon:after {
3
+ position: relative;
4
+ top: -0.5px;
5
+ margin: 0 0 0 2px;
6
+ content: ":";
7
+ }
8
+ .@{ant-prefix}-hw-form-item-required:before {
9
+ display: inline-block;
10
+ margin-right: 4px;
11
+ color: #ff4d4f;
12
+ font-size: 14px;
13
+ font-family: SimSun, sans-serif;
14
+ line-height: 1;
15
+ content: "*";
16
+ }
17
+
18
+ .@{ant-prefix}-hw-form-base-item {
19
+ display: flex;
20
+ align-items: center;
21
+ min-height: 32px;
22
+ }
23
+ .@{ant-prefix}-hw-form-base-item-top-left {
24
+ .@{ant-prefix}-form-item-label > label {
25
+ height: auto;
26
+ }
27
+ .@{ant-prefix}-hw-form-item-colon {
28
+ text-align: left;
29
+ }
30
+ }
31
+ .@{ant-prefix}-hw-form-base-item-top-right {
32
+ .@{ant-prefix}-form-item-label > label {
33
+ height: auto;
34
+ }
35
+ .@{ant-prefix}-hw-form-item-colon {
36
+ text-align: right;
37
+ }
38
+ }
39
+ .@{ant-prefix}-hw-form-base-item-top {
40
+ .@{ant-prefix}-form-item-label > label {
41
+ height: auto;
42
+ }
43
+ }
44
+ .@{ant-prefix}-hw-form-base-item-right {
45
+ .@{ant-prefix}-hw-form-item-colon {
46
+ text-align: right;
47
+ }
48
+ }
49
+
50
+ .@{ant-prefix}-hw-form-base-item-left {
51
+ .@{ant-prefix}-hw-form-item-colon {
52
+ text-align: left;
53
+ }
54
+ }
@@ -0,0 +1,113 @@
1
+ import { Form, Row } from "antd";
2
+ import type { HFormProps, HItemProps } from "./modal";
3
+ import Item from "./FormItem";
4
+ import { useCurrentForm, useInfoReq, useValuesChange } from "./hooks";
5
+ import { FormContext } from "./Context";
6
+ import PageHandler from "../PageHandler";
7
+ import useInitConfigData from "./hooks/useInitConfigData";
8
+ import { useEffect } from "react";
9
+ import InitSet from "./InitSet";
10
+ import {ItemPropsType} from "./modal";
11
+
12
+ export default ({
13
+ configData,
14
+ labelWidth,
15
+ form,
16
+ request,
17
+ onFinish,
18
+ infoRequest,
19
+ valueType = "float",
20
+ initialValues,
21
+ params = {},
22
+ onValuesChange,
23
+ itemSpan,
24
+ hideLabel: formHideLabel = false,
25
+ gutter,
26
+ submitLoading,
27
+ labelAlign: formLabelAlign,
28
+ formItemStyle,
29
+ itemProps:formItemProps={},
30
+ ...props
31
+ }: HFormProps) => {
32
+ const hForm = useCurrentForm(form);
33
+ const { newConfigData, dispatchSourceData } = useInitConfigData({
34
+ configData,
35
+ form: hForm,
36
+ });
37
+ const { subControl, infoControl } = useInfoReq({
38
+ initialValues,
39
+ request,
40
+ onFinish,
41
+ valueType,
42
+ form: hForm,
43
+ infoRequest,
44
+ params,
45
+ });
46
+ const valuesChange = useValuesChange({
47
+ onValuesChange,
48
+ dispatch: dispatchSourceData,
49
+ form: hForm,
50
+ });
51
+ const { run, loading } = subControl;
52
+ const {
53
+ run: infoRun,
54
+ loading: infoLoading,
55
+ error: infoErr,
56
+ data: infoData,
57
+ } = infoControl;
58
+
59
+ useEffect(() => {
60
+ return () => {
61
+ hForm.removeDispatchListener();
62
+ };
63
+ }, []);
64
+ return (
65
+ <PageHandler
66
+ loading={infoLoading}
67
+ error={infoErr}
68
+ data={infoData}
69
+ reload={infoRun}
70
+ >
71
+ <FormContext.Provider
72
+ value={{ loading: submitLoading || loading, form: hForm, valueType }}
73
+ >
74
+ <Form
75
+ form={hForm}
76
+ onFinish={run}
77
+ onValuesChange={valuesChange}
78
+ {...props}
79
+ >
80
+ <Row gutter={gutter}>
81
+ {newConfigData.map((itemData: HItemProps, index) => {
82
+ const {
83
+ labelWidth: itemLabelWidth,
84
+ hideLabel = formHideLabel,
85
+ labelAlign = formLabelAlign,
86
+ name,
87
+ style=formItemStyle,
88
+ itemProps={},
89
+ } = itemData;
90
+ const defaultItemProps={
91
+ ...formItemProps,
92
+ ...itemProps
93
+ }
94
+ return (
95
+ <Item
96
+ {...itemData}
97
+ labelAlign={labelAlign}
98
+ key={name||index}
99
+ style={style}
100
+ itemProps={(defaultItemProps as ItemPropsType)}
101
+ hideLabel={hideLabel}
102
+ itemSpan={itemSpan}
103
+ labelWidth={itemLabelWidth || labelWidth}
104
+ />
105
+ );
106
+ })}
107
+ </Row>
108
+ <InitSet />
109
+ </Form>
110
+ </FormContext.Provider>
111
+ </PageHandler>
112
+ );
113
+ };