优化useDeleteFile
parent
41e4e1e4fd
commit
9e58106183
|
|
@ -24,12 +24,36 @@ function useDeleteFile(returnType = "object") {
|
|||
throw new Error("请传入有效的 files");
|
||||
|
||||
// 如果没有文件则直接返回
|
||||
if (files.length === 0)
|
||||
if (files.length === 0) {
|
||||
setLoading(false);
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// 单文件并且没有文件路径则直接返回
|
||||
if (single) {
|
||||
const firstFile = files[0];
|
||||
if (!firstFile.filePath) {
|
||||
setLoading(false);
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 多文件并且没有文件id则直接返回
|
||||
else {
|
||||
const validFiles = files.filter(f => f.id);
|
||||
if (validFiles.length === 0) {
|
||||
setLoading(false);
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
request(
|
||||
single ? `/basic-info/imgFiles/delete?filePath=${files[0].filePath}` : `/basic-info/imgFiles/ids?ids=${files.map(f => f.id)}`,
|
||||
single
|
||||
? `/basic-info/imgFiles/delete?filePath=${files[0].filePath}`
|
||||
: `/basic-info/imgFiles/ids?ids=${files.filter(f => f.id).map(f => f.id)}`,
|
||||
"delete",
|
||||
)
|
||||
.then((res) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue