update Upload

update Upload
This commit is contained in:
梁灏 2017-01-22 18:08:36 +08:00
parent a6ac0a7603
commit 3c2f68f215
2 changed files with 12 additions and 2 deletions

View file

@ -207,7 +207,7 @@
const _file_format = file.name.split('.').pop().toLocaleLowerCase(); const _file_format = file.name.split('.').pop().toLocaleLowerCase();
const checked = this.format.some(item => item.toLocaleLowerCase() === _file_format); const checked = this.format.some(item => item.toLocaleLowerCase() === _file_format);
if (!checked) { if (!checked) {
this.onFormatError(file); this.onFormatError(file, this.fileList);
return false; return false;
} }
} }
@ -215,7 +215,7 @@
// check maxSize // check maxSize
if (this.maxSize) { if (this.maxSize) {
if (file.size > this.maxSize * 1024) { if (file.size > this.maxSize * 1024) {
this.onExceededSize(file); this.onExceededSize(file, this.fileList);
return false; return false;
} }
} }

View file

@ -20,6 +20,7 @@
:max-size="2048" :max-size="2048"
:on-format-error="handleFormatError" :on-format-error="handleFormatError"
:on-exceeded-size="handleMaxSize" :on-exceeded-size="handleMaxSize"
:before-upload="handleBeforeUpload"
multiple multiple
type="drag" type="drag"
action="//jsonplaceholder.typicode.com/posts/" action="//jsonplaceholder.typicode.com/posts/"
@ -81,6 +82,15 @@
title: '超出文件大小限制', title: '超出文件大小限制',
desc: '文件 ' + file.name + ' 太大,不能超过 2M。' desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
}); });
},
handleBeforeUpload () {
const check = this.uploadList.length < 5;
if (!check) {
this.$Notice.warning({
title: '最多只能上传 5 张图片。'
});
}
return check;
} }
} }
} }