diff --git a/components/upload/Upload.jsx b/components/upload/Upload.jsx index 62edc8422..ce8df496d 100644 --- a/components/upload/Upload.jsx +++ b/components/upload/Upload.jsx @@ -136,6 +136,9 @@ export default { fileList, }); }, + onReject(fileList) { + this.$emit('reject', fileList); + }, handleRemove(file) { const { remove } = getOptionProps(this); const { status } = file; @@ -232,6 +235,7 @@ export default { error: this.onError, progress: this.onProgress, success: this.onSuccess, + reject: this.onReject, }, ref: 'uploadRef', class: `${prefixCls}-btn`, diff --git a/components/upload/index.en-US.md b/components/upload/index.en-US.md index 40dc1d3df..0226dd4b2 100644 --- a/components/upload/index.en-US.md +++ b/components/upload/index.en-US.md @@ -28,6 +28,7 @@ | --- | --- | --- | | change | A callback function, can be executed when uploading state is changing. See [change](#change) | Function | - | | preview | A callback function, will be executed when file link or preview icon is clicked. | Function(file) | - | +| reject | A callback function, will be executed when drop files is not accept. | Function(fileList) | - | ### change diff --git a/components/upload/index.zh-CN.md b/components/upload/index.zh-CN.md index 30b5c7d9b..10a7f2fdf 100644 --- a/components/upload/index.zh-CN.md +++ b/components/upload/index.zh-CN.md @@ -28,6 +28,7 @@ | --- | --- | --- | | change | 上传文件改变时的状态,详见 [change](#change) | Function | 无 | | preview | 点击文件链接或预览图标时的回调 | Function(file) | 无 | +| reject | 拖拽文件不符合accept类型时的回调 | Function(fileList) | 无 | ### change diff --git a/components/vc-upload/src/AjaxUploader.jsx b/components/vc-upload/src/AjaxUploader.jsx index e9ec6adc7..bffd55d84 100644 --- a/components/vc-upload/src/AjaxUploader.jsx +++ b/components/vc-upload/src/AjaxUploader.jsx @@ -1,5 +1,6 @@ import PropTypes from '../../_util/vue-types'; import BaseMixin from '../../_util/BaseMixin'; +import partition from 'lodash/partition'; import classNames from 'classnames'; import defaultRequest from './request'; import getUid from './uid'; @@ -74,10 +75,13 @@ const AjaxUploader = { attrAccept(_file, this.accept), ); } else { - const files = Array.prototype.slice - .call(e.dataTransfer.files) - .filter(file => attrAccept(file, this.accept)); - this.uploadFiles(files); + const files = partition(Array.prototype.slice.call(e.dataTransfer.files), file => + attrAccept(file, this.accept), + ); + this.uploadFiles(files[0]); + if (files[1].length) { + this.$emit('reject', files[1]); + } } }, uploadFiles(files) {