zy-react-library 1.0.39 → 1.0.40
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/components/LeftTree/Department/Gwj/index.d.ts +1 -1
- package/hooks/useDeleteFile/index.js +7 -1
- package/hooks/useGetFile/index.d.ts +0 -1
- package/hooks/useGetFile/index.js +1 -1
- package/hooks/useUploadFile/index.d.ts +7 -4
- package/hooks/useUploadFile/index.js +11 -1
- package/package.json +1 -1
|
@@ -16,10 +16,16 @@ function useDeleteFile(returnType = "object") {
|
|
|
16
16
|
setLoading(true);
|
|
17
17
|
|
|
18
18
|
return new Promise((resolve, reject) => {
|
|
19
|
-
const { files, single = true } = options;
|
|
19
|
+
const { files = [], single = true } = options;
|
|
20
20
|
|
|
21
21
|
if (!files)
|
|
22
22
|
throw new Error("请传入 files");
|
|
23
|
+
if (!Array.isArray(files))
|
|
24
|
+
throw new Error("请传入有效的 files");
|
|
25
|
+
|
|
26
|
+
// 如果没有文件则直接返回
|
|
27
|
+
if (files.length === 0)
|
|
28
|
+
resolve();
|
|
23
29
|
|
|
24
30
|
// 发送请求
|
|
25
31
|
request(
|
|
@@ -27,7 +27,7 @@ function useGetFile(returnType = "object") {
|
|
|
27
27
|
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(eqType))
|
|
28
28
|
throw new Error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中");
|
|
29
29
|
|
|
30
|
-
if (
|
|
30
|
+
if (eqForeignKey === undefined || eqForeignKey === null)
|
|
31
31
|
throw new Error("请传入 options.eqForeignKey");
|
|
32
32
|
|
|
33
33
|
// 发送请求
|
|
@@ -13,7 +13,6 @@ export interface BaseParams {
|
|
|
13
13
|
type: number;
|
|
14
14
|
/** 企业id */
|
|
15
15
|
corpinfoId?: string;
|
|
16
|
-
[key: string]: any;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export interface SingleParams extends BaseParams {
|
|
@@ -44,16 +43,20 @@ export interface MultipleUploadFileOptions {
|
|
|
44
43
|
params: MultipleParams;
|
|
45
44
|
}
|
|
46
45
|
|
|
46
|
+
export interface SingleFileResponse {
|
|
47
|
+
/** 文件路径 */
|
|
48
|
+
filePath: string;
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
}
|
|
51
|
+
|
|
47
52
|
export interface MultipleFileResponse {
|
|
48
|
-
/** 文件列表 */
|
|
49
|
-
files: string[];
|
|
50
53
|
/** 文件ID */
|
|
51
54
|
id: string;
|
|
52
55
|
[key: string]: any;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
export interface UploadFileFunction {
|
|
56
|
-
(options: SingleUploadFileOptions): Promise<
|
|
59
|
+
(options: SingleUploadFileOptions): Promise<SingleFileResponse>;
|
|
57
60
|
(options: MultipleUploadFileOptions): Promise<MultipleFileResponse>;
|
|
58
61
|
}
|
|
59
62
|
|
|
@@ -17,10 +17,12 @@ function useUploadFile(returnType = "object") {
|
|
|
17
17
|
setLoading(true);
|
|
18
18
|
|
|
19
19
|
return new Promise((resolve, reject) => {
|
|
20
|
-
const { files, single = true, params } = options;
|
|
20
|
+
const { files = [], single = true, params } = options;
|
|
21
21
|
|
|
22
22
|
if (!files)
|
|
23
23
|
throw new Error("请传入 files");
|
|
24
|
+
if (!Array.isArray(files))
|
|
25
|
+
throw new Error("请传入有效的 files");
|
|
24
26
|
if (!params)
|
|
25
27
|
throw new Error("请传入 options.params");
|
|
26
28
|
if (!params.type)
|
|
@@ -39,6 +41,14 @@ function useUploadFile(returnType = "object") {
|
|
|
39
41
|
if (!single && (params.foreignKey === undefined || params.foreignKey === null))
|
|
40
42
|
throw new Error("请传入 options.params.foreignKey");
|
|
41
43
|
|
|
44
|
+
// 如果没有文件则直接返回
|
|
45
|
+
if (files.length === 0)
|
|
46
|
+
resolve(
|
|
47
|
+
single
|
|
48
|
+
? { filePath: '' }
|
|
49
|
+
: { id: '' },
|
|
50
|
+
);
|
|
51
|
+
|
|
42
52
|
const formData = new FormData();
|
|
43
53
|
|
|
44
54
|
// 将文件添加到formData中
|