@hw-component/form 1.9.46 → 1.9.47

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 (81) hide show
  1. package/.eslintcache +1 -1
  2. package/es/DialogForm/DrawerForm/Footer.js +5 -4
  3. package/es/DialogForm/DrawerForm/index.js +8 -16
  4. package/es/DialogForm/hooks.d.ts +5 -4
  5. package/es/DialogForm/hooks.js +13 -3
  6. package/es/DialogForm/modal.d.ts +1 -1
  7. package/es/Form/config.d.ts +1 -1
  8. package/es/Form/modal.d.ts +1 -1
  9. package/es/Input/ButtonInput.js +5 -5
  10. package/es/Input/SelectInput.js +1 -0
  11. package/es/PageHandler/ErrorComponent.js +3 -2
  12. package/es/Select/TreeSelect.d.ts +2 -2
  13. package/es/Select/components/NotFoundContent.js +3 -2
  14. package/es/Submit/components.js +3 -3
  15. package/es/Switch/index.d.ts +1 -1
  16. package/es/Text/index.d.ts +1 -1
  17. package/es/index.css +8 -8
  18. package/es/index.d.ts +1 -1
  19. package/lib/DialogForm/DrawerForm/Footer.js +4 -3
  20. package/lib/DialogForm/DrawerForm/index.js +7 -15
  21. package/lib/DialogForm/hooks.d.ts +5 -4
  22. package/lib/DialogForm/hooks.js +13 -3
  23. package/lib/DialogForm/modal.d.ts +1 -1
  24. package/lib/Form/config.d.ts +1 -1
  25. package/lib/Form/modal.d.ts +1 -1
  26. package/lib/Input/ButtonInput.js +4 -4
  27. package/lib/Input/SelectInput.js +1 -0
  28. package/lib/PageHandler/ErrorComponent.js +2 -1
  29. package/lib/Select/TreeSelect.d.ts +2 -2
  30. package/lib/Select/components/NotFoundContent.js +2 -1
  31. package/lib/Submit/components.js +3 -3
  32. package/lib/Switch/index.d.ts +1 -1
  33. package/lib/Text/index.d.ts +1 -1
  34. package/lib/index.css +8 -8
  35. package/lib/index.d.ts +1 -1
  36. package/package.json +5 -3
  37. package/src/components/CheckboxGroup/index.tsx +3 -3
  38. package/src/components/DialogForm/DrawerForm/Footer.tsx +7 -5
  39. package/src/components/DialogForm/DrawerForm/index.tsx +10 -21
  40. package/src/components/DialogForm/ModalForm.tsx +2 -2
  41. package/src/components/DialogForm/{hooks.ts → hooks.tsx} +17 -4
  42. package/src/components/DialogForm/modal.ts +1 -1
  43. package/src/components/Form/Basic.tsx +2 -2
  44. package/src/components/Form/HFormConnect.tsx +3 -3
  45. package/src/components/Form/config.ts +1 -1
  46. package/src/components/Form/hooks/index.ts +9 -9
  47. package/src/components/Form/hooks/useInitConfigData.tsx +3 -3
  48. package/src/components/Form/index.tsx +0 -1
  49. package/src/components/Form/modal.ts +6 -6
  50. package/src/components/Input/ButtonInput.tsx +27 -25
  51. package/src/components/Input/InputNumberGroup.tsx +4 -4
  52. package/src/components/Input/SelectInput.tsx +3 -2
  53. package/src/components/Input/TrimInput.tsx +3 -3
  54. package/src/components/Input/index.less +1 -1
  55. package/src/components/Input/modal.ts +1 -1
  56. package/src/components/PageHandler/ErrorComponent.tsx +4 -3
  57. package/src/components/PageHandler/index.tsx +0 -1
  58. package/src/components/PageHandler/modal.ts +1 -1
  59. package/src/components/Select/TreeSelect.tsx +51 -35
  60. package/src/components/Select/components/NotFoundContent.tsx +4 -3
  61. package/src/components/Select/index.less +18 -18
  62. package/src/components/Select/index.tsx +84 -75
  63. package/src/components/Select/modal.ts +2 -2
  64. package/src/components/Submit/components.tsx +5 -5
  65. package/src/components/Switch/index.tsx +16 -13
  66. package/src/components/TDPicker/RangePicker.tsx +2 -2
  67. package/src/components/Text/index.tsx +5 -5
  68. package/src/components/TextArea/TrimTextArea.tsx +3 -3
  69. package/src/components/Upload/MediaTypeEle/TypeEle.tsx +7 -1
  70. package/src/components/Upload/UrlUpload/index.tsx +1 -1
  71. package/src/components/Upload/index.tsx +4 -4
  72. package/src/components/index.tsx +1 -1
  73. package/src/components/styles/index.less +2 -2
  74. package/src/index.less +1 -0
  75. package/src/index.tsx +1 -0
  76. package/src/pages/DrawerForm/index.tsx +0 -3
  77. package/src/pages/Form/index.tsx +146 -77
  78. package/src/pages/Input/index.tsx +1 -1
  79. package/src/pages/ModalForm/index.tsx +3 -4
  80. package/src/pages/Switch/index.tsx +11 -11
  81. package/src/pages/Upload/index.tsx +6 -2
@@ -1,4 +1,5 @@
1
- import { Row, Space, Button } from "antd";
1
+ import { Row, Space } from "antd";
2
+ import {HJBtn} from "@hw-component/hj";
2
3
 
3
4
  interface IProps {
4
5
  onOk?: VoidFunction;
@@ -7,13 +8,14 @@ interface IProps {
7
8
  }
8
9
 
9
10
  export default ({ onCancel, onOk, confirmLoading }: IProps) => {
11
+
10
12
  return (
11
13
  <Row justify={"end"}>
12
- <Space size={"middle"}>
13
- <Button onClick={onCancel}>关闭</Button>
14
- <Button type={"primary"} onClick={onOk} loading={confirmLoading}>
14
+ <Space size={"small"}>
15
+ <HJBtn onClick={onCancel}>关闭</HJBtn>
16
+ <HJBtn type={"primary"} onClick={onOk} loading={confirmLoading}>
15
17
  确定
16
- </Button>
18
+ </HJBtn>
17
19
  </Space>
18
20
  </Row>
19
21
  );
@@ -1,9 +1,8 @@
1
1
  import { Drawer } from "antd";
2
2
  import type { DialogFormProps } from "../modal";
3
- import { useCurrentForm, useModifyProps, useSub } from "../hooks";
3
+ import {useCurrentForm, useFooterRender, useModifyProps, useSub} from "@/components/DialogForm/hooks";
4
4
  import HForm from "../../Form";
5
5
  import Title from "./Title";
6
- import Footer from "./Footer";
7
6
  import FormConfigProvider, {
8
7
  useFormConfigContext,
9
8
  } from "../../Form/Context/FormConfigProvider";
@@ -62,23 +61,13 @@ const Index: React.FC<DialogFormProps> = ({
62
61
  setModalVisible(false);
63
62
  };
64
63
  const { loading, run } = useSub({ request, onFinish });
65
- const footerComponent = () => {
66
- if (footer === null) {
67
- return null;
68
- }
69
- if (typeof footer === "function") {
70
- return footer(dialogForm, loading, formParams);
71
- }
72
- return (
73
- footer || (
74
- <Footer
75
- onCancel={cancel}
76
- onOk={currentForm.submit}
77
- confirmLoading={loading}
78
- />
79
- )
80
- );
81
- };
64
+
65
+ const defaultFooter = useFooterRender({
66
+ dialogForm,
67
+ footer,
68
+ confirmLoading: loading,
69
+ params: formParams,
70
+ });
82
71
  const node = (
83
72
  <HForm
84
73
  configData={modalFormData}
@@ -106,8 +95,8 @@ const Index: React.FC<DialogFormProps> = ({
106
95
  {...props}
107
96
  onClose={cancel}
108
97
  closable={false}
109
- destroyOnClose={true}
110
- footer={footerComponent()}
98
+ destroyOnClose
99
+ footer={defaultFooter}
111
100
  >
112
101
  <FormConfigProvider {...providerConfig}>
113
102
  <ChildComponent
@@ -9,7 +9,7 @@ import {
9
9
  useFooterRender,
10
10
  useModifyProps,
11
11
  useSub,
12
- } from "./hooks";
12
+ } from "@/components/DialogForm/hooks";
13
13
  import ChildComponent from "./ChildComponent";
14
14
  import React from "react";
15
15
  const Index: React.FC<DialogFormProps> = ({
@@ -97,7 +97,7 @@ const Index: React.FC<DialogFormProps> = ({
97
97
  }}
98
98
  {...props}
99
99
  onOk={currentForm.submit}
100
- destroyOnClose={true}
100
+ destroyOnClose
101
101
  footer={defaultFooter}
102
102
  >
103
103
  <FormConfigProvider {...providerConfig}>
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useState } from "react";
1
+ import React, { useEffect, useMemo, useState } from "react";
2
2
  import useHForm from "../Form/hooks/useHForm";
3
3
  import type {
4
4
  DialogFormProps,
@@ -6,6 +6,7 @@ import type {
6
6
  ModifyPropsModal,
7
7
  } from "./modal";
8
8
  import { useRequest } from "ahooks";
9
+ import Footer from "@/components/DialogForm/DrawerForm/Footer";
9
10
 
10
11
  export const useModifyProps = ({
11
12
  visible,
@@ -127,11 +128,23 @@ export const useFooterRender = ({
127
128
  dialogForm,
128
129
  params,
129
130
  }: Omit<DialogFormProps, "configData">) => {
130
- if (!footer) {
131
- return footer;
131
+ if (footer===null){
132
+ return null;
132
133
  }
133
134
  if (typeof footer === "function") {
134
135
  return footer(dialogForm, confirmLoading, params);
135
136
  }
136
- return footer;
137
+ return (
138
+ footer || (
139
+ <Footer
140
+ onCancel={()=>{
141
+ dialogForm?.hide();
142
+ }}
143
+ onOk={()=>{
144
+ dialogForm?.submit()
145
+ }}
146
+ confirmLoading={confirmLoading}
147
+ />
148
+ )
149
+ );
137
150
  };
@@ -29,7 +29,7 @@ export interface HDialogFormInstance<P = any, T = any> extends HFormInstance {
29
29
  show: (data?: ShowParamsModal<P, T>) => void;
30
30
  hide: VoidFunction;
31
31
  }
32
- type FooterRender = (
32
+ export type FooterRender = (
33
33
  dialogForm?: HDialogFormInstance,
34
34
  loading?: boolean,
35
35
  params?: Record<string, any>
@@ -53,8 +53,8 @@ export default ({
53
53
  ...formItemProps,
54
54
  ...itemProps,
55
55
  };
56
- const arrayName=Array.isArray(name)?name.join("."):name;
57
- const key=arrayName||nameKey;
56
+ const arrayName = Array.isArray(name) ? name.join(".") : name;
57
+ const key = arrayName || nameKey;
58
58
  return (
59
59
  <Item
60
60
  {...itemData}
@@ -45,7 +45,7 @@ export default (
45
45
  ) => {
46
46
  const { form, valueType = "float" } = useFormContext();
47
47
  const { name } = props;
48
- const relName=Array.isArray(name)?name.join("."):name;
48
+ const relName = Array.isArray(name) ? name.join(".") : name;
49
49
  useEffect(() => {
50
50
  if (!relName) {
51
51
  return;
@@ -59,11 +59,11 @@ export default (
59
59
  form?.addFormat(relName, formatMaker(props, aFormat[valueType]));
60
60
  };
61
61
  const addDispatchListener = (key: string, fn: argsFn) => {
62
- const {dispatch } = props;
62
+ const { dispatch } = props;
63
63
  if (!relName) {
64
64
  return;
65
65
  }
66
- form?.addDispatchListener({ key, name:relName, dispatch }, fn);
66
+ form?.addDispatchListener({ key, name: relName, dispatch }, fn);
67
67
  };
68
68
  const Component = component as React.ForwardRefRenderFunction<
69
69
  any,
@@ -21,7 +21,7 @@ import VerificationCodeInput from "../Input/VerificationCodeInput";
21
21
  import TrimInput from "../Input/TrimInput";
22
22
  import TrimTextArea from "../TextArea/TrimTextArea";
23
23
  import HInputNumberGroup from "../Input/InputNumberGroup";
24
- import HText from '../Text'
24
+ import HText from "../Text";
25
25
  export const placeholderConfig = {
26
26
  inputType: [
27
27
  "input",
@@ -33,19 +33,19 @@ export const useInfoReq = ({
33
33
  params: saveParams,
34
34
  };
35
35
  }, [params]);
36
- const {infoReq:initReq,options}=useMemo(()=>{
37
- if (typeof infoRequest==="object"){
38
- const {request:infoReq,...op}=infoRequest;
36
+ const { infoReq: initReq, options } = useMemo(() => {
37
+ if (typeof infoRequest === "object") {
38
+ const { request: infoReq, ...op } = infoRequest;
39
39
  return {
40
40
  infoReq,
41
- options:op
42
- }
41
+ options: op,
42
+ };
43
43
  }
44
44
  return {
45
- infoReq:infoRequest,
46
- options:{}
45
+ infoReq: infoRequest,
46
+ options: {},
47
47
  };
48
- },[infoRequest]);
48
+ }, [infoRequest]);
49
49
 
50
50
  const subControl = useRequest(
51
51
  async (value) => {
@@ -69,7 +69,7 @@ export const useInfoReq = ({
69
69
  }
70
70
  form?.setFieldsValue(initialValues);
71
71
  return initialValues;
72
- },options);
72
+ }, options);
73
73
  const { run, mutate } = infoControl;
74
74
  useEffect(() => {
75
75
  if (form) {
@@ -135,7 +135,7 @@ const dispatchProvider = (
135
135
  dispatchSourceData: DispatchSourceDataModal
136
136
  ) => {
137
137
  const { name = "", dispatch = {}, dependencies = "allDependencies" } = item;
138
- const relName=Array.isArray(name)?name.join("."):name;
138
+ const relName = Array.isArray(name) ? name.join(".") : name;
139
139
  const {
140
140
  fnKey,
141
141
  dependencies: dispatchDependencies = dependencies as string | string[],
@@ -151,7 +151,7 @@ const dispatchProvider = (
151
151
  };
152
152
  dispatchDependencies.forEach((key) => {
153
153
  const itemDispatch = itemDispatchProvider(
154
- relName,
154
+ relName,
155
155
  { dependencies: key, fnKey, manual, reset },
156
156
  dispatchSourceData
157
157
  );
@@ -163,7 +163,7 @@ const dispatchProvider = (
163
163
  return allDispatch;
164
164
  }
165
165
  const itemDispatch = itemDispatchProvider(
166
- relName,
166
+ relName,
167
167
  { dependencies: dispatchDependencies, fnKey, manual, reset },
168
168
  dispatchSourceData
169
169
  );
@@ -77,7 +77,6 @@ export default ({
77
77
  error={infoErr}
78
78
  data={infoData}
79
79
  reload={infoRun}
80
-
81
80
  >
82
81
  <FormContext.Provider
83
82
  value={{
@@ -36,7 +36,7 @@ import type { ColProps } from "antd/lib/grid/col";
36
36
  import type { Gutter } from "antd/lib/grid/row";
37
37
  import type { IUrlUploadProps } from "../Upload/modal";
38
38
  import { NamePath } from "rc-field-form/es/interface";
39
- import {BaseOptions} from "@ahooksjs/use-request/lib/types";
39
+ import type { BaseOptions } from "@ahooksjs/use-request/lib/types";
40
40
 
41
41
  type RenderFun = (
42
42
  props: HItemProps,
@@ -92,7 +92,7 @@ export interface HItemProps
92
92
  labelWidth?: number;
93
93
  hide?: boolean | HideModal;
94
94
  placeholder?: string | string[];
95
- name?: string|string[];
95
+ name?: string | string[];
96
96
  dispatch?: DispatchModal;
97
97
  itemSpan?: ColProps;
98
98
  hideLabel?: boolean;
@@ -100,17 +100,17 @@ export interface HItemProps
100
100
  label?: React.ReactNode | HelperModal;
101
101
  hidden?: boolean | HideModal;
102
102
  rowWrapper?: boolean;
103
- nameKey?:string;
103
+ nameKey?: string;
104
104
  }
105
- interface InfoRequestOp extends BaseOptions<any,any> {
106
- request:PromiseFnResult;
105
+ interface InfoRequestOp extends BaseOptions<any, any> {
106
+ request: PromiseFnResult;
107
107
  }
108
108
  export interface HFormProps<T = any, R = any>
109
109
  extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
110
110
  configData: HItemProps[];
111
111
  labelWidth?: number;
112
112
  request?: (values: T, params?: any) => Promise<R>;
113
- infoRequest?: PromiseFnResult|InfoRequestOp;
113
+ infoRequest?: PromiseFnResult | InfoRequestOp;
114
114
  valueType?: string;
115
115
  form?: HFormInstance;
116
116
  params?: any;
@@ -1,26 +1,26 @@
1
- import { Input, Button } from "antd";
1
+ import { Input} from "antd";
2
2
  import React from "react";
3
3
  import { useRequest } from "ahooks";
4
4
  import type { HButtonInputProps } from "./modal";
5
-
5
+ import {HJBtn} from '@hw-component/hj'
6
6
  const Index: React.FC<HButtonInputProps> = ({
7
7
  buttonProps = {},
8
8
  value,
9
9
  onChange,
10
10
  children,
11
11
  request,
12
- layType="group",
12
+ layType = "group",
13
13
  ...props
14
14
  }) => {
15
15
  const {
16
16
  onClick,
17
- type ,
17
+ type,
18
18
  ghost = true,
19
19
  loading: btnLoading,
20
20
  ...oProps
21
21
  } = buttonProps;
22
- const defaultBtnType=layType==="group"?"primary":"link"
23
- const btnType=type||defaultBtnType
22
+ const defaultBtnType = layType === "group" ? "primary" : "link";
23
+ const btnType = type || defaultBtnType;
24
24
  const { run, loading } = useRequest(
25
25
  (val) => {
26
26
  return request?.(val);
@@ -37,36 +37,38 @@ const Index: React.FC<HButtonInputProps> = ({
37
37
  }
38
38
  onClick?.(result, onChange);
39
39
  };
40
- if (layType==="text"){
41
- return <Input
42
- {...props}
43
- suffix={
44
- <Button
45
- type={btnType}
46
- onClick={click}
47
- size={"small"}
48
- loading={loading || btnLoading}
49
- ghost={ghost}
50
- {...oProps}
51
- >
52
- {children}
53
- </Button>
54
- }
55
- />
40
+ if (layType === "text") {
41
+ return (
42
+ <Input
43
+ {...props}
44
+ suffix={
45
+ <HJBtn
46
+ type={btnType}
47
+ onClick={click}
48
+ size={"small"}
49
+ loading={loading || btnLoading}
50
+ ghost={ghost}
51
+ {...oProps}
52
+ >
53
+ {children}
54
+ </HJBtn>
55
+ }
56
+ />
57
+ );
56
58
  }
57
59
  return (
58
60
  <Input.Group compact style={{ display: "flex" }}>
59
61
  <Input {...props} style={{ flex: 1 }} value={value} onChange={change} />
60
- <Button
62
+ <HJBtn
61
63
  type={btnType}
62
64
  onClick={click}
63
65
  loading={loading || btnLoading}
64
- style={{ marginLeft: 8, borderRadius: 4 }}
66
+ style={{ marginLeft: 8}}
65
67
  ghost={ghost}
66
68
  {...oProps}
67
69
  >
68
70
  {children}
69
- </Button>
71
+ </HJBtn>
70
72
  </Input.Group>
71
73
  );
72
74
  };
@@ -80,11 +80,11 @@ const InputNumberGroup = ({
80
80
  inputValue: (item, initValue) => {
81
81
  const { name: valueName = "" } = item;
82
82
  const { min: minKey, max: maxKey } = valueMap;
83
- const cuValue = initValue[(valueName as string)];
83
+ const cuValue = initValue[valueName as string];
84
84
  const minInitVal = initValue[minKey];
85
85
  const maxInitVal = initValue[maxKey];
86
86
  return {
87
- [(valueName as string)]: {
87
+ [valueName as string]: {
88
88
  [min]: minInitVal,
89
89
  [max]: maxInitVal,
90
90
  ...cuValue,
@@ -93,7 +93,7 @@ const InputNumberGroup = ({
93
93
  },
94
94
  outputValue: (item, outputValue) => {
95
95
  const { name: valueName = "" } = item;
96
- const { [(valueName as string)]: itemVal = {} } = outputValue;
96
+ const { [valueName as string]: itemVal = {} } = outputValue;
97
97
  const { min: minKey, max: maxKey } = valueMap;
98
98
  const {
99
99
  [minKey]: minSubVal,
@@ -103,7 +103,7 @@ const InputNumberGroup = ({
103
103
  return {
104
104
  [maxKey]: maxSubVal,
105
105
  [minKey]: minSubVal,
106
- [(valueName as string)]: oItemVal,
106
+ [valueName as string]: oItemVal,
107
107
  };
108
108
  },
109
109
  },
@@ -37,13 +37,14 @@ export const Index = ({
37
37
  Object.values(valueName).forEach((key) => {
38
38
  resultObj[key] = initValue[key];
39
39
  });
40
+ console.log(item, valueName);
40
41
  return {
41
- [(name as string)]: resultObj,
42
+ [name as string]: resultObj,
42
43
  };
43
44
  },
44
45
  outputValue: (item, outputValue) => {
45
46
  const { name = "" } = item;
46
- const { [(name as string)]: itemVal = {} } = outputValue;
47
+ const { [name as string]: itemVal = {} } = outputValue;
47
48
  const newItemVal = { [itemVal[select]]: itemVal[input] };
48
49
  return {
49
50
  ...newItemVal,
@@ -8,14 +8,14 @@ const Index = ({ addFormat, ...props }: HInputProps) => {
8
8
  inputValue: (item, initValue) => {
9
9
  const { name: valueName = "" } = item;
10
10
  return {
11
- [(valueName as string)]: initValue[(valueName as string)],
11
+ [valueName as string]: initValue[valueName as string],
12
12
  };
13
13
  },
14
14
  outputValue: (item, outputValue) => {
15
15
  const { name = "" } = item;
16
- const { [(name as string)]: itemVal } = outputValue;
16
+ const { [name as string]: itemVal } = outputValue;
17
17
  return {
18
- [(name as string)]: itemVal?.trim(),
18
+ [name as string]: itemVal?.trim(),
19
19
  };
20
20
  },
21
21
  },
@@ -70,4 +70,4 @@
70
70
  border-color: #ff4d4f !important;
71
71
  box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important;
72
72
  }
73
- }
73
+ }
@@ -37,5 +37,5 @@ export interface HButtonProps extends Omit<ButtonProps, "onClick"> {
37
37
  export interface HButtonInputProps extends HInputProps {
38
38
  buttonProps?: HButtonProps;
39
39
  request?: PromiseFnResult;
40
- layType?:"group"|"text";
40
+ layType?: "group" | "text";
41
41
  }
@@ -1,6 +1,7 @@
1
- import { Button, Row, Space, Typography } from "antd";
1
+ import { Row, Space, Typography } from "antd";
2
2
  import { ExclamationCircleOutlined } from "@ant-design/icons";
3
3
  import type { IHPageHandler } from "./modal";
4
+ import {HJBtn} from "@hw-component/hj";
4
5
 
5
6
  const { Text } = Typography;
6
7
  export default ({ error, reload }: IHPageHandler) => {
@@ -11,9 +12,9 @@ export default ({ error, reload }: IHPageHandler) => {
11
12
  <ExclamationCircleOutlined size={24} />
12
13
  </Text>
13
14
  <Text type={"danger"}>{error?.message}</Text>
14
- <Button type="primary" size={"small"} onClick={reload}>
15
+ <HJBtn type="primary" size={"small"} onClick={reload}>
15
16
  重新加载
16
- </Button>
17
+ </HJBtn>
17
18
  </Space>
18
19
  </Row>
19
20
  );
@@ -3,7 +3,6 @@ import Loading from "./LoadingComponent";
3
3
  import ErrorComponent from "./ErrorComponent";
4
4
  import type { IHPageHandler } from "./modal";
5
5
  const Index: React.FC<IHPageHandler> = ({ error, data, reload, children }) => {
6
-
7
6
  if (error) {
8
7
  return <ErrorComponent error={error} reload={reload} />;
9
8
  }
@@ -3,5 +3,5 @@ export interface IHPageHandler<T = any> {
3
3
  error?: Error;
4
4
  reload: VoidFunction;
5
5
  data?: T;
6
- loadingHideInData?:boolean;
6
+ loadingHideInData?: boolean;
7
7
  }
@@ -1,50 +1,66 @@
1
1
  import { TreeSelect } from "antd";
2
- import { TreeSelectProps } from "antd/lib/tree-select";
3
- import { PromiseFnResult } from "../modal";
2
+ import type { TreeSelectProps } from "antd/lib/tree-select";
3
+ import type { PromiseFnResult } from "../modal";
4
4
  import { useRequest } from "ahooks";
5
5
  export interface HTreeSelectProps extends TreeSelectProps {
6
6
  request?: PromiseFnResult;
7
- onlyCheckChild?:boolean;
7
+ onlyCheckChild?: boolean;
8
8
  }
9
9
  interface OpMkParamsModal {
10
- options?:any[];
11
- onlyCheckChild?:boolean;
12
- fieldNames?:TreeSelectProps["fieldNames"]
10
+ options?: any[];
11
+ onlyCheckChild?: boolean;
12
+ fieldNames?: TreeSelectProps["fieldNames"];
13
13
  }
14
- const opMk=({options,onlyCheckChild=false,fieldNames}:OpMkParamsModal)=>{
15
- const {children="children"}=fieldNames||{}
16
- return options?.map((item)=>{
17
- const {[children]:child}=item;
18
- const len=child?.length;
19
- if (!len){
20
- return {
21
- ...item
22
- };
23
- }
24
- const newChild=opMk({options:child,onlyCheckChild,fieldNames});
25
- return {
26
- ...item,
27
- selectable:!onlyCheckChild,
28
- [children]:newChild
29
- }
30
- })
31
- }
32
- export default ({ request,onlyCheckChild,multiple,treeCheckable,treeData,fieldNames, ...props }: HTreeSelectProps) => {
14
+ const opMk = ({
15
+ options,
16
+ onlyCheckChild = false,
17
+ fieldNames,
18
+ }: OpMkParamsModal) => {
19
+ const { children = "children" } = fieldNames || {};
20
+ return options?.map((item) => {
21
+ const { [children]: child } = item;
22
+ const len = child?.length;
23
+ if (!len) {
24
+ return {
25
+ ...item,
26
+ };
27
+ }
28
+ const newChild = opMk({ options: child, onlyCheckChild, fieldNames });
29
+ return {
30
+ ...item,
31
+ selectable: !onlyCheckChild,
32
+ [children]: newChild,
33
+ };
34
+ });
35
+ };
36
+ export default ({
37
+ request,
38
+ onlyCheckChild,
39
+ multiple,
40
+ treeCheckable,
41
+ treeData,
42
+ fieldNames,
43
+ ...props
44
+ }: HTreeSelectProps) => {
33
45
  const { loading, data } = useRequest(async () => {
34
- let options=treeData;
46
+ let options = treeData;
35
47
  if (request) {
36
- options=await request({});
48
+ options = await request({});
37
49
  }
38
50
  return opMk({
39
51
  options,
40
- onlyCheckChild:onlyCheckChild,
41
- fieldNames
52
+ onlyCheckChild: onlyCheckChild,
53
+ fieldNames,
42
54
  });
43
55
  });
44
- return <TreeSelect treeData={data}
45
- loading={loading}
46
- fieldNames={fieldNames}
47
- treeCheckable={treeCheckable}
48
- multiple={multiple}
49
- {...props}/>;
56
+ return (
57
+ <TreeSelect
58
+ treeData={data}
59
+ loading={loading}
60
+ fieldNames={fieldNames}
61
+ treeCheckable={treeCheckable}
62
+ multiple={multiple}
63
+ {...props}
64
+ />
65
+ );
50
66
  };
@@ -1,5 +1,6 @@
1
- import { Empty, Row, Space, Typography, Button } from "antd";
1
+ import { Empty, Row, Space, Typography } from "antd";
2
2
  import { ExclamationCircleOutlined } from "@ant-design/icons";
3
+ import {HJBtn} from "@hw-component/hj";
3
4
  const { Text } = Typography;
4
5
  interface IProps {
5
6
  error?: Error;
@@ -14,9 +15,9 @@ export default ({ error, reload }: IProps) => {
14
15
  <ExclamationCircleOutlined size={24} />
15
16
  </Text>
16
17
  <Text type={"danger"}>{error.message}</Text>
17
- <Button type="primary" size={"small"} onClick={reload}>
18
+ <HJBtn type="primary" size={"small"} onClick={reload}>
18
19
  重新加载
19
- </Button>
20
+ </HJBtn>
20
21
  </Space>
21
22
  </Row>
22
23
  );