mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 03:44:48 +00:00
fix(uploader): automatically filter files exceeding the max-size (#6150)
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user