@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.
- package/.eslintcache +1 -1
- package/es/DialogForm/hooks.d.ts +5 -5
- package/es/Form/config.js +1 -1
- package/es/Form/hooks/useHForm.js +3 -0
- package/es/Form/modal.d.ts +1 -0
- package/es/Upload/UrlUpload/hooks.d.ts +1 -1
- package/es/Upload/hooks/change.d.ts +1 -1
- package/es/Upload/index.js +13 -10
- package/es/index.css +3 -3
- package/lib/DialogForm/hooks.d.ts +5 -5
- package/lib/Form/config.js +1 -1
- package/lib/Form/hooks/useHForm.js +3 -0
- package/lib/Form/modal.d.ts +1 -0
- package/lib/Upload/UrlUpload/hooks.d.ts +1 -1
- package/lib/Upload/hooks/change.d.ts +1 -1
- package/lib/Upload/index.js +13 -10
- package/lib/index.css +3 -3
- package/package.json +1 -1
- package/src/components/DialogForm/DrawerForm/index.tsx +1 -1
- package/src/components/DialogForm/hooks.ts +1 -1
- package/src/components/Form/FormItem/BasicItem.tsx +3 -3
- package/src/components/Form/FormItem/hooks.tsx +7 -4
- package/src/components/Form/HFormConnect.tsx +0 -1
- package/src/components/Form/Label.tsx +6 -10
- package/src/components/Form/config.ts +1 -1
- package/src/components/Form/hooks/useHForm.ts +4 -1
- package/src/components/Form/index.less +7 -7
- package/src/components/Form/modal.ts +6 -4
- package/src/components/Input/ButtonInput.tsx +7 -2
- package/src/components/Input/VerificationCodeInput/hooks.ts +32 -33
- package/src/components/Input/VerificationCodeInput/index.tsx +83 -81
- package/src/components/Select/index.tsx +2 -2
- package/src/components/Upload/UrlUpload/hooks.ts +15 -12
- package/src/components/Upload/UrlUpload/index.tsx +18 -11
- package/src/components/Upload/hooks/change.ts +7 -7
- package/src/components/Upload/hooks/propsMaker.ts +2 -2
- package/src/components/Upload/index.tsx +21 -14
- package/src/components/Upload/modal.ts +2 -2
- package/src/components/Upload/util.ts +6 -3
- package/src/pages/DrawerForm/index.tsx +27 -94
- package/src/pages/Form/index.tsx +185 -185
- package/src/pages/ModalForm/index.tsx +1 -1
- package/src/pages/Select/index.tsx +1 -1
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type {IUrlUploadProps} from "../modal";
|
|
2
|
-
import {MediaTypeEnum} from
|
|
1
|
+
import type { IUrlUploadProps } from "../modal";
|
|
2
|
+
import { MediaTypeEnum } from "../enums";
|
|
3
3
|
|
|
4
|
-
const defaultExFiles={
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export const useDefaultExFiles=({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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({
|
|
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,9 +84,13 @@ const Index = ({
|
|
|
81
84
|
setUrl("");
|
|
82
85
|
setLoad(false);
|
|
83
86
|
};
|
|
84
|
-
const upProps={exFiles:defaultExFiles
|
|
87
|
+
const upProps = { exFiles: defaultExFiles, ...props };
|
|
85
88
|
return (
|
|
86
|
-
<Space
|
|
89
|
+
<Space
|
|
90
|
+
direction={"vertical"}
|
|
91
|
+
style={{ width: "100%", ...style }}
|
|
92
|
+
size={"middle"}
|
|
93
|
+
>
|
|
87
94
|
<Input
|
|
88
95
|
placeholder={placeholder}
|
|
89
96
|
onBlur={onBlur}
|
|
@@ -93,8 +100,8 @@ const Index = ({
|
|
|
93
100
|
setUrl(e.target.value);
|
|
94
101
|
}}
|
|
95
102
|
/>
|
|
96
|
-
{inputHelper
|
|
97
|
-
<Upload {...upProps}
|
|
103
|
+
{inputHelper && <Text type={"secondary"}>{inputHelper}</Text>}
|
|
104
|
+
<Upload {...upProps} ref={ref} value={value} onChange={onChange} />
|
|
98
105
|
{load && (
|
|
99
106
|
<div style={{ display: "none" }}>
|
|
100
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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, {
|
|
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 {
|
|
@@ -65,16 +70,19 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
|
|
|
65
70
|
const initFileList = initValue[name] || [];
|
|
66
71
|
const relInitFileList =
|
|
67
72
|
typeof initFileList === "string" ? [initFileList] : initFileList;
|
|
68
|
-
const fileList = relInitFileList.map((
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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 };
|
|
78
86
|
});
|
|
79
87
|
return {
|
|
80
88
|
[name]: fileList,
|
|
@@ -92,8 +100,7 @@ const Index: React.ForwardRefRenderFunction<IUploadRefModal, IUpLoadProps> = (
|
|
|
92
100
|
},
|
|
93
101
|
},
|
|
94
102
|
});
|
|
95
|
-
const relVal=Array.isArray(value)?value:[];
|
|
96
|
-
|
|
103
|
+
const relVal = Array.isArray(value) ? value : [];
|
|
97
104
|
return (
|
|
98
105
|
<div style={contentStyle}>
|
|
99
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 = (
|
|
10
|
-
|
|
11
|
-
|
|
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: "
|
|
8
|
+
type: "radioGroup",
|
|
48
9
|
rules: [{ required: true }],
|
|
49
10
|
helper: "帮助我",
|
|
50
11
|
options: [
|
|
51
|
-
{ label: "选择1", value:
|
|
52
|
-
{ label: "选择2", value:
|
|
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:
|
|
104
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
/>
|