@hw-component/form 0.0.4-beta-v4 → 0.0.4-beta-v6

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 (50) hide show
  1. package/es/DialogForm/hooks.d.ts +1 -1
  2. package/es/Form/HFormConnect.js +4 -2
  3. package/es/Form/hooks/index.d.ts +7 -0
  4. package/es/Form/hooks/index.js +26 -3
  5. package/es/Form/hooks/useHForm.js +19 -5
  6. package/es/Form/hooks/useInitConfigData.d.ts +6 -2
  7. package/es/Form/hooks/useInitConfigData.js +59 -6
  8. package/es/Form/index.d.ts +1 -1
  9. package/es/Form/index.js +16 -7
  10. package/es/Form/modal.d.ts +8 -0
  11. package/es/Input/SelectInput.d.ts +1 -1
  12. package/es/Select/hooks/norHooks.d.ts +3 -3
  13. package/es/Select/hooks/norHooks.js +29 -12
  14. package/es/Select/index.js +6 -3
  15. package/es/Select/modal.d.ts +6 -1
  16. package/es/modal.d.ts +1 -1
  17. package/lib/DialogForm/hooks.d.ts +1 -1
  18. package/lib/Form/HFormConnect.js +4 -2
  19. package/lib/Form/hooks/index.d.ts +7 -0
  20. package/lib/Form/hooks/index.js +26 -2
  21. package/lib/Form/hooks/useHForm.js +19 -5
  22. package/lib/Form/hooks/useInitConfigData.d.ts +6 -2
  23. package/lib/Form/hooks/useInitConfigData.js +59 -6
  24. package/lib/Form/index.d.ts +1 -1
  25. package/lib/Form/index.js +15 -6
  26. package/lib/Form/modal.d.ts +8 -0
  27. package/lib/Input/SelectInput.d.ts +1 -1
  28. package/lib/Select/hooks/norHooks.d.ts +3 -3
  29. package/lib/Select/hooks/norHooks.js +29 -12
  30. package/lib/Select/index.js +6 -3
  31. package/lib/Select/modal.d.ts +6 -1
  32. package/lib/modal.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/src/components/DialogForm/ModalForm.tsx +2 -2
  35. package/src/components/DialogForm/hooks.ts +5 -5
  36. package/src/components/DialogForm/modal.ts +2 -2
  37. package/src/components/Form/HFormConnect.tsx +2 -2
  38. package/src/components/Form/hooks/index.ts +36 -0
  39. package/src/components/Form/hooks/useHForm.ts +13 -4
  40. package/src/components/Form/hooks/useInitConfigData.tsx +79 -2
  41. package/src/components/Form/index.tsx +16 -6
  42. package/src/components/Form/modal.ts +9 -2
  43. package/src/components/Input/SelectInput.tsx +0 -1
  44. package/src/components/Select/hooks/norHooks.ts +12 -9
  45. package/src/components/Select/index.tsx +3 -0
  46. package/src/components/Select/modal.ts +7 -1
  47. package/src/components/modal.ts +4 -1
  48. package/src/pages/Form/index.tsx +10 -2
  49. package/src/pages/ModalForm/index.tsx +0 -11
  50. package/src/pages/Select/index.tsx +0 -1
@@ -10,6 +10,8 @@ import type { Rule } from "rc-field-form/lib/interface";
10
10
  import type { FormInstance } from "antd";
11
11
  import { useDefaultComponents } from "../hooks";
12
12
  import type { ConfigComponentModal } from "../modal";
13
+ import type { DispatchSourceDataModal } from "../modal";
14
+ import type { DispatchModal } from "../modal";
13
15
 
14
16
  const mathRequired = (
15
17
  configItem: HFormItemProps,
@@ -98,13 +100,88 @@ const itemControl = (
98
100
  render,
99
101
  };
100
102
  };
103
+ const itemDispatchProvider = (
104
+ name: string,
105
+ config: Required<DispatchModal<string>>,
106
+ dispatchSourceData: DispatchSourceDataModal
107
+ ) => {
108
+ const { dependencies, fnKey } = config;
109
+ const itemDispatch = dispatchSourceData[dependencies as string];
110
+ if (!itemDispatch) {
111
+ return {
112
+ [dependencies]: {
113
+ [name]: fnKey,
114
+ },
115
+ };
116
+ }
117
+ const itemNameDispatch = {
118
+ [name]: fnKey,
119
+ };
120
+ return {
121
+ [dependencies]: {
122
+ ...itemDispatch,
123
+ ...itemNameDispatch,
124
+ },
125
+ };
126
+ };
127
+ const dispatchProvider = (
128
+ item: HItemProps,
129
+ dispatchSourceData: DispatchSourceDataModal
130
+ ) => {
131
+ const { name = "", dispatch = {}, dependencies = "allDependencies" } = item;
132
+ const {
133
+ fnKey,
134
+ dependencies: dispatchDependencies = dependencies as string | string[],
135
+ manual = true,
136
+ } = dispatch;
137
+ if (!fnKey) {
138
+ return {};
139
+ }
140
+ if (Array.isArray(dispatchDependencies)) {
141
+ let allDispatch: DispatchSourceDataModal = {
142
+ ...dispatchSourceData,
143
+ };
144
+ dispatchDependencies.forEach((key) => {
145
+ const itemDispatch = itemDispatchProvider(
146
+ name,
147
+ { dependencies: key, fnKey, manual },
148
+ dispatchSourceData
149
+ );
150
+ allDispatch = {
151
+ ...allDispatch,
152
+ ...itemDispatch,
153
+ };
154
+ });
155
+ return allDispatch;
156
+ }
157
+ const itemDispatch = itemDispatchProvider(
158
+ name,
159
+ { dependencies: dispatchDependencies, fnKey, manual },
160
+ dispatchSourceData
161
+ );
162
+ return {
163
+ ...dispatchSourceData,
164
+ ...itemDispatch,
165
+ };
166
+ };
101
167
  type InitConfigModal = Required<Pick<HFormProps, "configData" | "form">>;
102
168
 
103
169
  export default ({ configData, form }: InitConfigModal) => {
104
170
  const defaultComponents = useDefaultComponents();
105
171
  return useMemo(() => {
106
- return configData.map((item) => {
107
- return itemControl(item, form, defaultComponents);
172
+ const newConfigData:HItemProps[] = [];
173
+ let dispatchSourceData: DispatchSourceDataModal = {};
174
+ configData.forEach((item) => {
175
+ const itemDispatch = dispatchProvider(item, dispatchSourceData);
176
+ dispatchSourceData = {
177
+ ...dispatchSourceData,
178
+ ...itemDispatch,
179
+ };
180
+ newConfigData.push(itemControl(item, form, defaultComponents));
108
181
  });
182
+ return {
183
+ newConfigData,
184
+ dispatchSourceData,
185
+ };
109
186
  }, [configData]);
110
187
  };
@@ -1,7 +1,7 @@
1
1
  import { Form } from "antd";
2
- import type { HFormProps } from "./modal";
2
+ import type { HFormProps, HItemProps } from "./modal";
3
3
  import Item from "./FormItem";
4
- import { useCurrentForm, useInfoReq } from "./hooks";
4
+ import { useCurrentForm, useInfoReq, useValuesChange } from "./hooks";
5
5
  import { FormContext } from "./Context";
6
6
  import PageHandler from "../PageHandler";
7
7
  import useInitConfigData from "./hooks/useInitConfigData";
@@ -18,10 +18,11 @@ export default ({
18
18
  valueType = "float",
19
19
  initialValues,
20
20
  params = {},
21
+ onValuesChange,
21
22
  ...props
22
23
  }: HFormProps) => {
23
24
  const hForm = useCurrentForm(form);
24
- const newConfigData = useInitConfigData({
25
+ const { newConfigData, dispatchSourceData } = useInitConfigData({
25
26
  configData,
26
27
  form: hForm,
27
28
  });
@@ -34,7 +35,11 @@ export default ({
34
35
  infoRequest,
35
36
  params,
36
37
  });
37
-
38
+ const valuesChange = useValuesChange({
39
+ onValuesChange,
40
+ dispatch: dispatchSourceData,
41
+ form: hForm,
42
+ });
38
43
  const { run, loading } = subControl;
39
44
  const {
40
45
  run: infoRun,
@@ -56,8 +61,13 @@ export default ({
56
61
  reload={infoRun}
57
62
  >
58
63
  <FormContext.Provider value={{ loading, form: hForm, valueType }}>
59
- <Form form={hForm} onFinish={run} {...props}>
60
- {newConfigData.map((itemData, index) => {
64
+ <Form
65
+ form={hForm}
66
+ onFinish={run}
67
+ onValuesChange={valuesChange}
68
+ {...props}
69
+ >
70
+ {newConfigData.map((itemData: HItemProps, index) => {
61
71
  const { labelWidth: itemLabelWidth } = itemData;
62
72
  return (
63
73
  <Item
@@ -27,6 +27,7 @@ import type {
27
27
  } from "../modal";
28
28
  import type { ForwardedRef } from "react";
29
29
  import type { DataFnProvider } from "../modal";
30
+
30
31
  type RenderFun = (
31
32
  props: HItemProps,
32
33
  node: React.ReactNode,
@@ -56,7 +57,12 @@ type HelperModal = (form: HFormInstance) => React.ReactNode | string;
56
57
  export type HideModal = (form: HFormInstance) => boolean;
57
58
 
58
59
  export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
59
-
60
+ export type DispatchSourceDataModal = Record<string, Record<string, string>>;
61
+ export interface DispatchModal<T = string | string[]> {
62
+ fnKey?: string;
63
+ dependencies?: T;
64
+ manual?: boolean;
65
+ }
60
66
  export interface HItemProps extends Omit<FormItemProps, "name"> {
61
67
  type?: string;
62
68
  itemProps?: ItemPropsType;
@@ -69,6 +75,7 @@ export interface HItemProps extends Omit<FormItemProps, "name"> {
69
75
  placeholder?: string | string[];
70
76
  // formatKeys?: string[];
71
77
  name?: string;
78
+ dispatch?: DispatchModal;
72
79
  }
73
80
 
74
81
  export interface HFormProps<T = any, R = any>
@@ -82,7 +89,6 @@ export interface HFormProps<T = any, R = any>
82
89
  params?: any;
83
90
  onFinish?: (values: T, params?: any) => void;
84
91
  }
85
-
86
92
  export interface HFormItemProps extends HItemProps {
87
93
  required?: boolean;
88
94
  value?: any;
@@ -123,6 +129,7 @@ export interface IFormConfigContextProps {
123
129
  interface ActionModal {
124
130
  key: string;
125
131
  name?: string;
132
+ dispatch?: DispatchModal;
126
133
  }
127
134
  export interface HFormInstance extends FormInstance {
128
135
  addFormat: (name: string, formats?: FormatItemModal) => void;
@@ -3,7 +3,6 @@ import type { HSelectInputProps } from "./modal";
3
3
  import HSelect from "../Select";
4
4
  import { defaultSelectStyle, defaultValueName } from "./defaultConfig";
5
5
  import HFormConnect from "../Form/HFormConnect";
6
- import { ConnectResultProps } from "@/components/Form/modal";
7
6
  export enum SelectInputType {
8
7
  input,
9
8
  select,
@@ -4,6 +4,7 @@ import type {
4
4
  PartialHSelectProps,
5
5
  } from "@/components/Select/modal";
6
6
  import { useRequest } from "ahooks";
7
+ import { useFormContext } from "../../Form/Context";
7
8
 
8
9
  interface ParamsModal {
9
10
  options?: OptionType[];
@@ -16,41 +17,43 @@ export const useOptionReq = ({
16
17
  serviceSearch,
17
18
  showSearch,
18
19
  onSearch: propsOnSearch,
20
+ dispatch = {},
19
21
  }: PartialHSelectProps) => {
22
+ const { manual: dispatchManual } = dispatch;
23
+ const { form } = useFormContext();
20
24
  const [data, setData] = useState<OptionType[] | undefined>();
21
25
  const { run, loading, error } = useRequest(
22
- async (params = {}, type = "init") => {
26
+ async (requestParams = {}) => {
27
+ const { params = {}, values, type = "init" } = requestParams;
28
+ const formData = values || form?.getFieldsValue();
23
29
  if (type === "init") {
24
30
  setData(undefined);
25
31
  }
26
32
  if (request) {
27
- return request(params);
33
+ return request(params, formData);
28
34
  }
29
35
  return Promise.resolve(options);
30
36
  },
31
37
  {
32
- manual,
38
+ manual: dispatchManual === false ? true : manual,
33
39
  debounceInterval: 300,
34
40
  onSuccess: (resultData) => {
35
41
  setData(resultData);
36
42
  },
37
43
  }
38
44
  );
39
- const reload = ({
40
- options: changeOpts,
41
- params: requestParams,
42
- }: ParamsModal) => {
45
+ const reload = ({ options: changeOpts, params }: ParamsModal) => {
43
46
  if (changeOpts) {
44
47
  return setData(changeOpts);
45
48
  }
46
- return run(requestParams);
49
+ return run({ params });
47
50
  };
48
51
  const onSearch = (inputValue: string) => {
49
52
  if (!serviceSearch) {
50
53
  propsOnSearch?.(inputValue);
51
54
  return;
52
55
  }
53
- run({ inputValue });
56
+ run({ params: { inputValue } });
54
57
  };
55
58
  useEffect(() => {
56
59
  if (options) {
@@ -31,6 +31,8 @@ const Index: React.FC<HSelectProps> = ({
31
31
  noMatchItemRender = defaultSelectConfig.noMatchItemRender,
32
32
  allSelect,
33
33
  addDispatchListener,
34
+ addFormat,
35
+ dispatch,
34
36
  ...props
35
37
  }) => {
36
38
  const { icon, render } = modeConfig?.[mode || ""] || {};
@@ -53,6 +55,7 @@ const Index: React.FC<HSelectProps> = ({
53
55
  serviceSearch,
54
56
  showSearch,
55
57
  onSearch: propsOnSearch,
58
+ dispatch,
56
59
  }); //options
57
60
 
58
61
  const data = useChangeOptions({ options: resultData, fieldNames });
@@ -2,6 +2,8 @@ import type { SelectProps } from "antd";
2
2
  import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
4
  import type { argsFn } from "@/components/Form/modal";
5
+ import type { addFormatItemModal } from "@/components/Form/modal";
6
+ import type { DispatchModal } from "@/components/Form/modal";
5
7
  export type OptionType = Record<string, any>;
6
8
  export type PartialHSelectProps = Partial<HSelectProps>;
7
9
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -14,7 +16,8 @@ export interface ModeConfig {
14
16
  multiple?: ModeConfigItem;
15
17
  tags?: ModeConfigItem;
16
18
  }
17
- export interface HSelectProps extends Omit<SelectProps, "options"> {
19
+ export interface HSelectProps
20
+ extends Omit<SelectProps, "options" | "placeholder"> {
18
21
  style?: React.CSSProperties;
19
22
  request?: PromiseFnResult<any, OptionType[]>;
20
23
  manual?: boolean;
@@ -25,6 +28,9 @@ export interface HSelectProps extends Omit<SelectProps, "options"> {
25
28
  noMatchItemRender?: RenderFn; //没有数据
26
29
  allSelect?: boolean; //显示全选
27
30
  addDispatchListener?: (key: string, fn: argsFn) => void;
31
+ addFormat?: (format: Record<string, addFormatItemModal>) => void;
32
+ placeholder?: string;
33
+ dispatch?: DispatchModal;
28
34
  }
29
35
  export interface FilterDataModal {
30
36
  value: any;
@@ -2,7 +2,10 @@ export interface ValueCheckMapModal {
2
2
  checked?: any;
3
3
  noChecked?: any;
4
4
  }
5
- export type PromiseFnResult<T = any, R = any> = (params: T) => Promise<R>;
5
+ export type PromiseFnResult<T = any, R = any> = (
6
+ params: T,
7
+ formDataValues?: any
8
+ ) => Promise<R>;
6
9
  export interface ValueSwitchMapModal {
7
10
  open?: any;
8
11
  close?: any;
@@ -24,11 +24,18 @@ const formData = (options) => {
24
24
  label: "下拉框",
25
25
  name: "select",
26
26
  type: "select",
27
+ dispatch: {
28
+ fnKey: "reload",
29
+ dependencies: ["selectInput", "sz"],
30
+ manual: false,
31
+ },
27
32
  itemProps: {
28
- request: (params = {}) => {
33
+ request: (params = {}, values) => {
34
+ console.log(values, "paramsparamsparams");
29
35
  const { label = "123", value = 1 } = params;
30
36
  return Promise.resolve([{ label, value }]);
31
37
  },
38
+ showSearch: true,
32
39
  },
33
40
  rules: [{ required: true }],
34
41
  },
@@ -144,11 +151,12 @@ export default () => {
144
151
  configData={formData(options)}
145
152
  labelWidth={200}
146
153
  form={form}
154
+ initialValues={{}}
147
155
  onFinish={(value) => {
148
156
  console.log(value);
149
157
  }}
150
158
  onValuesChange={(val) => {
151
- console.log(val);
159
+ console.log(val, "onValuesChange");
152
160
  }}
153
161
  infoRequest={() => {
154
162
  return new Promise<any>((resolve) => {
@@ -120,17 +120,6 @@ export default () => {
120
120
  request={(val, params) => {
121
121
  console.log(val, params);
122
122
  }}
123
- infoRequest={(ppp) => {
124
- console.log(ppp);
125
- return Promise.resolve({
126
- check1: 1,
127
- testStart: "1694747960",
128
- testEnd: "1693538359",
129
- op: 1,
130
- opInput: "12121",
131
- name: ppp.name,
132
- });
133
- }}
134
123
  dialogForm={modalForm}
135
124
  title="测试"
136
125
  />
@@ -15,7 +15,6 @@ export default () => {
15
15
  { name: "测试2", value: 20, userId: 112321 },
16
16
  ]}
17
17
  placeholder="多选"
18
- mode={"multiple"}
19
18
  onChange={(val, option) => {
20
19
  console.log(val, option);
21
20
  }}