zy-react-library 1.0.47 → 1.0.49
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.
|
@@ -24,12 +24,36 @@ function useDeleteFile(returnType = "object") {
|
|
|
24
24
|
throw new Error("请传入有效的 files");
|
|
25
25
|
|
|
26
26
|
// 如果没有文件则直接返回
|
|
27
|
-
if (files.length === 0)
|
|
27
|
+
if (files.length === 0) {
|
|
28
|
+
setLoading(false);
|
|
28
29
|
resolve();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 单文件并且没有文件路径则直接返回
|
|
34
|
+
if (single) {
|
|
35
|
+
const firstFile = files[0];
|
|
36
|
+
if (!firstFile.filePath) {
|
|
37
|
+
setLoading(false);
|
|
38
|
+
resolve();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// 多文件并且没有文件id则直接返回
|
|
43
|
+
else {
|
|
44
|
+
const validFiles = files.filter(f => f.id);
|
|
45
|
+
if (validFiles.length === 0) {
|
|
46
|
+
setLoading(false);
|
|
47
|
+
resolve();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
29
51
|
|
|
30
52
|
// 发送请求
|
|
31
53
|
request(
|
|
32
|
-
single
|
|
54
|
+
single
|
|
55
|
+
? `/basic-info/imgFiles/delete?filePath=${files[0].filePath}`
|
|
56
|
+
: `/basic-info/imgFiles/ids?ids=${files.filter(f => f.id).map(f => f.id)}`,
|
|
33
57
|
"delete",
|
|
34
58
|
)
|
|
35
59
|
.then((res) => {
|
|
@@ -38,16 +38,24 @@ function useUploadFile(returnType = "object") {
|
|
|
38
38
|
throw new Error(`未找到 type ${params.type} 对应的 path `);
|
|
39
39
|
|
|
40
40
|
// 当single为false时,foreignKey是必需的
|
|
41
|
-
if (!single
|
|
42
|
-
|
|
41
|
+
if (!single) {
|
|
42
|
+
if (!params.hasOwnProperty('foreignKey'))
|
|
43
|
+
throw new Error("请传入 options.params.foreignKey");
|
|
44
|
+
// 如果 foreignKey 是 undefined,设置默认值为空字符串
|
|
45
|
+
if (params.foreignKey === undefined || params.foreignKey === null)
|
|
46
|
+
params.foreignKey = "";
|
|
47
|
+
}
|
|
43
48
|
|
|
44
49
|
// 如果没有文件则直接返回
|
|
45
|
-
if (files.length === 0)
|
|
50
|
+
if (files.length === 0) {
|
|
51
|
+
setLoading(false);
|
|
46
52
|
resolve(
|
|
47
53
|
single
|
|
48
54
|
? { filePath: '' }
|
|
49
|
-
: { id:
|
|
55
|
+
: { id: params.foreignKey },
|
|
50
56
|
);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
51
59
|
|
|
52
60
|
const formData = new FormData();
|
|
53
61
|
|