自定义ajax模块 (#3363)

Upload: Custom Ajax.
pull/3385/head
2017-03-09 12:24:32 +08:00 committed by Cyril Su
parent 54a29e8394
commit 126331c328
4 changed files with 15 additions and 2 deletions

View File

@ -353,6 +353,7 @@ with-credentials | whether cookies are sent | boolean | — |false
show-upload-list | whether to show the uploaded file list | boolean | — | true
type | type of Upload | string | select/drag | select
accept | accepted [file types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept), will not work when `thumbnail-mode` is `true` | string | — | —
on-ajax | Optional parameters, the file when the server sends the hook, you can use the custom sdk [oss / bos] upload to the server to return data | function(optionts) | — | —
on-preview | hook function when clicking the uploaded files | function(file) | — | —
on-remove | hook function when files are removed | function(file, fileList) | — | —
on-success | hook function when uploaded successfully | function(response, file, fileList) | — | —

View File

@ -403,6 +403,7 @@
| show-file-list | 是否显示已上传文件列表 | boolean | — | true |
| type | 上传控件类型 | string | select,drag | select |
| accept | 可选参数, 接受上传的[文件类型](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept)thumbnail-mode 模式下此参数无效)| string | — | — |
| on-ajax | 可选参数, 文件发送服务器时的钩子, 可以通过 使用自定义sdk[oss/bos] 上传到服务端返回数据 | function(optionts) | — | — |
| on-preview | 可选参数, 点击已上传的文件链接时的钩子, 可以通过 file.response 拿到服务端返回数据 | function(file) | — | — |
| on-remove | 可选参数, 文件列表移除文件时的钩子 | function(file, fileList) | — | — |
| on-success | 可选参数, 文件上传成功时的钩子 | function(response, file, fileList) | — | — |

View File

@ -48,6 +48,7 @@ export default {
type: String,
default: 'select'
},
onAjax: Function,
beforeUpload: Function,
onRemove: {
type: Function,
@ -223,6 +224,7 @@ export default {
fileList: this.uploadFiles,
autoUpload: this.autoUpload,
listType: this.listType,
'on-ajax': this.onAjax,
'on-start': this.handleStart,
'on-progress': this.handleProgress,
'on-success': this.handleSuccess,

View File

@ -27,6 +27,10 @@ export default {
onError: Function,
beforeUpload: Function,
drag: Boolean,
onAjax: {
type: Function,
default: ajax
},
onPreview: {
type: Function,
default: function() {}
@ -93,7 +97,7 @@ export default {
}
},
post(rawFile) {
ajax({
const options = {
headers: this.headers,
withCredentials: this.withCredentials,
file: rawFile,
@ -109,7 +113,12 @@ export default {
onError: err => {
this.onError(err, rawFile);
}
});
};
const ajaxPromise = this.onAjax(options);
/* global Promise:true */
if (typeof Promise !== 'undefined' && ajaxPromise instanceof Promise) {
ajaxPromise.then(options.onSuccess, options.onError);
}
},
handleClick() {
this.$refs.input.click();