Merge pull request #666 from ariesjia/feat-1.4.0

add reject event for drag not accepted files to upload component
pull/802/head
三点包子 2019-04-10 08:44:26 +08:00 committed by GitHub
commit c483390dbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -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`,

View File

@ -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

View File

@ -28,6 +28,7 @@
| --- | --- | --- |
| change | 上传文件改变时的状态,详见 [change](#change) | Function | 无 |
| preview | 点击文件链接或预览图标时的回调 | Function(file) | 无 |
| reject | 拖拽文件不符合accept类型时的回调 | Function(fileList) | 无 |
### change

View File

@ -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) {