@hw-component/form 0.0.4-beta-v5 → 0.0.4-beta-v7

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 (38) hide show
  1. package/es/Form/HFormConnect.js +4 -2
  2. package/es/Form/hooks/index.d.ts +7 -0
  3. package/es/Form/hooks/index.js +26 -3
  4. package/es/Form/hooks/useHForm.js +22 -4
  5. package/es/Form/hooks/useInitConfigData.d.ts +6 -2
  6. package/es/Form/hooks/useInitConfigData.js +59 -6
  7. package/es/Form/index.d.ts +1 -1
  8. package/es/Form/index.js +17 -7
  9. package/es/Form/modal.d.ts +8 -0
  10. package/es/Select/hooks/norHooks.d.ts +3 -3
  11. package/es/Select/hooks/norHooks.js +21 -9
  12. package/es/Select/index.js +5 -3
  13. package/es/Select/modal.d.ts +2 -0
  14. package/lib/Form/HFormConnect.js +4 -2
  15. package/lib/Form/hooks/index.d.ts +7 -0
  16. package/lib/Form/hooks/index.js +26 -2
  17. package/lib/Form/hooks/useHForm.js +22 -4
  18. package/lib/Form/hooks/useInitConfigData.d.ts +6 -2
  19. package/lib/Form/hooks/useInitConfigData.js +59 -6
  20. package/lib/Form/index.d.ts +1 -1
  21. package/lib/Form/index.js +16 -6
  22. package/lib/Form/modal.d.ts +8 -0
  23. package/lib/Select/hooks/norHooks.d.ts +3 -3
  24. package/lib/Select/hooks/norHooks.js +21 -9
  25. package/lib/Select/index.js +5 -3
  26. package/lib/Select/modal.d.ts +2 -0
  27. package/package.json +1 -1
  28. package/src/components/Form/HFormConnect.tsx +2 -2
  29. package/src/components/Form/hooks/index.ts +36 -0
  30. package/src/components/Form/hooks/useHForm.ts +17 -4
  31. package/src/components/Form/hooks/useInitConfigData.tsx +79 -2
  32. package/src/components/Form/index.tsx +17 -6
  33. package/src/components/Form/modal.ts +9 -2
  34. package/src/components/Select/hooks/norHooks.ts +9 -9
  35. package/src/components/Select/index.tsx +2 -0
  36. package/src/components/Select/modal.ts +2 -0
  37. package/src/pages/Form/index.tsx +8 -1
  38. package/src/pages/ModalForm/index.tsx +19 -11
@@ -17,12 +17,15 @@ export const useOptionReq = ({
17
17
  serviceSearch,
18
18
  showSearch,
19
19
  onSearch: propsOnSearch,
20
+ dispatch = {},
20
21
  }: PartialHSelectProps) => {
22
+ const { manual: dispatchManual } = dispatch;
21
23
  const { form } = useFormContext();
22
24
  const [data, setData] = useState<OptionType[] | undefined>();
23
25
  const { run, loading, error } = useRequest(
24
- async (params = {}, type = "init") => {
25
- const formData = form?.getFieldsValue();
26
+ async (requestParams = {}) => {
27
+ const { params = {}, values, type = "init" } = requestParams;
28
+ const formData = values || form?.getFieldsValue();
26
29
  if (type === "init") {
27
30
  setData(undefined);
28
31
  }
@@ -32,28 +35,25 @@ export const useOptionReq = ({
32
35
  return Promise.resolve(options);
33
36
  },
34
37
  {
35
- manual,
38
+ manual: dispatchManual === false ? true : manual,
36
39
  debounceInterval: 300,
37
40
  onSuccess: (resultData) => {
38
41
  setData(resultData);
39
42
  },
40
43
  }
41
44
  );
42
- const reload = ({
43
- options: changeOpts,
44
- params: requestParams,
45
- }: ParamsModal) => {
45
+ const reload = ({ options: changeOpts, params }: ParamsModal) => {
46
46
  if (changeOpts) {
47
47
  return setData(changeOpts);
48
48
  }
49
- return run(requestParams);
49
+ return run({ params });
50
50
  };
51
51
  const onSearch = (inputValue: string) => {
52
52
  if (!serviceSearch) {
53
53
  propsOnSearch?.(inputValue);
54
54
  return;
55
55
  }
56
- run({ inputValue });
56
+ run({ params: { inputValue } });
57
57
  };
58
58
  useEffect(() => {
59
59
  if (options) {
@@ -32,6 +32,7 @@ const Index: React.FC<HSelectProps> = ({
32
32
  allSelect,
33
33
  addDispatchListener,
34
34
  addFormat,
35
+ dispatch,
35
36
  ...props
36
37
  }) => {
37
38
  const { icon, render } = modeConfig?.[mode || ""] || {};
@@ -54,6 +55,7 @@ const Index: React.FC<HSelectProps> = ({
54
55
  serviceSearch,
55
56
  showSearch,
56
57
  onSearch: propsOnSearch,
58
+ dispatch,
57
59
  }); //options
58
60
 
59
61
  const data = useChangeOptions({ options: resultData, fieldNames });
@@ -3,6 +3,7 @@ import type React from "react";
3
3
  import type { PromiseFnResult } from "../modal";
4
4
  import type { argsFn } from "@/components/Form/modal";
5
5
  import type { addFormatItemModal } from "@/components/Form/modal";
6
+ import type { DispatchModal } from "@/components/Form/modal";
6
7
  export type OptionType = Record<string, any>;
7
8
  export type PartialHSelectProps = Partial<HSelectProps>;
8
9
  export type RenderFn = (data: OptionType) => React.ReactNode;
@@ -29,6 +30,7 @@ export interface HSelectProps
29
30
  addDispatchListener?: (key: string, fn: argsFn) => void;
30
31
  addFormat?: (format: Record<string, addFormatItemModal>) => void;
31
32
  placeholder?: string;
33
+ dispatch?: DispatchModal;
32
34
  }
33
35
  export interface FilterDataModal {
34
36
  value: any;
@@ -24,8 +24,14 @@ 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
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
  },
@@ -145,11 +151,12 @@ export default () => {
145
151
  configData={formData(options)}
146
152
  labelWidth={200}
147
153
  form={form}
154
+ initialValues={{}}
148
155
  onFinish={(value) => {
149
156
  console.log(value);
150
157
  }}
151
158
  onValuesChange={(val) => {
152
- console.log(val);
159
+ console.log(val, "onValuesChange");
153
160
  }}
154
161
  infoRequest={() => {
155
162
  return new Promise<any>((resolve) => {
@@ -96,6 +96,25 @@ const data = [
96
96
  type: "urlUpload",
97
97
  rules: [{ required: true }],
98
98
  },
99
+ {
100
+ label: "下拉框",
101
+ name: "select",
102
+ type: "select",
103
+ dispatch: {
104
+ fnKey: "reload",
105
+ dependencies: ["selectInput", "sz"],
106
+ manual: false,
107
+ },
108
+ itemProps: {
109
+ request: (params = {}, values) => {
110
+ console.log(values, "paramsparamsparams");
111
+ const { label = "123", value = 1 } = params;
112
+ return Promise.resolve([{ label, value }]);
113
+ },
114
+ showSearch: true,
115
+ },
116
+ rules: [{ required: true }],
117
+ },
99
118
  ];
100
119
  let num = 0;
101
120
  export default () => {
@@ -120,17 +139,6 @@ export default () => {
120
139
  request={(val, params) => {
121
140
  console.log(val, params);
122
141
  }}
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
142
  dialogForm={modalForm}
135
143
  title="测试"
136
144
  />