解决文件上传 autoUpload 参数错误问题

This commit is contained in:
icssoa 2023-12-17 17:47:04 +08:00
parent 1ab8562123
commit 43fdb3034b
2 changed files with 15 additions and 19 deletions

View File

@ -174,7 +174,7 @@ function onUpload(raw: File, _: any, { next }: any) {
next(); next();
return true; return false;
} }
// //

View File

@ -294,7 +294,7 @@ async function onBeforeUpload(file: any, item?: Upload.Item) {
size: file.size, size: file.size,
name: file.name, name: file.name,
type: getType(file.name), type: getType(file.name),
progress: 0, progress: props.autoUpload ? 0 : 100, // 100%
url: "", url: "",
preload: "", preload: "",
error: "" error: ""
@ -310,24 +310,20 @@ async function onBeforeUpload(file: any, item?: Upload.Item) {
// //
emit("upload", d, file); emit("upload", d, file);
// //
if (props.autoUpload) { if (item) {
// Object.assign(item, d);
if (item) { } else {
Object.assign(item, d); if (props.multiple) {
} else { if (!isAdd.value) {
if (props.multiple) { ElMessage.warning(`最多只能上传${limit}个文件`);
if (!isAdd.value) { return false;
ElMessage.warning(`最多只能上传${limit.value}个文件`);
} else {
list.value.push(d);
}
} else { } else {
list.value = [d]; list.value.push(d);
} }
} else {
list.value = [d];
} }
return true;
} }
return true; return true;
@ -335,13 +331,13 @@ async function onBeforeUpload(file: any, item?: Upload.Item) {
// //
if (props.beforeUpload) { if (props.beforeUpload) {
const r = props.beforeUpload(file, item, { next }); let r = props.beforeUpload(file, item, { next });
if (isPromise(r)) { if (isPromise(r)) {
r.then(next).catch(() => null); r.then(next).catch(() => null);
} else { } else {
if (r) { if (r) {
next(); r = next();
} }
} }