文件上传修改

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