bug修复
This commit is contained in:
parent
add4c8e032
commit
7d4b929fc4
|
|
@ -111,7 +111,7 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
fileList: {
|
fileList: {
|
||||||
handler(newVal) {
|
handler(newVal) {
|
||||||
|
|
||||||
if (this.files.length === 0 && newVal.length > 0) {
|
if (this.files.length === 0 && newVal.length > 0) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (this.$refs.upload) {
|
if (this.$refs.upload) {
|
||||||
|
|
@ -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) {
|
||||||
|
|
||||||
|
// 触发删除事件
|
||||||
|
this.$emit('del-file', { ...fileList[0], response: fileList[0].res })
|
||||||
|
// 清空文件列表
|
||||||
|
this.files = [];
|
||||||
|
|
||||||
if (remainingSlots > 0) {
|
// 更新 el-upload 的文件列表
|
||||||
const filesToAdd = filesArray.slice(0, remainingSlots);
|
this.$nextTick(() => {
|
||||||
filesToAdd.forEach(file => {
|
if (this.$refs.upload) {
|
||||||
const newFileObj = this.createFileObject(file);
|
this.$refs.upload.uploadFiles = [];
|
||||||
this.files.push(newFileObj);
|
}
|
||||||
|
|
||||||
if (this.autoUpload) {
|
// 添加新文件(只取第一个)
|
||||||
this.$nextTick(() => {
|
if (filesArray.length > 0) {
|
||||||
this.uploadFile(newFileObj);
|
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
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ export default {
|
||||||
this.$refs.basicInfo.validate(),
|
this.$refs.basicInfo.validate(),
|
||||||
this.$refs.fileInfo.validate()
|
this.$refs.fileInfo.validate()
|
||||||
])
|
])
|
||||||
|
|
||||||
// 所有校验通过,组装完整数据
|
// 所有校验通过,组装完整数据
|
||||||
let formData = {
|
let formData = {
|
||||||
...basicInfoData,
|
...basicInfoData,
|
||||||
|
|
|
||||||
|
|
@ -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: []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue