fix(uploader): automatically filter files exceeding the max-size (#6150)

This commit is contained in:
fujialing
2020-04-27 21:01:35 +08:00
committed by GitHub
parent 9e7d72eff2
commit 8aced05260
6 changed files with 117 additions and 5 deletions

View File

@@ -175,15 +175,38 @@ export default createComponent({
onAfterRead(files, oversize) {
this.resetInput();
let validFiles = files;
if (oversize) {
this.$emit('oversize', files, this.getDetail());
return;
let oversizeFiles = files;
if (Array.isArray(files)) {
oversizeFiles = [];
validFiles = [];
files.forEach((item) => {
if (item.file) {
if (item.file.size > this.maxSize) {
oversizeFiles.push(item);
} else {
validFiles.push(item);
}
}
});
} else {
validFiles = null;
}
this.$emit('oversize', oversizeFiles, this.getDetail());
}
this.$emit('input', [...this.fileList, ...toArray(files)]);
const isValidFiles = Array.isArray(validFiles)
? Boolean(validFiles.length)
: Boolean(validFiles);
if (this.afterRead) {
this.afterRead(files, this.getDetail());
if (isValidFiles) {
this.$emit('input', [...this.fileList, ...toArray(validFiles)]);
if (this.afterRead) {
this.afterRead(validFiles, this.getDetail());
}
}
},