From ba26eff2c9aa72f99d65149ecb1332ac7ce593bd Mon Sep 17 00:00:00 2001 From: wangxueliang Date: Fri, 16 Nov 2018 10:32:11 +0800 Subject: [PATCH] fix: update remove property of upload #259 --- components/upload/Upload.jsx | 3 ++- components/upload/demo/upload-manually.md | 2 +- components/upload/index.en-US.md | 3 ++- components/upload/index.zh-CN.md | 2 +- components/upload/interface.jsx | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/upload/Upload.jsx b/components/upload/Upload.jsx index e9ca35f9c..bc154b126 100644 --- a/components/upload/Upload.jsx +++ b/components/upload/Upload.jsx @@ -124,7 +124,8 @@ export default { }) }, handleRemove (file) { - Promise.resolve(this.$emit('remove', file)).then(ret => { + const { remove } = getOptionProps(this) + Promise.resolve(typeof remove === 'function' ? remove(file) : remove).then(ret => { // Prevent removing file if (ret === false) { return diff --git a/components/upload/demo/upload-manually.md b/components/upload/demo/upload-manually.md index 7802ee312..ef6f65c4c 100644 --- a/components/upload/demo/upload-manually.md +++ b/components/upload/demo/upload-manually.md @@ -14,7 +14,7 @@ Upload files manually after `beforeUpload` returns `false`. diff --git a/components/upload/index.en-US.md b/components/upload/index.en-US.md index 6d7519c75..af6752cec 100644 --- a/components/upload/index.en-US.md +++ b/components/upload/index.en-US.md @@ -20,13 +20,14 @@ | showUploadList | Whether to show default upload list, could be an object to specify `showPreviewIcon` and `showRemoveIcon` individually | Boolean or { showPreviewIcon?: boolean, showRemoveIcon?: boolean } | true | | supportServerRender | Need to be turned on while the server side is rendering. | boolean | false | | withCredentials | ajax upload with cookie sent | boolean | false | +| remove | A callback function, will be executed when removing file button is clicked, remove event will be prevented when return value is `false` or a Promise which resolve(false) or reject. | Function(file): `boolean | Promise` | - | ### events | Events Name | Description | Arguments | | --- | --- | --- | | 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) | - | -| remove | A callback function, will be executed when removing file button is clicked, remove event will be prevented when return value is `false` or a Promise which resolve(false) or reject. | Function(file): `boolean | Promise` | - | + ### change diff --git a/components/upload/index.zh-CN.md b/components/upload/index.zh-CN.md index c016a7e54..f10efc625 100644 --- a/components/upload/index.zh-CN.md +++ b/components/upload/index.zh-CN.md @@ -20,13 +20,13 @@ | showUploadList | 是否展示 uploadList, 可设为一个对象,用于单独设定 showPreviewIcon 和 showRemoveIcon | Boolean or { showPreviewIcon?: boolean, showRemoveIcon?: boolean } | true | | supportServerRender | 服务端渲染时需要打开这个 | boolean | false | | withCredentials | 上传请求时是否携带 cookie | boolean | false | +| remove   | 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象,Promise 对象 resolve(false) 或 reject 时不移除。               | Function(file): `boolean | Promise` | 无   | ### 事件 | 事件名称 | 说明 | 回调参数 | | --- | --- | --- | | change | 上传文件改变时的状态,详见 [change](#change) | Function | 无 | | preview | 点击文件链接或预览图标时的回调 | Function(file) | 无 | -| remove   | 点击移除文件时的回调,返回值为 false 时不移除。支持返回一个 Promise 对象,Promise 对象 resolve(false) 或 reject 时不移除。               | Function(file): `boolean | Promise` | 无   | ### change diff --git a/components/upload/interface.jsx b/components/upload/interface.jsx index 29b38951b..179e3ad9f 100755 --- a/components/upload/interface.jsx +++ b/components/upload/interface.jsx @@ -69,7 +69,7 @@ export const UploadProps = { listType: PropsTypes.oneOf(['text', 'picture', 'picture-card']), // className: PropsTypes.string, // onPreview: PropsTypes.func, - // onRemove: PropsTypes.func, + remove: PropsTypes.func, supportServerRender: PropsTypes.bool, // style: PropsTypes.object, disabled: PropsTypes.bool,