@hw-component/form 1.3.4 → 1.3.5

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 (43) hide show
  1. package/.eslintcache +1 -1
  2. package/es/DialogForm/hooks.d.ts +5 -5
  3. package/es/Form/config.js +1 -1
  4. package/es/Form/hooks/useHForm.js +3 -0
  5. package/es/Form/modal.d.ts +1 -0
  6. package/es/Upload/UrlUpload/hooks.d.ts +1 -1
  7. package/es/Upload/hooks/change.d.ts +1 -1
  8. package/es/Upload/index.js +13 -10
  9. package/es/index.css +3 -3
  10. package/lib/DialogForm/hooks.d.ts +5 -5
  11. package/lib/Form/config.js +1 -1
  12. package/lib/Form/hooks/useHForm.js +3 -0
  13. package/lib/Form/modal.d.ts +1 -0
  14. package/lib/Upload/UrlUpload/hooks.d.ts +1 -1
  15. package/lib/Upload/hooks/change.d.ts +1 -1
  16. package/lib/Upload/index.js +13 -10
  17. package/lib/index.css +3 -3
  18. package/package.json +1 -1
  19. package/src/components/DialogForm/DrawerForm/index.tsx +1 -1
  20. package/src/components/DialogForm/hooks.ts +1 -1
  21. package/src/components/Form/FormItem/BasicItem.tsx +3 -3
  22. package/src/components/Form/FormItem/hooks.tsx +7 -4
  23. package/src/components/Form/HFormConnect.tsx +0 -1
  24. package/src/components/Form/Label.tsx +6 -10
  25. package/src/components/Form/config.ts +1 -1
  26. package/src/components/Form/hooks/useHForm.ts +4 -1
  27. package/src/components/Form/index.less +7 -7
  28. package/src/components/Form/modal.ts +6 -4
  29. package/src/components/Input/ButtonInput.tsx +7 -2
  30. package/src/components/Input/VerificationCodeInput/hooks.ts +32 -33
  31. package/src/components/Input/VerificationCodeInput/index.tsx +83 -81
  32. package/src/components/Select/index.tsx +2 -2
  33. package/src/components/Upload/UrlUpload/hooks.ts +15 -12
  34. package/src/components/Upload/UrlUpload/index.tsx +18 -11
  35. package/src/components/Upload/hooks/change.ts +7 -7
  36. package/src/components/Upload/hooks/propsMaker.ts +2 -2
  37. package/src/components/Upload/index.tsx +21 -14
  38. package/src/components/Upload/modal.ts +2 -2
  39. package/src/components/Upload/util.ts +6 -3
  40. package/src/pages/DrawerForm/index.tsx +27 -94
  41. package/src/pages/Form/index.tsx +185 -185
  42. package/src/pages/ModalForm/index.tsx +1 -1
  43. package/src/pages/Select/index.tsx +1 -1
@@ -1,15 +1,15 @@
1
- import React from "react";
1
+ /// <reference types="react" />
2
2
  import type { DialogFormProps, HDialogFormInstance, ModifyPropsModal } from "./modal";
3
3
  export declare const useModifyProps: ({ visible, configData, initialValues, dialogForm, afterClose, params, title, onCancel, autoClear, }: ModifyPropsModal) => {
4
4
  modalFormData: import("../Form/modal").HItemProps[];
5
5
  modalVisible: boolean | undefined;
6
- setModalVisible: React.Dispatch<React.SetStateAction<boolean | undefined>>;
7
- setModalFormData: React.Dispatch<React.SetStateAction<import("../Form/modal").HItemProps[]>>;
6
+ setModalVisible: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
7
+ setModalFormData: import("react").Dispatch<import("react").SetStateAction<import("../Form/modal").HItemProps[]>>;
8
8
  initValue: Record<string, any> | undefined;
9
- setInitValue: React.Dispatch<React.SetStateAction<Record<string, any> | undefined>>;
9
+ setInitValue: import("react").Dispatch<import("react").SetStateAction<Record<string, any> | undefined>>;
10
10
  onAfterClose: () => void;
11
11
  formParams: any;
12
- title: string | number | boolean | {} | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactNodeArray | React.ReactPortal | null | undefined;
12
+ title: string | number | boolean | {} | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNodeArray | import("react").ReactPortal | null | undefined;
13
13
  };
14
14
  export declare const useHDialogForm: () => HDialogFormInstance<any, any>;
15
15
  export declare const useCurrentForm: (hDialogForm?: HDialogFormInstance) => HDialogFormInstance<any, any>;
@@ -25,7 +25,7 @@ var TrimInput = require('../Input/TrimInput.js');
25
25
  var TrimTextArea = require('../TextArea/TrimTextArea.js');
26
26
 
27
27
  var placeholderConfig = {
28
- inputType: ["input", "inputNumber", "selectInput", "buttonInput", "verificationCodeInput", "trimInput", 'urlUpload'],
28
+ inputType: ["input", "inputNumber", "selectInput", "buttonInput", "verificationCodeInput", "trimInput", "urlUpload"],
29
29
  selectType: ["select", "datePicker", "timePicker", "colorInput"]
30
30
  };
31
31
  var componentConfig = {
@@ -79,6 +79,9 @@ var useHForm = (function () {
79
79
  outputValue: outputValue
80
80
  };
81
81
  },
82
+ clearFormat: function clearFormat(name) {
83
+ Reflect.deleteProperty(formatSourceData, name);
84
+ },
82
85
  formatValues: function formatValues() {
83
86
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
84
87
  var formatKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "inputValue";
@@ -122,6 +122,7 @@ export interface HFormInstance extends FormInstance {
122
122
  reload: PromiseFnResult;
123
123
  clear: VoidFunction;
124
124
  resetFieldsInitValue: VoidFunction;
125
+ clearFormat: (name: string) => void;
125
126
  }
126
127
  export interface ConnectConfigModal {
127
128
  format?: Record<string, addFormatItemModal>;
@@ -1,2 +1,2 @@
1
1
  import type { IUrlUploadProps } from "../modal";
2
- export declare const useDefaultExFiles: ({ mediaType, exFiles }: IUrlUploadProps) => any;
2
+ export declare const useDefaultExFiles: ({ mediaType, exFiles, }: IUrlUploadProps) => any;
@@ -1,3 +1,3 @@
1
1
  import type { IUpLoadProps } from "../modal";
2
2
  import type { UploadChangeParam, UploadFile } from "antd/lib/upload/interface";
3
- export declare const useChange: ({ value, onChange, maxCount, request, exFiles, maxSize, thumbUrl }: IUpLoadProps) => (info: UploadChangeParam<UploadFile>) => void;
3
+ export declare const useChange: ({ value, onChange, maxCount, request, exFiles, maxSize, thumbUrl, }: IUpLoadProps) => (info: UploadChangeParam<UploadFile>) => void;
@@ -93,16 +93,19 @@ var Index = function Index(_ref, ref) {
93
93
  name = _item$name === void 0 ? "" : _item$name;
94
94
  var initFileList = initValue[name] || [];
95
95
  var relInitFileList = typeof initFileList === "string" ? [initFileList] : initFileList;
96
- var fileList = relInitFileList.map(function (url, index) {
97
- return {
98
- name: url,
99
- response: {
100
- url: url
101
- },
102
- status: "done",
103
- uid: "init-".concat(index),
104
- thumbUrl: thumbUrl || url
105
- };
96
+ var fileList = relInitFileList.map(function (itemData, index) {
97
+ if (typeof itemData === "string") {
98
+ return {
99
+ name: itemData,
100
+ response: {
101
+ itemData: itemData
102
+ },
103
+ status: "done",
104
+ uid: "init-".concat(index),
105
+ thumbUrl: thumbUrl || itemData
106
+ };
107
+ }
108
+ return _objectSpread({}, itemData);
106
109
  });
107
110
  return _defineProperty({}, name, fileList);
108
111
  },
package/lib/index.css CHANGED
@@ -32,8 +32,8 @@
32
32
  }
33
33
  .ant-hw-form-base-item-top-left .ant-hw-form-item-required {
34
34
  position: absolute;
35
- left: -10px;
36
35
  top: 0;
36
+ left: -10px;
37
37
  }
38
38
  .ant-hw-form-base-item-top-left .ant-hw-form-label-item {
39
39
  position: relative;
@@ -58,8 +58,8 @@
58
58
  }
59
59
  .ant-hw-form-base-item-left .ant-hw-form-item-required {
60
60
  position: absolute;
61
- left: -10px;
62
61
  top: 0;
62
+ left: -10px;
63
63
  }
64
64
  .ant-hw-form-base-item-left .ant-hw-form-label-item {
65
65
  position: relative;
@@ -73,12 +73,12 @@
73
73
  .ant-hw-form-item-required:before {
74
74
  display: inline-block;
75
75
  width: 10px;
76
+ margin-right: 4px;
76
77
  color: #ff4d4f;
77
78
  font-size: 14px;
78
79
  font-family: SimSun, sans-serif;
79
80
  line-height: 1;
80
81
  content: "*";
81
- margin-right: 4px;
82
82
  }
83
83
  .ant-hw-form-form-item .ant-form-item-label {
84
84
  overflow: visible;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,7 +49,7 @@ export default ({
49
49
  title,
50
50
  onCancel,
51
51
  autoClear,
52
- afterClose
52
+ afterClose,
53
53
  });
54
54
  const cancel = () => {
55
55
  onAfterClose();
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useMemo, useState } from "react";
1
+ import { useEffect, useMemo, useState } from "react";
2
2
  import useHForm from "../Form/hooks/useHForm";
3
3
  import type {
4
4
  DialogFormProps,
@@ -3,7 +3,7 @@ import { Form, Space, Col } from "antd";
3
3
  import React from "react";
4
4
  import Helper from "./Helper";
5
5
  import { useClassName } from "../../hooks";
6
- import {useFormItemLabel, useHide, usePositionClassName} from "./hooks";
6
+ import { useFormItemLabel, useHide, usePositionClassName } from "./hooks";
7
7
  import { useFormContext } from "../Context";
8
8
  import type { HItemProps } from "../modal";
9
9
  import { useDefaultRender } from "../hooks/useDefaultRender";
@@ -56,7 +56,7 @@ const Index: React.FC<HFormItemProps> = (props) => {
56
56
  const defaultComponent = useDefaultComponents();
57
57
  const formItemStyle = useFormConfigContext("formItemStyle");
58
58
  const ctxItemProps = useFormConfigContext("itemProps");
59
- const itemClassName=useClassName("hw-form-form-item")
59
+ const itemClassName = useClassName("hw-form-form-item");
60
60
  const defaultItemProps = {
61
61
  ...ctxItemProps,
62
62
  ...itemProps,
@@ -67,7 +67,7 @@ const Index: React.FC<HFormItemProps> = (props) => {
67
67
  );
68
68
  const className = usePositionClassName(align);
69
69
  const hideItem = useHide({ hide, form });
70
- const formItemLabel=useFormItemLabel(form,label);
70
+ const formItemLabel = useFormItemLabel(form, label);
71
71
  if (hideItem) {
72
72
  return null;
73
73
  }
@@ -5,7 +5,7 @@ import { useMemo } from "react";
5
5
  import type { HFormInstance, HItemProps } from "../modal";
6
6
  import type { LabelAlignModal } from "../modal";
7
7
  import { useClassName } from "../../hooks";
8
- import type {HelperModal} from "../modal";
8
+ import type { HelperModal } from "../modal";
9
9
 
10
10
  export const useFormItemDomControl = ({
11
11
  shouldUpdate,
@@ -55,6 +55,9 @@ export const usePositionClassName = (position: LabelAlignModal) => {
55
55
  return useClassName(className);
56
56
  };
57
57
 
58
- export const useFormItemLabel=(form: HFormInstance,label?: React.ReactNode|HelperModal,)=>{
59
- return typeof label==="function"?label(form):label;
60
- }
58
+ export const useFormItemLabel = (
59
+ form: HFormInstance,
60
+ label?: React.ReactNode | HelperModal
61
+ ) => {
62
+ return typeof label === "function" ? label(form) : label;
63
+ };
@@ -50,7 +50,6 @@ export default (
50
50
  useEffect(() => {
51
51
  form?.addFormat(name, formatMaker(props, format[valueType]));
52
52
  }, [valueType, props]);
53
-
54
53
  const addFormat = (aFormat: Record<string, addFormatItemModal>) => {
55
54
  form?.addFormat(name, formatMaker(props, aFormat[valueType]));
56
55
  };
@@ -27,18 +27,14 @@ const Index: React.FC<IProps> = ({
27
27
  hover,
28
28
  }) => {
29
29
  const { text, icon } = useHover({ hover });
30
- const array = [
31
- colon ? "hw-form-item-colon" : "",
32
- ];
30
+ const array = [colon ? "hw-form-item-colon" : ""];
33
31
 
34
- const className = useClassName([...array,"hw-form-label-item"]);
35
- const requiredClass=useClassName("hw-form-item-required");
36
- const noRequiredClass=useClassName("hw-form-item-no-required")
32
+ const className = useClassName([...array, "hw-form-label-item"]);
33
+ const requiredClass = useClassName("hw-form-item-required");
34
+ const noRequiredClass = useClassName("hw-form-item-no-required");
37
35
  return (
38
- <div style={{ width: labelWidth }}
39
- className={className}
40
- >
41
- <span className={required?requiredClass:noRequiredClass}/>
36
+ <div style={{ width: labelWidth }} className={className}>
37
+ <span className={required ? requiredClass : noRequiredClass} />
42
38
  {children}
43
39
  {text && (
44
40
  <span style={{ marginLeft: 4 }}>
@@ -27,7 +27,7 @@ export const placeholderConfig = {
27
27
  "buttonInput",
28
28
  "verificationCodeInput",
29
29
  "trimInput",
30
- 'urlUpload'
30
+ "urlUpload",
31
31
  ],
32
32
  selectType: ["select", "datePicker", "timePicker", "colorInput"],
33
33
  };
@@ -1,4 +1,4 @@
1
- import { useMemo } from "react";
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import { Form } from "antd";
3
3
  import type { FormatItemModal, HFormInstance } from "../modal";
4
4
  import type { argsFn } from "../modal";
@@ -61,6 +61,9 @@ export default () => {
61
61
  outputValue,
62
62
  };
63
63
  }, //注册转化方法
64
+ clearFormat(name: string) {
65
+ Reflect.deleteProperty(formatSourceData, name);
66
+ },
64
67
  formatValues(value = {}, formatKey = "inputValue") {
65
68
  const valKeys = Object.keys(value).length;
66
69
  if (!valKeys) {
@@ -19,8 +19,8 @@
19
19
  }
20
20
  .@{ant-prefix}-hw-form-item-required {
21
21
  position: absolute;
22
- left: -10px;
23
22
  top: 0;
23
+ left: -10px;
24
24
  }
25
25
  .@{ant-prefix}-hw-form-label-item {
26
26
  position: relative;
@@ -54,8 +54,8 @@
54
54
  }
55
55
  .@{ant-prefix}-hw-form-item-required {
56
56
  position: absolute;
57
- left: -10px;
58
57
  top: 0;
58
+ left: -10px;
59
59
  }
60
60
  .@{ant-prefix}-hw-form-label-item {
61
61
  position: relative;
@@ -71,15 +71,15 @@
71
71
  .@{ant-prefix}-hw-form-item-required:before {
72
72
  display: inline-block;
73
73
  width: 10px;
74
+ margin-right: 4px;
74
75
  color: #ff4d4f;
75
76
  font-size: 14px;
76
77
  font-family: SimSun, sans-serif;
77
78
  line-height: 1;
78
79
  content: "*";
79
- margin-right: 4px;
80
80
  }
81
81
  .@{ant-prefix}-hw-form-form-item {
82
- .@{ant-prefix}-form-item-label {
83
- overflow:visible
84
- }
85
- }
82
+ .@{ant-prefix}-form-item-label {
83
+ overflow: visible;
84
+ }
85
+ }
@@ -34,7 +34,7 @@ import type { ForwardedRef } from "react";
34
34
  import type { DataFnProvider } from "../modal";
35
35
  import type { ColProps } from "antd/lib/grid/col";
36
36
  import type { Gutter } from "antd/lib/grid/row";
37
- import type {IUrlUploadProps} from "../Upload/modal";
37
+ import type { IUrlUploadProps } from "../Upload/modal";
38
38
 
39
39
  type RenderFun = (
40
40
  props: HItemProps,
@@ -56,7 +56,7 @@ export type ItemPropsType =
56
56
  | TextAreaProps
57
57
  | IUpLoadProps
58
58
  | CascaderProps<any>
59
- | IUrlUploadProps
59
+ | IUrlUploadProps;
60
60
 
61
61
  export interface HoverModal {
62
62
  text?: string;
@@ -79,7 +79,8 @@ export interface DispatchModal<T = string | string[]> {
79
79
  }
80
80
  export type LabelAlignModal = "left" | "right" | "topLeft" | "topRight" | "top";
81
81
 
82
- export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"|"label"> {
82
+ export interface HItemProps
83
+ extends Omit<FormItemProps, "name" | "labelAlign" | "label"> {
83
84
  type?: string;
84
85
  itemProps?: ItemPropsType;
85
86
  render?: RenderFun;
@@ -95,7 +96,7 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"|"l
95
96
  itemSpan?: ColProps;
96
97
  hideLabel?: boolean;
97
98
  labelAlign?: LabelAlignModal;
98
- label?: React.ReactNode|HelperModal;
99
+ label?: React.ReactNode | HelperModal;
99
100
  }
100
101
  export interface HFormProps<T = any, R = any>
101
102
  extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
@@ -177,6 +178,7 @@ export interface HFormInstance extends FormInstance {
177
178
  reload: PromiseFnResult;
178
179
  clear: VoidFunction;
179
180
  resetFieldsInitValue: VoidFunction;
181
+ clearFormat: (name: string) => void;
180
182
  }
181
183
 
182
184
  export interface ConnectConfigModal {
@@ -11,7 +11,12 @@ const Index: React.FC<HButtonInputProps> = ({
11
11
  request,
12
12
  ...props
13
13
  }) => {
14
- const { onClick, type = "primary", loading:btnLoading,...oProps } = buttonProps;
14
+ const {
15
+ onClick,
16
+ type = "primary",
17
+ loading: btnLoading,
18
+ ...oProps
19
+ } = buttonProps;
15
20
  const { run, loading } = useRequest(
16
21
  (val) => {
17
22
  return request?.(val);
@@ -36,7 +41,7 @@ const Index: React.FC<HButtonInputProps> = ({
36
41
  {...oProps}
37
42
  type={type}
38
43
  onClick={click}
39
- loading={loading||btnLoading}
44
+ loading={loading || btnLoading}
40
45
  style={{ marginLeft: 4 }}
41
46
  >
42
47
  {children}
@@ -1,36 +1,35 @@
1
- import type {ButtonProps} from "./index";
2
- import {useEffect, useState} from "react";
1
+ import type { ButtonProps } from "./index";
2
+ import { useEffect, useState } from "react";
3
3
 
4
- export const useDis=(buttonProps: ButtonProps)=>{
5
- const {disabled}=buttonProps;
6
- const [btnDis,setBtnDis]=useState<boolean|undefined>(!!disabled);
7
- const [countdown, setCountdown] = useState<number>(0);
8
- const setBtnDisabled=({changedValues})=>{
9
- if (!!countdown){
10
- return setBtnDis(true);
11
- }
12
- if (typeof disabled==="function"){
13
- const resultDisabled=disabled(changedValues);
14
- return setBtnDis(resultDisabled);
15
- }
16
- return setBtnDis(disabled);
4
+ export const useDis = (buttonProps: ButtonProps) => {
5
+ const { disabled } = buttonProps;
6
+ const [btnDis, setBtnDis] = useState<boolean | undefined>(!!disabled);
7
+ const [countdown, setCountdown] = useState<number>(0);
8
+ const setBtnDisabled = ({ changedValues }) => {
9
+ if (!!countdown) {
10
+ return setBtnDis(true);
17
11
  }
18
- useEffect(() => {
19
- setBtnDis(!!countdown);
20
- }, [countdown]);
21
- useEffect(() => {
22
- if (!!countdown){
23
- return;
24
- }
25
- if (typeof disabled==="boolean"){
26
- setBtnDis(disabled);
27
- }
28
-
29
- }, [disabled]);
30
- return {
31
- disabled:btnDis,
32
- setBtnDisabled,
33
- countdown,
34
- setCountdown
12
+ if (typeof disabled === "function") {
13
+ const resultDisabled = disabled(changedValues);
14
+ return setBtnDis(resultDisabled);
15
+ }
16
+ return setBtnDis(disabled);
17
+ };
18
+ useEffect(() => {
19
+ setBtnDis(!!countdown);
20
+ }, [countdown]);
21
+ useEffect(() => {
22
+ if (!!countdown) {
23
+ return;
24
+ }
25
+ if (typeof disabled === "boolean") {
26
+ setBtnDis(disabled);
35
27
  }
36
- }
28
+ }, [disabled]);
29
+ return {
30
+ disabled: btnDis,
31
+ setBtnDisabled,
32
+ countdown,
33
+ setCountdown,
34
+ };
35
+ };
@@ -2,95 +2,97 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import ButtonInput from "../ButtonInput";
3
3
  import { useRequest } from "ahooks";
4
4
  import type { HFormInstance } from "../../Form/modal";
5
- import type {HButtonInputProps} from "../modal";
5
+ import type { HButtonInputProps } from "../modal";
6
6
  import HFormConnect from "../../Form/HFormConnect";
7
- import type {argsFn} from "../../Form/modal";
8
- import {useDis} from "./hooks";
7
+ import type { argsFn } from "../../Form/modal";
8
+ import { useDis } from "./hooks";
9
9
 
10
- type disabledFn=(data: any) => boolean;
11
- export interface ButtonProps extends Omit<HButtonInputProps["buttonProps"],"disabled">{
12
- disabled?: boolean|disabledFn;
10
+ type disabledFn = (data: any) => boolean;
11
+ export interface ButtonProps
12
+ extends Omit<HButtonInputProps["buttonProps"], "disabled"> {
13
+ disabled?: boolean | disabledFn;
13
14
  }
14
15
 
15
- export interface HVerificationCodeInputProps extends Omit<HButtonInputProps, "form"|"buttonProps"> {
16
- request?: (value: any) => Promise<any>;
17
- form?: HFormInstance;
18
- addDispatchListener?: (key: string, fn: argsFn) => void;
19
- buttonProps?: ButtonProps;
16
+ export interface HVerificationCodeInputProps
17
+ extends Omit<HButtonInputProps, "form" | "buttonProps"> {
18
+ request?: (value: any) => Promise<any>;
19
+ form?: HFormInstance;
20
+ addDispatchListener?: (key: string, fn: argsFn) => void;
21
+ buttonProps?: ButtonProps;
20
22
  }
21
- const Index= ({
22
- value,
23
- request,
24
- form,
25
- onChange,
26
- addDispatchListener,
27
- buttonProps={},
28
- ...props
29
- }: HVerificationCodeInputProps) => {
30
- const {disabled,setBtnDisabled,countdown,setCountdown}=useDis(buttonProps);
31
- const timer = useMemo<{ time: any }>(() => {
32
- return {
33
- time: undefined,
34
- };
35
- }, []);
36
- const timerControl = useCallback(() => {
37
- timer.time = setInterval(() => {
38
- setCountdown((oldVal = 0) => {
39
- const newVal = oldVal - 1;
40
- if (newVal <= 0) {
41
- clearInterval(timer.time);
42
- }
43
- return newVal;
44
- });
45
- }, 1000);
46
- }, []);
47
- const { run, loading } = useRequest(
48
- async () => {
49
- if (!request) {
50
- return Promise.resolve({});
51
- }
52
- const val = form?.getFieldsValue();
53
- const result = await request?.(val);
54
- if (result) {
55
- setCountdown(60);
56
- }
57
- timerControl();
58
- return result;
59
- },
60
- { manual: true }
61
- );
62
- useEffect(() => {
63
- return () => {
64
- clearInterval(timer.time);
65
- };
66
- }, []);
67
- const text = () => {
68
- if (!countdown) {
69
- return "获取验证码";
70
- }
71
- let countdownStr = `${countdown}`;
72
- if (countdown < 10) {
73
- countdownStr = `0${countdownStr}`;
23
+ const Index = ({
24
+ value,
25
+ request,
26
+ form,
27
+ onChange,
28
+ addDispatchListener,
29
+ buttonProps = {},
30
+ ...props
31
+ }: HVerificationCodeInputProps) => {
32
+ const { disabled, setBtnDisabled, countdown, setCountdown } =
33
+ useDis(buttonProps);
34
+ const timer = useMemo<{ time: any }>(() => {
35
+ return {
36
+ time: undefined,
37
+ };
38
+ }, []);
39
+ const timerControl = useCallback(() => {
40
+ timer.time = setInterval(() => {
41
+ setCountdown((oldVal = 0) => {
42
+ const newVal = oldVal - 1;
43
+ if (newVal <= 0) {
44
+ clearInterval(timer.time);
74
45
  }
75
- return `${countdownStr}秒后重新获取`;
46
+ return newVal;
47
+ });
48
+ }, 1000);
49
+ }, []);
50
+ const { run, loading } = useRequest(
51
+ async () => {
52
+ if (!request) {
53
+ return Promise.resolve({});
54
+ }
55
+ const val = form?.getFieldsValue();
56
+ const result = await request?.(val);
57
+ if (result) {
58
+ setCountdown(60);
59
+ }
60
+ timerControl();
61
+ return result;
62
+ },
63
+ { manual: true }
64
+ );
65
+ useEffect(() => {
66
+ return () => {
67
+ clearInterval(timer.time);
76
68
  };
77
-
78
- const defaultButtonProps={
79
- onClick: run,
80
- loading,
69
+ }, []);
70
+ const text = () => {
71
+ if (!countdown) {
72
+ return "获取验证码";
81
73
  }
82
- addDispatchListener?.("disabled",setBtnDisabled);
83
- return (
84
- <ButtonInput
85
- value={value}
86
- onChange={onChange}
87
- buttonProps={{...defaultButtonProps,...buttonProps,disabled}}
88
- {...props}
89
- >
90
- {text()}
91
- </ButtonInput>
92
- );
74
+ let countdownStr = `${countdown}`;
75
+ if (countdown < 10) {
76
+ countdownStr = `0${countdownStr}`;
77
+ }
78
+ return `${countdownStr}秒后重新获取`;
79
+ };
80
+
81
+ const defaultButtonProps = {
82
+ onClick: run,
83
+ loading,
84
+ };
85
+ addDispatchListener?.("disabled", setBtnDisabled);
86
+ return (
87
+ <ButtonInput
88
+ value={value}
89
+ onChange={onChange}
90
+ buttonProps={{ ...defaultButtonProps, ...buttonProps, disabled }}
91
+ {...props}
92
+ >
93
+ {text()}
94
+ </ButtonInput>
95
+ );
93
96
  };
94
97
 
95
98
  export default HFormConnect(Index);
96
-
@@ -105,12 +105,12 @@ const Index: React.FC<HSelectProps> = ({
105
105
  {...props}
106
106
  >
107
107
  {data?.map((item) => {
108
- const { value: optionValue, label ,...oItem} = item;
108
+ const { value: optionValue, label, ...oItem } = item;
109
109
  const result = filterProvider?.(item) || label;
110
110
  const filter = { [optionFilterProp]: result };
111
111
  return (
112
112
  <Option
113
- {...oItem}
113
+ {...oItem}
114
114
  value={optionValue}
115
115
  key={optionValue}
116
116
  label={label}