文件上传修改

This commit is contained in:
cwchen 2025-10-27 17:25:48 +08:00
parent 5fa91a7240
commit fb2e787a47
1 changed files with 5 additions and 36 deletions

View File

@ -85,14 +85,12 @@ export default {
previewFileType: '',
isUploading: false, //
defaultFileSize: 1024 * 1024 * 5, // 5MB 5MB
fileValidationMap: new Map(), //
}
},
methods: {
beforeUpload(file) {
//
if (this.isUploading) {
this.fileValidationMap.set(file.uid, false);
return false;
}
@ -105,23 +103,16 @@ export default {
//
const isLtMaxSize = file.size / 1024 / 1024 < this.maxSizeMB;
let isValid = true;
if (!isAllowedType || !isAllowedMimeType) {
this.$message.error(`只能上传 ${this.uploadType} 格式的文件!`);
isValid = false;
return false;
}
if (!isLtMaxSize) {
this.$message.error(`文件大小不能超过 ${this.maxFileTips}!`);
isValid = false;
return false;
}
//
this.fileValidationMap.set(file.uid, isValid);
// false
return false;
},
//
@ -131,20 +122,7 @@ export default {
return;
}
//
const isValid = this.fileValidationMap.get(file.uid);
if (isValid === false) {
//
const fileIndex = fileList.findIndex(item => item.uid === file.uid);
if (fileIndex !== -1) {
fileList.splice(fileIndex, 1);
}
this.fileValidationMap.delete(file.uid);
this.files = this.formatFileList(fileList);
return;
}
//
// 使使 fileList files
this.files = this.formatFileList(fileList);
//
@ -162,7 +140,7 @@ export default {
}
//
if (this.autoUpload && file.status === 'ready' && !this.isUploading && isValid !== false) {
if (this.autoUpload && file.status === 'ready' && !this.isUploading) {
if (this.fileUploadRule.fields_json) {
// ocr
this.uploadFile(file, '识别中');
@ -171,9 +149,6 @@ export default {
this.uploadFile(file, '上传中');
}
}
//
this.fileValidationMap.delete(file.uid);
},
//
@ -360,13 +335,7 @@ export default {
//
const newFile = files[0];
//
const isValid = this.beforeUpload(newFile);
if (!isValid) {
return;
}
this.beforeUpload(newFile); //
// percentage
const newFileObj = {