@hw-component/form 1.3.3 → 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 (45) 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/UrlUpload/index.js +0 -1
  8. package/es/Upload/hooks/change.d.ts +1 -1
  9. package/es/Upload/index.js +13 -11
  10. package/es/index.css +3 -3
  11. package/lib/DialogForm/hooks.d.ts +5 -5
  12. package/lib/Form/config.js +1 -1
  13. package/lib/Form/hooks/useHForm.js +3 -0
  14. package/lib/Form/modal.d.ts +1 -0
  15. package/lib/Upload/UrlUpload/hooks.d.ts +1 -1
  16. package/lib/Upload/UrlUpload/index.js +0 -1
  17. package/lib/Upload/hooks/change.d.ts +1 -1
  18. package/lib/Upload/index.js +13 -11
  19. package/lib/index.css +3 -3
  20. package/package.json +1 -1
  21. package/src/components/DialogForm/DrawerForm/index.tsx +1 -1
  22. package/src/components/DialogForm/hooks.ts +1 -1
  23. package/src/components/Form/FormItem/BasicItem.tsx +3 -3
  24. package/src/components/Form/FormItem/hooks.tsx +7 -4
  25. package/src/components/Form/HFormConnect.tsx +0 -1
  26. package/src/components/Form/Label.tsx +6 -10
  27. package/src/components/Form/config.ts +1 -1
  28. package/src/components/Form/hooks/useHForm.ts +4 -1
  29. package/src/components/Form/index.less +7 -7
  30. package/src/components/Form/modal.ts +6 -4
  31. package/src/components/Input/ButtonInput.tsx +7 -2
  32. package/src/components/Input/VerificationCodeInput/hooks.ts +32 -33
  33. package/src/components/Input/VerificationCodeInput/index.tsx +83 -81
  34. package/src/components/Select/index.tsx +2 -2
  35. package/src/components/Upload/UrlUpload/hooks.ts +15 -12
  36. package/src/components/Upload/UrlUpload/index.tsx +18 -12
  37. package/src/components/Upload/hooks/change.ts +7 -7
  38. package/src/components/Upload/hooks/propsMaker.ts +2 -2
  39. package/src/components/Upload/index.tsx +21 -15
  40. package/src/components/Upload/modal.ts +2 -2
  41. package/src/components/Upload/util.ts +6 -3
  42. package/src/pages/DrawerForm/index.tsx +27 -94
  43. package/src/pages/Form/index.tsx +185 -185
  44. package/src/pages/ModalForm/index.tsx +1 -1
  45. package/src/pages/Select/index.tsx +1 -1
@@ -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}
@@ -1,13 +1,16 @@
1
- import type {IUrlUploadProps} from "../modal";
2
- import {MediaTypeEnum} from '../enums';
1
+ import type { IUrlUploadProps } from "../modal";
2
+ import { MediaTypeEnum } from "../enums";
3
3
 
4
- const defaultExFiles={
5
- [MediaTypeEnum.video]:["MP4"],
6
- [MediaTypeEnum.audio]:["MP3"],
7
- }
8
- export const useDefaultExFiles=({mediaType=MediaTypeEnum.img,exFiles}: IUrlUploadProps)=>{
9
- if (exFiles||exFiles===null){
10
- return exFiles;
11
- };
12
- return defaultExFiles[mediaType]
13
- }
4
+ const defaultExFiles = {
5
+ [MediaTypeEnum.video]: ["MP4"],
6
+ [MediaTypeEnum.audio]: ["MP3"],
7
+ };
8
+ export const useDefaultExFiles = ({
9
+ mediaType = MediaTypeEnum.img,
10
+ exFiles,
11
+ }: IUrlUploadProps) => {
12
+ if (exFiles || exFiles === null) {
13
+ return exFiles;
14
+ }
15
+ return defaultExFiles[mediaType];
16
+ };
@@ -1,12 +1,12 @@
1
- import { message, Space ,Typography} from "antd";
1
+ import { message, Space, Typography } from "antd";
2
2
  import Input from "antd/es/input/Input";
3
3
  import Upload from "../index";
4
4
  import type { IUploadRefModal, IUrlUploadProps } from "../modal";
5
5
  import TypeEle from "../MediaTypeEle/TypeEle";
6
- import { useRef, useState } from "react";
6
+ import { useEffect, useRef, useState } from "react";
7
7
  import type { RcFile, UploadFile } from "antd/es/upload/interface";
8
- import {useDefaultExFiles} from "./hooks";
9
- const {Text}=Typography;
8
+ import { useDefaultExFiles } from "./hooks";
9
+ const { Text } = Typography;
10
10
  const mkSubFileList = (fileList: UploadFile[], maxCount = 1) => {
11
11
  const len = fileList.length;
12
12
  if (len > maxCount) {
@@ -21,12 +21,15 @@ const Index = ({
21
21
  onChange,
22
22
  mediaType,
23
23
  inputHelper,
24
- style={},
24
+ style = {},
25
25
  exFiles,
26
26
  ...props
27
27
  }: IUrlUploadProps) => {
28
- const { maxCount} = props;
29
- const defaultExFiles: string[]|null=useDefaultExFiles({mediaType,exFiles});
28
+ const { maxCount } = props;
29
+ const defaultExFiles: string[] | null = useDefaultExFiles({
30
+ mediaType,
31
+ exFiles,
32
+ });
30
33
  const [url, setUrl] = useState("");
31
34
  const [load, setLoad] = useState<boolean>(false);
32
35
  const ref = useRef<IUploadRefModal | null>(null);
@@ -81,10 +84,13 @@ const Index = ({
81
84
  setUrl("");
82
85
  setLoad(false);
83
86
  };
84
- const upProps={exFiles:defaultExFiles,...props};
85
- console.log(value,"urlUpload")
87
+ const upProps = { exFiles: defaultExFiles, ...props };
86
88
  return (
87
- <Space direction={"vertical"} style={{width:"100%",...style}} size={"middle"}>
89
+ <Space
90
+ direction={"vertical"}
91
+ style={{ width: "100%", ...style }}
92
+ size={"middle"}
93
+ >
88
94
  <Input
89
95
  placeholder={placeholder}
90
96
  onBlur={onBlur}
@@ -94,8 +100,8 @@ const Index = ({
94
100
  setUrl(e.target.value);
95
101
  }}
96
102
  />
97
- {inputHelper&&<Text type={"secondary"}>{inputHelper}</Text>}
98
- <Upload {...upProps} ref={ref} value={value} onChange={onChange} />
103
+ {inputHelper && <Text type={"secondary"}>{inputHelper}</Text>}
104
+ <Upload {...upProps} ref={ref} value={value} onChange={onChange} />
99
105
  {load && (
100
106
  <div style={{ display: "none" }}>
101
107
  <TypeEle
@@ -14,7 +14,7 @@ const checkFile = (item: UploadFile, oldFile: UploadFile[] = []) => {
14
14
  const matchFile = (
15
15
  newFile: UploadFile[],
16
16
  oldFile: UploadFile[] = [],
17
- exFiles?: string[]|null,
17
+ exFiles?: string[] | null,
18
18
  maxSize?: number
19
19
  ) => {
20
20
  const newResultFileList: UploadFile[] = [];
@@ -50,7 +50,7 @@ export const useChange = ({
50
50
  request,
51
51
  exFiles,
52
52
  maxSize,
53
- thumbUrl
53
+ thumbUrl,
54
54
  }: IUpLoadProps) => {
55
55
  const customRequest = useCustomRequest({ request, onChange, value });
56
56
 
@@ -68,11 +68,11 @@ export const useChange = ({
68
68
  if (errList.length) {
69
69
  message.error(errList[0].message);
70
70
  }
71
- const changeFile=newFileList?.map((item)=>{
72
- return {
73
- thumbUrl,
74
- ...item
75
- }
71
+ const changeFile = newFileList?.map((item) => {
72
+ return {
73
+ thumbUrl,
74
+ ...item,
75
+ };
76
76
  });
77
77
  onChange?.(changeFile);
78
78
  customRequest(addFile);
@@ -15,9 +15,9 @@ export const useProps = ({ request, exFiles, maxSize }: IUpLoadProps) => {
15
15
  return;
16
16
  }
17
17
  });
18
- const defaultExFiles=exFiles===undefined?resultProps.exFiles:exFiles;
18
+ const defaultExFiles = exFiles === undefined ? resultProps.exFiles : exFiles;
19
19
  return {
20
20
  ...resultProps,
21
- exFiles:defaultExFiles
21
+ exFiles: defaultExFiles,
22
22
  };
23
23
  };
@@ -1,4 +1,9 @@
1
- import React, { useImperativeHandle, useMemo, useState } from "react";
1
+ import React, {
2
+ useEffect,
3
+ useImperativeHandle,
4
+ useMemo,
5
+ useState,
6
+ } from "react";
2
7
  import type { IUpLoadProps, IUploadRefModal } from "./modal";
3
8
  import { useProps } from "./hooks/propsMaker";
4
9
  import type { IPreviewProps } from "./Preview";
@@ -32,7 +37,7 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
32
37
  value,
33
38
  maxCount,
34
39
  onChange,
35
- thumbUrl
40
+ thumbUrl,
36
41
  });
37
42
  useImperativeHandle(ref, () => {
38
43
  return {
@@ -61,21 +66,23 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
61
66
  addFormat?.({
62
67
  float: {
63
68
  inputValue: (item, initValue) => {
64
- console.log("inputValue")
65
69
  const { name = "" } = item;
66
70
  const initFileList = initValue[name] || [];
67
71
  const relInitFileList =
68
72
  typeof initFileList === "string" ? [initFileList] : initFileList;
69
- const fileList = relInitFileList.map((url, index) => {
70
- return {
71
- name: url,
72
- response: {
73
- url,
74
- },
75
- status: "done",
76
- uid: `init-${index}`,
77
- thumbUrl: thumbUrl||url,
78
- };
73
+ const fileList = relInitFileList.map((itemData, index) => {
74
+ if (typeof itemData === "string") {
75
+ return {
76
+ name: itemData,
77
+ response: {
78
+ itemData,
79
+ },
80
+ status: "done",
81
+ uid: `init-${index}`,
82
+ thumbUrl: thumbUrl || itemData,
83
+ };
84
+ }
85
+ return { ...itemData };
79
86
  });
80
87
  return {
81
88
  [name]: fileList,
@@ -93,8 +100,7 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
93
100
  },
94
101
  },
95
102
  });
96
- const relVal=Array.isArray(value)?value:[];
97
-
103
+ const relVal = Array.isArray(value) ? value : [];
98
104
  return (
99
105
  <div style={contentStyle}>
100
106
  <Upload
@@ -7,7 +7,7 @@ import type { addFormatItemModal } from "@/components/Form/modal";
7
7
  import type React from "react";
8
8
 
9
9
  export interface IUpLoadProps extends Omit<UploadProps, "onChange"> {
10
- exFiles?: string[]|null;
10
+ exFiles?: string[] | null;
11
11
  request?: (
12
12
  file: Exclude<BeforeUploadFileType, File | boolean> | RcFile
13
13
  ) => Promise<{ url: string }>;
@@ -32,5 +32,5 @@ export interface IUploadRefModal {
32
32
  export interface IUrlUploadProps extends IUpLoadProps {
33
33
  placeholder?: string;
34
34
  mediaType?: MediaTypeEnum;
35
- inputHelper?: React.ReactNode
35
+ inputHelper?: React.ReactNode;
36
36
  }
@@ -6,9 +6,12 @@ export const getFileExt = (file: UploadFile): string => {
6
6
  return name.substring(index + 1).toUpperCase();
7
7
  };
8
8
 
9
- export const checkFileType = (file: UploadFile, exFiles: string[]|null = []) => {
10
- if (!exFiles){
11
- return true;
9
+ export const checkFileType = (
10
+ file: UploadFile,
11
+ exFiles: string[] | null = []
12
+ ) => {
13
+ if (!exFiles) {
14
+ return true;
12
15
  }
13
16
  const exName: string = getFileExt(file);
14
17
  return exFiles.indexOf(exName) !== -1;
@@ -1,107 +1,34 @@
1
1
  import { Button } from "antd";
2
2
  import { HDrawerForm, useHDialogForm } from "../../components";
3
- import {MediaTypeEnum} from "../../components/Upload/enums";
3
+ import { MediaTypeEnum } from "../../components/Upload/enums";
4
4
  const data = [
5
- {
6
- label: "输入框",
7
- name: "name",
8
- rules: [
9
- () => {
10
- return {
11
- required: true,
12
- };
13
- },
14
- ],
15
- },
16
- {
17
- label: "数字",
18
- name: "sz",
19
- type: "inputNumber",
20
- rules: [{ required: true }],
21
- },
22
- {
23
- label: "下拉输入框",
24
- name: "selectInput",
25
- type: "selectInput",
26
- rules: [{ required: true }],
27
- itemProps: {
28
- valueName: {
29
- select: "op",
30
- input: "opInput",
31
- },
32
- selectProps: {
33
- options: [{ label: "测试", value: 1 }],
34
- },
35
- },
36
- },
37
- {
38
- label: "按钮输入框",
39
- name: "buttonInput",
40
- type: "buttonInput",
41
- children: "点击",
42
- rules: [{ required: true }],
43
- },
44
5
  {
45
6
  label: "选择",
46
7
  name: "checkboxGroup",
47
- type: "checkboxGroup",
8
+ type: "radioGroup",
48
9
  rules: [{ required: true }],
49
10
  helper: "帮助我",
50
11
  options: [
51
- { label: "选择1", value: "check1" },
52
- { label: "选择2", value: "check2" },
12
+ { label: "选择1", value: 0 },
13
+ { label: "选择2", value: 1 },
53
14
  ],
54
15
  },
55
- {
56
- label: "开关",
57
- name: "switch",
58
- type: "switch",
59
- rules: [{ required: true }],
60
- },
61
- {
62
- label: "时间",
63
- name: "datePicker",
64
- type: "datePicker",
65
- hover: "时间选择",
66
- helper: "帮助我",
67
- rules: [{ required: true }],
68
- },
69
- {
70
- label: "时间段",
71
- name: "rangePicker",
72
- type: "rangePicker",
73
- helper: "帮助我",
74
- rules: [{ required: true }],
75
- itemProps: {
76
- valueMap: {
77
- start: "testStart",
78
- end: "testEnd",
79
- },
80
- },
81
- },
82
- {
83
- label: "时分秒",
84
- name: "timePicker",
85
- type: "timePicker",
86
- rules: [{ required: true }],
87
- },
88
- {
89
- label: "文件",
90
- name: "upload",
91
- type: "upload",
92
- rules: [{ required: true }],
93
- },
94
16
  {
95
17
  label: "地址文件",
96
18
  name: "urlUpload",
97
19
  type: "urlUpload",
98
20
  rules: [{ required: true }],
21
+ hide: (form) => {
22
+ const check = form.getFieldValue("checkboxGroup");
23
+ return check !== 0;
24
+ },
99
25
  itemProps: {
100
26
  style: { width: 368 },
101
- placeholder: '粘贴图片地址鼠标移出输入框自动保存',
27
+ placeholder: "粘贴图片地址鼠标移出输入框自动保存",
102
28
  maxSize: 1024 * 1024 * 10,
103
- thumbUrl:"http://gips3.baidu.com/it/u=3886271102,3123389489&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
104
- mediaType:MediaTypeEnum.video
29
+ thumbUrl:
30
+ "http://gips3.baidu.com/it/u=3886271102,3123389489&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960",
31
+ mediaType: MediaTypeEnum.video,
105
32
  },
106
33
  },
107
34
  {
@@ -125,11 +52,17 @@ export default () => {
125
52
  num++;
126
53
  modalForm.show({
127
54
  initialValues: {
128
- check1: 1,
129
- op: 1,
130
- opInput: num,
131
- upload:"fff",
132
- urlUpload:"fff"
55
+ checkboxGroup: 1,
56
+ urlUpload: [
57
+ {
58
+ name: "https://yzimage.52youzai.net/eeff9ae7fded45b7bdca95c6fc72ba3c.mp4",
59
+ response: {
60
+ url: "https://yzimage.52youzai.net/eeff9ae7fded45b7bdca95c6fc72ba3c.mp4",
61
+ },
62
+ status: "done",
63
+ uid: `init-${num}`,
64
+ },
65
+ ],
133
66
  },
134
67
  });
135
68
  }}
@@ -148,11 +81,11 @@ export default () => {
148
81
  labelWidth={88}
149
82
  labelAlign={"left"}
150
83
  dialogForm={modalForm}
151
- afterClose={()=>{
152
- console.log("afterClose")
84
+ afterClose={() => {
85
+ console.log("afterClose");
153
86
  }}
154
- contentRender={(node)=>{
155
- return <div>{node}</div>
87
+ contentRender={(node) => {
88
+ return <div>{node}</div>;
156
89
  }}
157
90
  title="测试"
158
91
  />