zy-react-library 1.0.85 → 1.0.87
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/FormBuilder/FormBuilder.js +4 -1
- package/hooks/useDeleteFile/index.js +24 -5
- package/hooks/useDictionary/index.js +12 -2
- package/hooks/useDownloadBlob/index.js +13 -2
- package/hooks/useDownloadFile/index.js +19 -2
- package/hooks/useGetFile/index.js +12 -2
- package/hooks/useGetUserInfo/index.js +12 -2
- package/hooks/useImportFile/index.js +12 -2
- package/hooks/useUploadFile/index.js +20 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Button, Col, Form, Row, Space, Spin } from "antd";
|
|
1
|
+
import { Button, Col, Form, Row, Space, Spin, message } from "antd";
|
|
2
2
|
import FormItemsRenderer from "./FormItemsRenderer";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -34,6 +34,9 @@ const FormBuilder = (props) => {
|
|
|
34
34
|
scrollToFirstError
|
|
35
35
|
wrapperCol={{ span: 24 - labelCol.span }}
|
|
36
36
|
initialValues={values}
|
|
37
|
+
onFinishFailed={() => {
|
|
38
|
+
message.error("请补全必填项");
|
|
39
|
+
}}
|
|
37
40
|
style={{ width: `calc(100% - ${gutter * 2}px)`, margin: `0 auto` }}
|
|
38
41
|
{...restProps}
|
|
39
42
|
>
|
|
@@ -7,13 +7,19 @@ import { useState } from "react";
|
|
|
7
7
|
function useDeleteFile(returnType = "object") {
|
|
8
8
|
// loading状态
|
|
9
9
|
const [loading, setLoading] = useState(false);
|
|
10
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
11
|
+
let requestCount = 0;
|
|
10
12
|
|
|
11
13
|
// 删除文件
|
|
12
14
|
const deleteFile = (options) => {
|
|
13
15
|
if (!options)
|
|
14
16
|
throw new Error("请传入 options");
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
// 增加请求数量并设置loading状态
|
|
19
|
+
requestCount++;
|
|
20
|
+
if (requestCount > 0) {
|
|
21
|
+
setLoading(true);
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
return new Promise((resolve, reject) => {
|
|
19
25
|
const { files = [], single = true } = options;
|
|
@@ -25,7 +31,10 @@ function useDeleteFile(returnType = "object") {
|
|
|
25
31
|
|
|
26
32
|
// 如果没有文件则直接返回
|
|
27
33
|
if (files.length === 0) {
|
|
28
|
-
|
|
34
|
+
requestCount--;
|
|
35
|
+
if (requestCount <= 0) {
|
|
36
|
+
setLoading(false);
|
|
37
|
+
}
|
|
29
38
|
resolve();
|
|
30
39
|
return;
|
|
31
40
|
}
|
|
@@ -34,7 +43,10 @@ function useDeleteFile(returnType = "object") {
|
|
|
34
43
|
if (single) {
|
|
35
44
|
const firstFile = files[0];
|
|
36
45
|
if (!firstFile.filePath) {
|
|
37
|
-
|
|
46
|
+
requestCount--;
|
|
47
|
+
if (requestCount <= 0) {
|
|
48
|
+
setLoading(false);
|
|
49
|
+
}
|
|
38
50
|
resolve();
|
|
39
51
|
return;
|
|
40
52
|
}
|
|
@@ -43,7 +55,10 @@ function useDeleteFile(returnType = "object") {
|
|
|
43
55
|
else {
|
|
44
56
|
const validFiles = files.filter(f => f.id);
|
|
45
57
|
if (validFiles.length === 0) {
|
|
46
|
-
|
|
58
|
+
requestCount--;
|
|
59
|
+
if (requestCount <= 0) {
|
|
60
|
+
setLoading(false);
|
|
61
|
+
}
|
|
47
62
|
resolve();
|
|
48
63
|
return;
|
|
49
64
|
}
|
|
@@ -63,7 +78,11 @@ function useDeleteFile(returnType = "object") {
|
|
|
63
78
|
reject(err);
|
|
64
79
|
})
|
|
65
80
|
.finally(() => {
|
|
66
|
-
|
|
81
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
82
|
+
requestCount--;
|
|
83
|
+
if (requestCount <= 0) {
|
|
84
|
+
setLoading(false);
|
|
85
|
+
}
|
|
67
86
|
});
|
|
68
87
|
});
|
|
69
88
|
};
|
|
@@ -8,13 +8,19 @@ import { DICTIONARY_APP_KEY_ENUM } from "../../enum/dictionary";
|
|
|
8
8
|
function useDictionary(returnType = "object") {
|
|
9
9
|
// loading状态
|
|
10
10
|
const [loading, setLoading] = useState(false);
|
|
11
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
+
let requestCount = 0;
|
|
11
13
|
|
|
12
14
|
// 获取数据字典
|
|
13
15
|
const getDictionary = (options) => {
|
|
14
16
|
if (!options)
|
|
15
17
|
throw new Error("请传入 options");
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
// 增加请求数量并设置loading状态
|
|
20
|
+
requestCount++;
|
|
21
|
+
if (requestCount > 0) {
|
|
22
|
+
setLoading(true);
|
|
23
|
+
}
|
|
18
24
|
|
|
19
25
|
return new Promise((resolve, reject) => {
|
|
20
26
|
const { appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT, dictValue } = options;
|
|
@@ -37,7 +43,11 @@ function useDictionary(returnType = "object") {
|
|
|
37
43
|
reject(err);
|
|
38
44
|
})
|
|
39
45
|
.finally(() => {
|
|
40
|
-
|
|
46
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
47
|
+
requestCount--;
|
|
48
|
+
if (requestCount <= 0) {
|
|
49
|
+
setLoading(false);
|
|
50
|
+
}
|
|
41
51
|
});
|
|
42
52
|
});
|
|
43
53
|
};
|
|
@@ -8,10 +8,16 @@ import { useState } from "react";
|
|
|
8
8
|
export default function useDownloadBlob(returnType = "object") {
|
|
9
9
|
// loading状态
|
|
10
10
|
const [loading, setLoading] = useState(false);
|
|
11
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
+
let requestCount = 0;
|
|
11
13
|
|
|
12
14
|
// 下载Blob流文件
|
|
13
15
|
const downloadBlob = (url, options) => {
|
|
14
|
-
|
|
16
|
+
// 增加请求数量并设置loading状态
|
|
17
|
+
requestCount++;
|
|
18
|
+
if (requestCount > 0) {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
}
|
|
15
21
|
|
|
16
22
|
return new Promise((resolve, reject) => {
|
|
17
23
|
if (!url)
|
|
@@ -27,6 +33,7 @@ export default function useDownloadBlob(returnType = "object") {
|
|
|
27
33
|
mode: "cors",
|
|
28
34
|
headers: {
|
|
29
35
|
"Content-Type": "application/json",
|
|
36
|
+
"token": window.sessionStorage["token"],
|
|
30
37
|
},
|
|
31
38
|
})
|
|
32
39
|
.then((response) => {
|
|
@@ -56,7 +63,11 @@ export default function useDownloadBlob(returnType = "object") {
|
|
|
56
63
|
reject(err);
|
|
57
64
|
})
|
|
58
65
|
.finally(() => {
|
|
59
|
-
|
|
66
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
67
|
+
requestCount--;
|
|
68
|
+
if (requestCount <= 0) {
|
|
69
|
+
setLoading(false);
|
|
70
|
+
}
|
|
60
71
|
});
|
|
61
72
|
});
|
|
62
73
|
};
|
|
@@ -8,10 +8,16 @@ import { getFileName, getFileSuffix, getFileUrl } from "../../utils";
|
|
|
8
8
|
export default function useDownloadFile(returnType = "object") {
|
|
9
9
|
// loading状态
|
|
10
10
|
const [loading, setLoading] = useState(false);
|
|
11
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
+
let requestCount = 0;
|
|
11
13
|
|
|
12
14
|
// 下载文件
|
|
13
15
|
const downloadFile = (options) => {
|
|
14
|
-
|
|
16
|
+
// 增加请求数量并设置loading状态
|
|
17
|
+
requestCount++;
|
|
18
|
+
if (requestCount > 0) {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
}
|
|
15
21
|
|
|
16
22
|
const { url, name: fileName } = options;
|
|
17
23
|
if (!url)
|
|
@@ -50,9 +56,20 @@ export default function useDownloadFile(returnType = "object") {
|
|
|
50
56
|
message.error("下载失败");
|
|
51
57
|
})
|
|
52
58
|
.finally(() => {
|
|
53
|
-
|
|
59
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
60
|
+
requestCount--;
|
|
61
|
+
if (requestCount <= 0) {
|
|
62
|
+
setLoading(false);
|
|
63
|
+
}
|
|
54
64
|
});
|
|
55
65
|
},
|
|
66
|
+
onCancel: () => {
|
|
67
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
68
|
+
requestCount--;
|
|
69
|
+
if (requestCount <= 0) {
|
|
70
|
+
setLoading(false);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
56
73
|
});
|
|
57
74
|
};
|
|
58
75
|
|
|
@@ -9,13 +9,19 @@ import { addingPrefixToFile } from "../../utils";
|
|
|
9
9
|
function useGetFile(returnType = "object") {
|
|
10
10
|
// loading状态
|
|
11
11
|
const [loading, setLoading] = useState(false);
|
|
12
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
13
|
+
let requestCount = 0;
|
|
12
14
|
|
|
13
15
|
// 获取文件
|
|
14
16
|
const getFile = (options) => {
|
|
15
17
|
if (!options)
|
|
16
18
|
throw new Error("请传入 options");
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
// 增加请求数量并设置loading状态
|
|
21
|
+
requestCount++;
|
|
22
|
+
if (requestCount > 0) {
|
|
23
|
+
setLoading(true);
|
|
24
|
+
}
|
|
19
25
|
|
|
20
26
|
return new Promise((resolve, reject) => {
|
|
21
27
|
const { eqType, eqForeignKey } = options;
|
|
@@ -43,7 +49,11 @@ function useGetFile(returnType = "object") {
|
|
|
43
49
|
reject(err);
|
|
44
50
|
})
|
|
45
51
|
.finally(() => {
|
|
46
|
-
|
|
52
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
53
|
+
requestCount--;
|
|
54
|
+
if (requestCount <= 0) {
|
|
55
|
+
setLoading(false);
|
|
56
|
+
}
|
|
47
57
|
});
|
|
48
58
|
});
|
|
49
59
|
};
|
|
@@ -7,10 +7,16 @@ import { useState } from "react";
|
|
|
7
7
|
function useGetUserInfo(returnType = "object") {
|
|
8
8
|
// loading状态
|
|
9
9
|
const [loading, setLoading] = useState(false);
|
|
10
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
11
|
+
let requestCount = 0;
|
|
10
12
|
|
|
11
13
|
// 获取用户信息
|
|
12
14
|
const getUserInfo = () => {
|
|
13
|
-
|
|
15
|
+
// 增加请求数量并设置loading状态
|
|
16
|
+
requestCount++;
|
|
17
|
+
if (requestCount > 0) {
|
|
18
|
+
setLoading(true);
|
|
19
|
+
}
|
|
14
20
|
|
|
15
21
|
return new Promise((resolve, reject) => {
|
|
16
22
|
// 发送请求
|
|
@@ -26,7 +32,11 @@ function useGetUserInfo(returnType = "object") {
|
|
|
26
32
|
reject(err);
|
|
27
33
|
})
|
|
28
34
|
.finally(() => {
|
|
29
|
-
|
|
35
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
36
|
+
requestCount--;
|
|
37
|
+
if (requestCount <= 0) {
|
|
38
|
+
setLoading(false);
|
|
39
|
+
}
|
|
30
40
|
});
|
|
31
41
|
});
|
|
32
42
|
};
|
|
@@ -7,10 +7,16 @@ import { useState } from "react";
|
|
|
7
7
|
export default function useImportFile(returnType = "object") {
|
|
8
8
|
// loading状态
|
|
9
9
|
const [loading, setLoading] = useState(false);
|
|
10
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
11
|
+
let requestCount = 0;
|
|
10
12
|
|
|
11
13
|
// 导入文件
|
|
12
14
|
const importFile = (url, options) => {
|
|
13
|
-
|
|
15
|
+
// 增加请求数量并设置loading状态
|
|
16
|
+
requestCount++;
|
|
17
|
+
if (requestCount > 0) {
|
|
18
|
+
setLoading(true);
|
|
19
|
+
}
|
|
14
20
|
|
|
15
21
|
return new Promise((resolve, reject) => {
|
|
16
22
|
if (!url)
|
|
@@ -38,7 +44,11 @@ export default function useImportFile(returnType = "object") {
|
|
|
38
44
|
reject(err);
|
|
39
45
|
})
|
|
40
46
|
.finally(() => {
|
|
41
|
-
|
|
47
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
48
|
+
requestCount--;
|
|
49
|
+
if (requestCount <= 0) {
|
|
50
|
+
setLoading(false);
|
|
51
|
+
}
|
|
42
52
|
});
|
|
43
53
|
});
|
|
44
54
|
};
|
|
@@ -8,13 +8,19 @@ import { UPLOAD_FILE_PATH_ENUM, UPLOAD_FILE_TYPE_ENUM } from "../../enum/uploadF
|
|
|
8
8
|
function useUploadFile(returnType = "object") {
|
|
9
9
|
// loading状态
|
|
10
10
|
const [loading, setLoading] = useState(false);
|
|
11
|
+
// 用于跟踪进行中的请求数量(不暴露给外部)
|
|
12
|
+
let requestCount = 0;
|
|
11
13
|
|
|
12
14
|
// 上传文件
|
|
13
15
|
const uploadFile = (options) => {
|
|
14
16
|
if (!options)
|
|
15
17
|
throw new Error("请传入 options");
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
// 增加请求数量并设置loading状态
|
|
20
|
+
requestCount++;
|
|
21
|
+
if (requestCount > 0) {
|
|
22
|
+
setLoading(true);
|
|
23
|
+
}
|
|
18
24
|
|
|
19
25
|
return new Promise((resolve, reject) => {
|
|
20
26
|
const { files = [], single = true, params } = options;
|
|
@@ -48,7 +54,10 @@ function useUploadFile(returnType = "object") {
|
|
|
48
54
|
|
|
49
55
|
// 如果没有文件则直接返回
|
|
50
56
|
if (files.length === 0) {
|
|
51
|
-
|
|
57
|
+
requestCount--;
|
|
58
|
+
if (requestCount <= 0) {
|
|
59
|
+
setLoading(false);
|
|
60
|
+
}
|
|
52
61
|
resolve(
|
|
53
62
|
single
|
|
54
63
|
? { filePath: "" }
|
|
@@ -77,7 +86,10 @@ function useUploadFile(returnType = "object") {
|
|
|
77
86
|
|
|
78
87
|
// 如果没有文件则返回老文件
|
|
79
88
|
if (filesLength === 0) {
|
|
80
|
-
|
|
89
|
+
requestCount--;
|
|
90
|
+
if (requestCount <= 0) {
|
|
91
|
+
setLoading(false);
|
|
92
|
+
}
|
|
81
93
|
resolve(
|
|
82
94
|
single
|
|
83
95
|
? { filePath: files[0].filePath }
|
|
@@ -104,7 +116,11 @@ function useUploadFile(returnType = "object") {
|
|
|
104
116
|
reject(err);
|
|
105
117
|
})
|
|
106
118
|
.finally(() => {
|
|
107
|
-
|
|
119
|
+
// 减少请求数量并在没有进行中的请求时设置loading为false
|
|
120
|
+
requestCount--;
|
|
121
|
+
if (requestCount <= 0) {
|
|
122
|
+
setLoading(false);
|
|
123
|
+
}
|
|
108
124
|
});
|
|
109
125
|
});
|
|
110
126
|
};
|