@hw-component/form 0.0.9-beta-v19 → 0.0.9-beta-v21

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 (116) hide show
  1. package/.eslintcache +1 -0
  2. package/.idea/hw-component-form.iml +12 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +7 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/vcs.xml +6 -0
  7. package/es/Select/modal.d.ts +1 -3
  8. package/lib/Select/modal.d.ts +1 -3
  9. package/package.json +1 -1
  10. package/public/index.html +0 -19
  11. package/scripts/rollup.config.js +0 -90
  12. package/scripts/webpack.config.js +0 -76
  13. package/src/Layout.tsx +0 -61
  14. package/src/app.tsx +0 -33
  15. package/src/components/Cascader/index.tsx +0 -31
  16. package/src/components/CheckboxGroup/CheckBox/index.tsx +0 -38
  17. package/src/components/CheckboxGroup/hooks.ts +0 -105
  18. package/src/components/CheckboxGroup/index.tsx +0 -85
  19. package/src/components/CheckboxGroup/modal.ts +0 -17
  20. package/src/components/DialogForm/DrawerForm/Footer.tsx +0 -20
  21. package/src/components/DialogForm/DrawerForm/Title.tsx +0 -12
  22. package/src/components/DialogForm/DrawerForm/index.tsx +0 -110
  23. package/src/components/DialogForm/ModalForm.tsx +0 -91
  24. package/src/components/DialogForm/hooks.ts +0 -122
  25. package/src/components/DialogForm/modal.ts +0 -44
  26. package/src/components/Form/Context/FormConfigProvider.tsx +0 -38
  27. package/src/components/Form/Context/index.tsx +0 -14
  28. package/src/components/Form/FormItem/BasicItem.tsx +0 -95
  29. package/src/components/Form/FormItem/Helper.tsx +0 -25
  30. package/src/components/Form/FormItem/RegularFormItem.tsx +0 -13
  31. package/src/components/Form/FormItem/UpFormItem.tsx +0 -21
  32. package/src/components/Form/FormItem/hooks.tsx +0 -54
  33. package/src/components/Form/FormItem/index.tsx +0 -8
  34. package/src/components/Form/HFormConnect.tsx +0 -74
  35. package/src/components/Form/InitSet.tsx +0 -10
  36. package/src/components/Form/Label.tsx +0 -50
  37. package/src/components/Form/config.ts +0 -58
  38. package/src/components/Form/hooks/index.ts +0 -114
  39. package/src/components/Form/hooks/useDefaultRender.tsx +0 -45
  40. package/src/components/Form/hooks/useHForm.ts +0 -182
  41. package/src/components/Form/hooks/useInitConfigData.tsx +0 -194
  42. package/src/components/Form/index.less +0 -54
  43. package/src/components/Form/index.tsx +0 -113
  44. package/src/components/Form/modal.ts +0 -206
  45. package/src/components/Input/ButtonInput.tsx +0 -47
  46. package/src/components/Input/ColorInput/Picker.tsx +0 -18
  47. package/src/components/Input/ColorInput/data.ts +0 -102
  48. package/src/components/Input/ColorInput/index.less +0 -10
  49. package/src/components/Input/ColorInput/index.tsx +0 -58
  50. package/src/components/Input/InputNumber.tsx +0 -5
  51. package/src/components/Input/SelectInput.tsx +0 -75
  52. package/src/components/Input/TrimInput.tsx +0 -26
  53. package/src/components/Input/VerificationCodeInput.tsx +0 -74
  54. package/src/components/Input/defaultConfig.ts +0 -8
  55. package/src/components/Input/index.tsx +0 -26
  56. package/src/components/Input/modal.ts +0 -40
  57. package/src/components/PageHandler/ErrorComponent.tsx +0 -20
  58. package/src/components/PageHandler/LoadingComponent.tsx +0 -9
  59. package/src/components/PageHandler/index.tsx +0 -14
  60. package/src/components/PageHandler/modal.ts +0 -6
  61. package/src/components/RadioGroup/index.tsx +0 -45
  62. package/src/components/Select/components/AllSelect.tsx +0 -54
  63. package/src/components/Select/components/CheckBoxOption.tsx +0 -14
  64. package/src/components/Select/components/DropdownComponent.tsx +0 -36
  65. package/src/components/Select/components/NoFindItem.tsx +0 -7
  66. package/src/components/Select/components/NotFoundContent.tsx +0 -25
  67. package/src/components/Select/defaultConfig.tsx +0 -23
  68. package/src/components/Select/hooks/changeHooks.tsx +0 -159
  69. package/src/components/Select/hooks/norHooks.ts +0 -85
  70. package/src/components/Select/index.less +0 -22
  71. package/src/components/Select/index.tsx +0 -126
  72. package/src/components/Select/modal.ts +0 -38
  73. package/src/components/Select/utils.ts +0 -18
  74. package/src/components/Submit/components.tsx +0 -57
  75. package/src/components/Submit/hooks.ts +0 -31
  76. package/src/components/Submit/index.tsx +0 -33
  77. package/src/components/Switch/index.tsx +0 -77
  78. package/src/components/TDPicker/RangePicker.tsx +0 -109
  79. package/src/components/TDPicker/TimePicker.tsx +0 -29
  80. package/src/components/TDPicker/hooks.ts +0 -150
  81. package/src/components/TDPicker/index.tsx +0 -33
  82. package/src/components/TDPicker/modal.ts +0 -48
  83. package/src/components/TextArea/TrimTextArea.tsx +0 -30
  84. package/src/components/TextArea/index.tsx +0 -8
  85. package/src/components/Upload/Btn.tsx +0 -24
  86. package/src/components/Upload/MediaTypeEle/TypeEle.tsx +0 -26
  87. package/src/components/Upload/MediaTypeEle/index.tsx +0 -34
  88. package/src/components/Upload/Preview/index.tsx +0 -14
  89. package/src/components/Upload/UrlUpload/index.tsx +0 -104
  90. package/src/components/Upload/enums.ts +0 -5
  91. package/src/components/Upload/hooks/change.ts +0 -79
  92. package/src/components/Upload/hooks/customRequest.ts +0 -87
  93. package/src/components/Upload/hooks/propsMaker.ts +0 -20
  94. package/src/components/Upload/index.tsx +0 -119
  95. package/src/components/Upload/modal.ts +0 -33
  96. package/src/components/Upload/util.ts +0 -27
  97. package/src/components/config.ts +0 -47
  98. package/src/components/hooks/index.ts +0 -53
  99. package/src/components/index.tsx +0 -37
  100. package/src/components/modal.ts +0 -20
  101. package/src/components/styles/index.less +0 -3
  102. package/src/components/styles/local.less +0 -1
  103. package/src/components/typings.d.ts +0 -11
  104. package/src/index.less +0 -20
  105. package/src/index.tsx +0 -12
  106. package/src/pages/Checkbox/index.tsx +0 -14
  107. package/src/pages/DatePicker/index.tsx +0 -33
  108. package/src/pages/DrawerForm/index.tsx +0 -145
  109. package/src/pages/Form/index.tsx +0 -172
  110. package/src/pages/Input/index.tsx +0 -30
  111. package/src/pages/ModalForm/index.tsx +0 -191
  112. package/src/pages/Radio/index.tsx +0 -18
  113. package/src/pages/Select/index.tsx +0 -63
  114. package/src/pages/Switch/index.tsx +0 -18
  115. package/src/pages/Upload/index.tsx +0 -14
  116. package/src/routes.tsx +0 -80
@@ -1,48 +0,0 @@
1
- import type { RangePickerProps } from "antd/es/date-picker";
2
- import type { SharedTimeProps } from "rc-picker/lib/panels/TimePanel";
3
- import type { Moment } from "moment";
4
- import type { DatePickerProps } from "antd";
5
- import type { TimePickerProps } from "antd";
6
- import type { DurationInputArg2 } from "moment";
7
- import type { DateRangePickerValueMapModal } from "../modal";
8
- import type { addFormatItemModal } from "@/components/Form/modal";
9
- interface DisabledDateFnModal<T = Moment | undefined> {
10
- (currentDate: Moment, value: T): boolean;
11
- }
12
-
13
- export interface HDatePickerProps
14
- extends Omit<
15
- DatePickerProps,
16
- "onChange" | "format" | "ranges" | "disabledDate"
17
- > {
18
- onChange?: (time?: Moment | string | number) => void;
19
- format?: string;
20
- showTime?: boolean | SharedTimeProps<Moment>;
21
- disabledDate?: DisabledDateFnModal;
22
- addFormat?: (config: Record<string, addFormatItemModal>) => void;
23
- }
24
- export interface HRangePickerProps
25
- extends Omit<
26
- RangePickerProps,
27
- "onChange" | "format" | "ranges" | "value" | "disabledDate"
28
- > {
29
- value?: [any, any] | Record<string, any>;
30
- onChange?: (val: any) => void;
31
- showTime?: boolean | { defaultValue?: Moment[] };
32
- format?: string;
33
- valueMap?: DateRangePickerValueMapModal;
34
- ranges?: RangePickerProps["ranges"] | boolean;
35
- addFormat?: (config: Record<string, addFormatItemModal>) => void;
36
- disabledDate?: DisabledDateFnModal<Moment[] | undefined>;
37
- }
38
-
39
- export interface HTimePickerProps
40
- extends Omit<
41
- TimePickerProps,
42
- "onChange" | "format" | "ranges" | "disabledDate"
43
- > {
44
- onChange?: (time?: Moment | string | number) => void;
45
- format?: DurationInputArg2 | string;
46
- disabledDate?: DisabledDateFnModal;
47
- addFormat?: (config: Record<string, addFormatItemModal>) => void;
48
- }
@@ -1,30 +0,0 @@
1
- import TextArea from "./index";
2
- import type { TextAreaProps } from "antd/es/input";
3
- import type { addFormatItemModal } from "../Form/modal";
4
- import HFormConnect from "../Form/HFormConnect";
5
-
6
- interface TrimTextAreaProps extends TextAreaProps {
7
- addFormat?: (config: Record<string, addFormatItemModal>) => void;
8
- }
9
- const Index = ({ addFormat, ...props }: TrimTextAreaProps) => {
10
- addFormat?.({
11
- float: {
12
- inputValue: (item, initValue) => {
13
- const { name: valueName = "" } = item;
14
- return {
15
- [valueName]: initValue[valueName],
16
- };
17
- },
18
- outputValue: (item, outputValue) => {
19
- const { name = "" } = item;
20
- const { [name]: itemVal } = outputValue;
21
- return {
22
- [name]: itemVal?.trim(),
23
- };
24
- },
25
- },
26
- });
27
- return <TextArea {...props} />;
28
- };
29
-
30
- export default HFormConnect(Index);
@@ -1,8 +0,0 @@
1
- import { Input } from "antd";
2
- import type { TextAreaProps } from "antd/es/input";
3
- export default ({
4
- autoSize = { minRows: 4, maxRows: 4 },
5
- ...props
6
- }: TextAreaProps) => {
7
- return <Input.TextArea autoSize={autoSize} {...props} />;
8
- };
@@ -1,24 +0,0 @@
1
- import { PlusOutlined, UploadOutlined } from "@ant-design/icons";
2
- import type { IUpLoadProps } from "./modal";
3
- import { useMemo } from "react";
4
- import { Button } from "antd";
5
-
6
- export default ({ value, maxCount = 1, listType }: IUpLoadProps) => {
7
- const len = value?.length || 0;
8
- const text = useMemo(() => {
9
- if (len === maxCount) {
10
- return "更新";
11
- }
12
- return "上传";
13
- }, [len, maxCount]);
14
-
15
- if (listType === "picture-card") {
16
- return (
17
- <div>
18
- <PlusOutlined />
19
- <div style={{ marginTop: 8 }}>{text}</div>
20
- </div>
21
- );
22
- }
23
- return <Button icon={<UploadOutlined />}>{text}</Button>;
24
- };
@@ -1,26 +0,0 @@
1
- import { MediaTypeEnum } from "../enums";
2
-
3
- interface TypeEleProps {
4
- mediaType?: MediaTypeEnum;
5
- url?: string;
6
- onReady?: VoidFunction;
7
- onError?: VoidFunction;
8
- }
9
- export default ({ mediaType, url, onReady, onError }: TypeEleProps) => {
10
- if (mediaType === MediaTypeEnum.video) {
11
- return (
12
- <video autoPlay width="100%" controls onPlay={onReady} onError={onError}>
13
- <source src={url} />
14
- </video>
15
- );
16
- }
17
-
18
- if (mediaType === MediaTypeEnum.audio) {
19
- return (
20
- <audio autoPlay controls onPlay={onReady} onError={onError}>
21
- <source src={url} />
22
- </audio>
23
- );
24
- }
25
- return <img src={url} width="100%" onLoad={onReady} onError={onError} />;
26
- };
@@ -1,34 +0,0 @@
1
- import { getFileExt } from "../util";
2
- import TypeEle from "./TypeEle";
3
- import { useMemo } from "react";
4
- import type { IMediaTypeEleProps } from "../modal";
5
- import { MediaTypeEnum } from "../enums";
6
-
7
- const videoType = ["MP4"];
8
- const audioType = ["MP3"];
9
-
10
- export default ({ file, onReady, onError }: IMediaTypeEleProps) => {
11
- if (!file) {
12
- return null;
13
- }
14
-
15
- const name = getFileExt(file);
16
- const mediaType = useMemo(() => {
17
- if (videoType.indexOf(name) !== -1) {
18
- return MediaTypeEnum.video;
19
- }
20
- if (audioType.indexOf(name) !== -1) {
21
- return MediaTypeEnum.audio;
22
- }
23
- return MediaTypeEnum.img;
24
- }, [name]);
25
-
26
- return (
27
- <TypeEle
28
- onError={onError}
29
- onReady={onReady}
30
- mediaType={mediaType}
31
- url={file.response.url}
32
- />
33
- );
34
- };
@@ -1,14 +0,0 @@
1
- import type { ModalProps } from "antd";
2
- import { Modal } from "antd";
3
- import MediaTypeEle from "../MediaTypeEle";
4
- import type { IMediaTypeEleProps } from "../modal";
5
-
6
- export type IPreviewProps = IMediaTypeEleProps & ModalProps;
7
-
8
- export default ({ visible, file, onCancel }: IPreviewProps) => {
9
- return (
10
- <Modal footer={null} visible={visible} title="预览" onCancel={onCancel}>
11
- <MediaTypeEle file={file} />
12
- </Modal>
13
- );
14
- };
@@ -1,104 +0,0 @@
1
- import { message, Space } from "antd";
2
- import Input from "antd/es/input/Input";
3
- import Upload from "../index";
4
- import type { IUploadRefModal, IUrlUploadProps } from "../modal";
5
- import TypeEle from "../MediaTypeEle/TypeEle";
6
- import { useRef, useState } from "react";
7
- import type { RcFile, UploadFile } from "antd/es/upload/interface";
8
-
9
- const mkSubFileList = (fileList: UploadFile[], maxCount = 1) => {
10
- const len = fileList.length;
11
- if (len > maxCount) {
12
- return fileList.slice(len - maxCount);
13
- }
14
- return fileList;
15
- };
16
-
17
- const Index = ({
18
- placeholder = "请输入文件地址",
19
- value = [],
20
- onChange,
21
- mediaType,
22
- ...props
23
- }: IUrlUploadProps) => {
24
- const { maxCount } = props;
25
- const [url, setUrl] = useState("");
26
- const [load, setLoad] = useState<boolean>(false);
27
- const ref = useRef<IUploadRefModal | null>(null);
28
- const onReady = () => {
29
- const newFileList = [...value];
30
- newFileList.push({
31
- url,
32
- uid: new Date().valueOf().toString(),
33
- name: url,
34
- fileName: url,
35
- thumbUrl: url,
36
- response: {
37
- url,
38
- },
39
- });
40
- onChange?.(mkSubFileList(newFileList, maxCount));
41
- setUrl("");
42
- setLoad(false);
43
- };
44
- const onError = () => {
45
- message.error("文件错误!");
46
- setUrl("");
47
- setLoad(false);
48
- };
49
- const onBlur = (e) => {
50
- if (e.target.value.trim() === "") {
51
- return;
52
- }
53
- setLoad(true);
54
- };
55
- const onPaste = (e) => {
56
- const files = e.clipboardData.files;
57
- if (!files.length) {
58
- return;
59
- }
60
- e.preventDefault();
61
- const newFileList = Array.from<RcFile>(files).map<UploadFile>((item) => {
62
- const { name, size, type } = item;
63
- return {
64
- name,
65
- size,
66
- status: "uploading",
67
- uid: new Date().valueOf().toString(),
68
- originFileObj: item,
69
- type,
70
- };
71
- });
72
- ref.current?.change({
73
- fileList: mkSubFileList([...value, ...newFileList], maxCount),
74
- file: newFileList[0],
75
- });
76
- setUrl("");
77
- setLoad(false);
78
- };
79
- return (
80
- <Space direction={"vertical"} style={{ width: "100%" }} size={"middle"}>
81
- <Input
82
- placeholder={placeholder}
83
- onBlur={onBlur}
84
- value={url}
85
- onPaste={onPaste}
86
- onChange={(e) => {
87
- setUrl(e.target.value);
88
- }}
89
- />
90
- <Upload {...props} ref={ref} value={value} onChange={onChange} />
91
- {load && (
92
- <div style={{ display: "none" }}>
93
- <TypeEle
94
- url={url}
95
- mediaType={mediaType}
96
- onReady={onReady}
97
- onError={onError}
98
- />
99
- </div>
100
- )}
101
- </Space>
102
- );
103
- };
104
- export default Index;
@@ -1,5 +0,0 @@
1
- export enum MediaTypeEnum {
2
- video,
3
- audio,
4
- img,
5
- }
@@ -1,79 +0,0 @@
1
- import type { IUpLoadProps } from "../modal";
2
- import type { UploadChangeParam, UploadFile } from "antd/lib/upload/interface";
3
- import { useRequest } from "ahooks";
4
- import { useCustomRequest } from "./customRequest";
5
- import { checkFileSize, checkFileType } from "../util";
6
- import { message } from "antd";
7
-
8
- const checkFile = (item: UploadFile, oldFile: UploadFile[] = []) => {
9
- return oldFile.every((oldItem) => {
10
- return item.uid !== oldItem.uid;
11
- });
12
- };
13
-
14
- const matchFile = (
15
- newFile: UploadFile[],
16
- oldFile: UploadFile[] = [],
17
- exFiles?: string[],
18
- maxSize?: number
19
- ) => {
20
- const newResultFileList: UploadFile[] = [];
21
- const addFile: UploadFile[] = [];
22
- const errList: Error[] = [];
23
- newFile.forEach((item) => {
24
- if (!checkFileSize(item, maxSize)) {
25
- return errList.push(new Error("超出限制大小!"));
26
- }
27
- if (!checkFileType(item, exFiles)) {
28
- return errList.push(new Error("文件格式错误!"));
29
- }
30
- if (checkFile(item, oldFile)) {
31
- addFile.push(item);
32
- newResultFileList.push({
33
- ...item,
34
- status: "uploading",
35
- });
36
- } else {
37
- newResultFileList.push(item);
38
- }
39
- });
40
- return {
41
- addFile,
42
- fileList: newResultFileList,
43
- errList,
44
- };
45
- }; //验证错误+新增文件
46
- export const useChange = ({
47
- value,
48
- onChange,
49
- maxCount = 1,
50
- request,
51
- exFiles,
52
- maxSize,
53
- }: IUpLoadProps) => {
54
- const customRequest = useCustomRequest({ request, onChange, value });
55
-
56
- const { run } = useRequest(
57
- async ({ fileList }: UploadChangeParam<UploadFile>) => {
58
- if (fileList.length > maxCount) {
59
- message.error("超出最多文件限制!");
60
- return;
61
- }
62
- const {
63
- addFile,
64
- fileList: newFileList,
65
- errList,
66
- } = matchFile(fileList, value, exFiles, maxSize);
67
- if (errList.length) {
68
- message.error(errList[0].message);
69
- }
70
- onChange?.(newFileList);
71
- customRequest(addFile);
72
- },
73
- { manual: true, debounceInterval: 100 }
74
- );
75
-
76
- return (info: UploadChangeParam<UploadFile>) => {
77
- run(info);
78
- };
79
- };
@@ -1,87 +0,0 @@
1
- import type { IUpLoadProps } from "../modal";
2
- import type { UploadFile } from "antd/es/upload/interface";
3
- import type { RcFile } from "antd/lib/upload";
4
- import { useEffect, useMemo } from "react";
5
- import type { UploadFileStatus } from "antd/es/upload/interface";
6
- import type { BeforeUploadFileType } from "rc-upload/lib/interface";
7
- import { message } from "antd";
8
-
9
- interface SubReqParamsModal {
10
- request?: (
11
- file: Exclude<BeforeUploadFileType, File | boolean> | RcFile
12
- ) => Promise<{ url: string }>;
13
- file: RcFile;
14
- }
15
- interface ResultModal {
16
- url: string;
17
- status: UploadFileStatus;
18
- uid?: string;
19
- }
20
- const subReq = async ({
21
- request,
22
- file,
23
- }: SubReqParamsModal): Promise<ResultModal> => {
24
- if (!request) {
25
- return {
26
- url: "",
27
- status: "done",
28
- };
29
- }
30
- try {
31
- const { url } = await request(file);
32
- return {
33
- url,
34
- status: "done",
35
- };
36
- } catch (err: any) {
37
- message.error(err.message);
38
- return {
39
- url: "",
40
- status: "error",
41
- };
42
- }
43
- };
44
- const fileListProvider = (changeFile: ResultModal, files?: UploadFile[]) => {
45
- const { status, url, uid } = changeFile;
46
- if (status === "error") {
47
- return files?.filter((item) => {
48
- return item.uid !== uid;
49
- });
50
- }
51
- return files?.map((item) => {
52
- const resultUrl = url || item.thumbUrl;
53
- if (item.uid === uid) {
54
- item.status = status;
55
- item.response = { url: resultUrl };
56
- return item;
57
- }
58
- return item;
59
- });
60
- };
61
- export const useCustomRequest = ({
62
- value,
63
- request,
64
- onChange,
65
- }: IUpLoadProps) => {
66
- const valObj = useMemo(() => {
67
- return {
68
- value,
69
- };
70
- }, []);
71
-
72
- useEffect(() => {
73
- valObj.value = value;
74
- }, [value]); //强制同步避免闭包问题
75
-
76
- const sendFile = async (file: RcFile) => {
77
- const { uid } = file;
78
- const result = await subReq({ request, file });
79
- const fileList = fileListProvider({ ...result, uid }, valObj.value);
80
- onChange?.(fileList || []);
81
- };
82
- return (fileList: UploadFile[]) => {
83
- fileList.forEach((item) => {
84
- sendFile(item as RcFile);
85
- });
86
- };
87
- };
@@ -1,20 +0,0 @@
1
- import { useFormConfigContext } from "../../Form/Context/FormConfigProvider";
2
- import type { IUpLoadProps } from "../modal";
3
-
4
- export const useProps = ({ request, exFiles, maxSize }: IUpLoadProps) => {
5
- const configUploadProps = useFormConfigContext("uploadProps");
6
- const inputProps = {
7
- request,
8
- exFiles,
9
- maxSize,
10
- };
11
- const keys = Object.keys(inputProps);
12
- const resultProps = { ...configUploadProps };
13
- keys.forEach((key) => {
14
- if (inputProps[key]) {
15
- resultProps[key] = inputProps[key];
16
- return;
17
- }
18
- });
19
- return resultProps;
20
- };
@@ -1,119 +0,0 @@
1
- import React, { useImperativeHandle, useMemo, useState } from "react";
2
- import type { IUpLoadProps, IUploadRefModal } from "./modal";
3
- import { useProps } from "./hooks/propsMaker";
4
- import type { IPreviewProps } from "./Preview";
5
- import Preview from "./Preview";
6
- import { useChange } from "./hooks/change";
7
- import { Upload } from "antd";
8
- import Btn from "./Btn";
9
- import HFormConnect from "../Form/HFormConnect";
10
-
11
- const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
12
- {
13
- value = [],
14
- onChange,
15
- listType = "picture-card",
16
- exFiles,
17
- maxCount = 1,
18
- maxRowNum = 3,
19
- onPreview,
20
- request,
21
- maxSize,
22
- addFormat,
23
- ...props
24
- },
25
- ref
26
- ) => {
27
- const matchProps = useProps({ request, exFiles, maxSize });
28
- const [previewModal, setPreviewModal] = useState<IPreviewProps>({});
29
- const change = useChange({
30
- ...matchProps,
31
- value,
32
- maxCount,
33
- onChange,
34
- });
35
- useImperativeHandle(ref, () => {
36
- return {
37
- change,
38
- };
39
- });
40
- const contentStyle = useMemo(() => {
41
- if (listType !== "picture-card") {
42
- return {};
43
- }
44
- return { width: 112 * maxRowNum, maxWidth: "100%" };
45
- }, [maxRowNum, listType]);
46
-
47
- const preview = (file) => {
48
- if (onPreview) {
49
- onPreview(file);
50
- return;
51
- }
52
- setPreviewModal({
53
- visible: true,
54
- file,
55
- });
56
- };
57
- const maxNum = maxCount === 1 ? maxCount : Number.MAX_VALUE;
58
- const { visible, file: previewFile } = previewModal;
59
- addFormat?.({
60
- float: {
61
- inputValue: (item, initValue) => {
62
- const { name = "" } = item;
63
- const initFileList = initValue[name] || [];
64
- const relInitFileList =
65
- typeof initFileList === "string" ? [initFileList] : initFileList;
66
- const fileList = relInitFileList.map((url, index) => {
67
- return {
68
- name: url,
69
- response: {
70
- url,
71
- },
72
- status: "done",
73
- uid: `init-${index}`,
74
- thumbUrl: url,
75
- };
76
- });
77
- return {
78
- [name]: fileList,
79
- };
80
- },
81
- outputValue: (item, outputValue) => {
82
- const { name: valueName = "" } = item;
83
- const { [valueName]: itemVal = [] } = outputValue;
84
- const urls = itemVal.map((fileItem) => {
85
- return fileItem.response.url;
86
- });
87
- return {
88
- [valueName]: maxCount === 1 ? urls[0] : urls,
89
- };
90
- },
91
- },
92
- });
93
- return (
94
- <div style={contentStyle}>
95
- <Upload
96
- listType={listType}
97
- maxCount={maxNum}
98
- fileList={value}
99
- onPreview={preview}
100
- onChange={change}
101
- beforeUpload={() => {
102
- return false;
103
- }}
104
- {...props}
105
- >
106
- <Btn value={value} maxCount={maxCount} listType={listType} />
107
- </Upload>
108
- <Preview
109
- visible={visible}
110
- file={previewFile}
111
- onCancel={() => {
112
- setPreviewModal({});
113
- }}
114
- />
115
- </div>
116
- );
117
- };
118
-
119
- export default HFormConnect(React.forwardRef(Index));
@@ -1,33 +0,0 @@
1
- import type { UploadProps } from "antd";
2
- import type { UploadFile } from "antd/es/upload/interface";
3
- import type { BeforeUploadFileType, RcFile } from "rc-upload/lib/interface";
4
- import type { UploadChangeParam } from "antd/lib/upload/interface";
5
- import type { MediaTypeEnum } from "@/components/Upload/enums";
6
- import type { addFormatItemModal } from "@/components/Form/modal";
7
-
8
- export interface IUpLoadProps extends Omit<UploadProps, "onChange"> {
9
- exFiles?: string[];
10
- request?: (
11
- file: Exclude<BeforeUploadFileType, File | boolean> | RcFile
12
- ) => Promise<{ url: string }>;
13
- errorType?: "alert" | "show";
14
- onChange?: (fileList: UploadFile[]) => void;
15
- value?: UploadFile[];
16
- maxRowNum?: number;
17
- maxSize?: number;
18
- addFormat?: (config: Record<string, addFormatItemModal>) => void;
19
- }
20
- export interface IMediaTypeEleProps {
21
- file?: UploadFile;
22
- onReady?: VoidFunction;
23
- onError?: VoidFunction;
24
- }
25
-
26
- export interface IUploadRefModal {
27
- change: (info: UploadChangeParam<UploadFile>) => void;
28
- }
29
-
30
- export interface IUrlUploadProps extends IUpLoadProps {
31
- placeholder?: string;
32
- mediaType?: MediaTypeEnum;
33
- }
@@ -1,27 +0,0 @@
1
- import type { UploadFile } from "antd/es/upload/interface";
2
-
3
- export const getFileExt = (file: UploadFile): string => {
4
- const { name } = file;
5
- const index = name.lastIndexOf(".");
6
- return name.substring(index + 1).toUpperCase();
7
- };
8
-
9
- export const checkFileType = (file: UploadFile, exFiles: string[] = []) => {
10
- const exName: string = getFileExt(file);
11
- return exFiles.indexOf(exName) !== -1;
12
- };
13
-
14
- export const checkFileSize = (file: UploadFile, maxSize = 0) => {
15
- const { size = 0 } = file;
16
- return size <= maxSize;
17
- };
18
-
19
- export const fileToBase64 = (file: any) => {
20
- return new Promise((resolve) => {
21
- const reader = new FileReader();
22
- reader.readAsDataURL(file?.originFileObj);
23
- reader.onload = (e) => {
24
- resolve(e.target?.result);
25
- };
26
- });
27
- };