bug修复

This commit is contained in:
cwchen 2025-11-19 11:06:32 +08:00
parent add4c8e032
commit 7d4b929fc4
3 changed files with 52 additions and 15 deletions

View File

@ -273,24 +273,55 @@ export default {
}, },
handleExceed(files, fileList) { handleExceed(files, fileList) {
this.$message.warning(`最多只能上传 ${this.limitUploadNum} 个文件,已自动截取前 ${this.limitUploadNum} 个文件`);
// FileList // FileList
const filesArray = Array.from(files); 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); this.$emit('del-file', { ...fileList[0], response: fileList[0].res })
filesToAdd.forEach(file => { //
const newFileObj = this.createFileObject(file); this.files = [];
this.files.push(newFileObj);
if (this.autoUpload) { // el-upload
this.$nextTick(() => { this.$nextTick(() => {
this.uploadFile(newFileObj); 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 formattedFile.percentage = 100
} }
//
if (file.response) { if (file.response) {
formattedFile.response = file.response formattedFile.response = file.response
formattedFile.res = file.response formattedFile.res = file.response
} }
if (file.filePath) formattedFile.filePath = file.filePath
if (file.statusText) formattedFile.statusText = file.statusText
return formattedFile return formattedFile
}) })

View File

@ -70,7 +70,7 @@ export default {
handler(newVal) { handler(newVal) {
if (Object.keys(newVal).length > 0) { if (Object.keys(newVal).length > 0) {
this.limitUploadNum = 1; this.limitUploadNum = 1;
this.disabled = true; // this.disabled = true;
this.setFormData(newVal) this.setFormData(newVal)
} }
}, },
@ -102,13 +102,16 @@ export default {
}, },
// //
handleDelFile(file) { handleDelFile(file) {
const delPath = file?.response?.fileRes?.filePath || file?.filePath || null; const delPath = file?.response?.fileRes?.filePath || file?.filePath || null;
if (delPath) { if (delPath) {
this.form.delFileList.push(delPath); this.form.delFileList.push(delPath);
} }
}, },
setFormData() { setFormData() {
const fileList = this.getFileList(); const fileList = this.getFileList();
this.form = { this.form = {
fileList: fileList, fileList: fileList,
delFileList: [] delFileList: []