bug修复
This commit is contained in:
parent
add4c8e032
commit
7d4b929fc4
|
|
@ -273,24 +273,55 @@ export default {
|
|||
},
|
||||
|
||||
handleExceed(files, fileList) {
|
||||
this.$message.warning(`最多只能上传 ${this.limitUploadNum} 个文件,已自动截取前 ${this.limitUploadNum} 个文件`);
|
||||
|
||||
// 将 FileList 转换为数组
|
||||
const filesArray = Array.from(files);
|
||||
const remainingSlots = this.limitUploadNum - this.files.length;
|
||||
// 如果只允许上传一个文件,则替换现有文件
|
||||
if (this.limitUploadNum === 1) {
|
||||
|
||||
if (remainingSlots > 0) {
|
||||
const filesToAdd = filesArray.slice(0, remainingSlots);
|
||||
filesToAdd.forEach(file => {
|
||||
const newFileObj = this.createFileObject(file);
|
||||
this.files.push(newFileObj);
|
||||
// 触发删除事件
|
||||
this.$emit('del-file', { ...fileList[0], response: fileList[0].res })
|
||||
// 清空文件列表
|
||||
this.files = [];
|
||||
|
||||
if (this.autoUpload) {
|
||||
this.$nextTick(() => {
|
||||
this.uploadFile(newFileObj);
|
||||
});
|
||||
// 更新 el-upload 的文件列表
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.upload) {
|
||||
this.$refs.upload.uploadFiles = [];
|
||||
}
|
||||
|
||||
// 添加新文件(只取第一个)
|
||||
if (filesArray.length > 0) {
|
||||
const newFileObj = this.createFileObject(filesArray[0]);
|
||||
this.files.push(newFileObj);
|
||||
|
||||
if (this.autoUpload) {
|
||||
this.$nextTick(() => {
|
||||
this.uploadFile(newFileObj);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.$message.success('文件已替换');
|
||||
} else {
|
||||
// 多文件模式:保持原有逻辑
|
||||
this.$message.warning(`最多只能上传 ${this.limitUploadNum} 个文件,已自动截取前 ${this.limitUploadNum} 个文件`);
|
||||
|
||||
const remainingSlots = this.limitUploadNum - this.files.length;
|
||||
|
||||
if (remainingSlots > 0) {
|
||||
const filesToAdd = filesArray.slice(0, remainingSlots);
|
||||
filesToAdd.forEach(file => {
|
||||
const newFileObj = this.createFileObject(file);
|
||||
this.files.push(newFileObj);
|
||||
|
||||
if (this.autoUpload) {
|
||||
this.$nextTick(() => {
|
||||
this.uploadFile(newFileObj);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -392,10 +423,13 @@ export default {
|
|||
formattedFile.percentage = 100
|
||||
}
|
||||
|
||||
// 保留其他属性
|
||||
if (file.response) {
|
||||
formattedFile.response = file.response
|
||||
formattedFile.res = file.response
|
||||
}
|
||||
if (file.filePath) formattedFile.filePath = file.filePath
|
||||
if (file.statusText) formattedFile.statusText = file.statusText
|
||||
|
||||
return formattedFile
|
||||
})
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ export default {
|
|||
handler(newVal) {
|
||||
if (Object.keys(newVal).length > 0) {
|
||||
this.limitUploadNum = 1;
|
||||
this.disabled = true;
|
||||
// this.disabled = true;
|
||||
this.setFormData(newVal)
|
||||
}
|
||||
},
|
||||
|
|
@ -102,13 +102,16 @@ export default {
|
|||
},
|
||||
// 文件删除时触发
|
||||
handleDelFile(file) {
|
||||
|
||||
const delPath = file?.response?.fileRes?.filePath || file?.filePath || null;
|
||||
|
||||
if (delPath) {
|
||||
this.form.delFileList.push(delPath);
|
||||
}
|
||||
},
|
||||
setFormData() {
|
||||
const fileList = this.getFileList();
|
||||
|
||||
this.form = {
|
||||
fileList: fileList,
|
||||
delFileList: []
|
||||
|
|
|
|||
Loading…
Reference in New Issue