Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #344 #345

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions components/upload/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class Upload extends Component {
const {
onChange
} = this.props
const ret = onChange(file, fileList, response)

const onUploadError = () => {
for (const index in fileList) {
if (fileList[index].fileId === file.fileId) {
Expand All @@ -182,15 +182,19 @@ export default class Upload extends Component {
}
}

if (ret === false) {
onUploadError()
} else if (ret && typeof ret.then === 'function') {
ret.then(res => {
if (res === false) {
onUploadError()
}
})
const callback = (ret) => {
if (ret === false) {
onUploadError()
} else if (ret && typeof ret.then === 'function') {
ret.then(res => {
if (res === false) {
onUploadError()
}
})
}
}

onChange(file, fileList, response, callback)
}

uploadFile (file, dataUrl = '') {
Expand Down
41 changes: 20 additions & 21 deletions docs/zh-CN/components/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,27 @@ Upload 上传

```js
constructor(props) {
super(props)
this.state={param:{id:'uid',channel:'youpin'}}
super(props)
this.state={param:{id:'uid',channel:'youpin'}}
}
render () {
const param = this.state.param
return (
<div>
<Upload
type="normal"
uploadAction= "https://easy-mock.com/mock/5c1b42e3fe5907404e6540e9/hiui/upload"
headers={{name: 'mi'}}
buttonText="上传文件"
param={param}
name={'files[]'}
onChange = {(file, fileList, response) => {
console.log('upload callback', file, fileList, response)
// if(response&&response.status !== 200) return false // 返回 false 则该文件会从列表里删除
}}
disabled={false}
/>
</div>
)
const param = this.state.param
return (
<Upload
type="normal"
uploadAction= "https://easy-mock.com/mock/5c1b42e3fe5907404e6540e9/hiui/upload"
headers={{name: 'mi'}}
buttonText="上传文件"
param={param}
name={'files[]'}
onChange = {(file, fileList, response, callback) => {
console.log('upload callback', file, fileList, response)
if(response && response.status !== 200) {
// callback(false) // callback 回调 false 则该文件会从列表里删除
}
}}
/>
)
}
```
:::
Expand Down Expand Up @@ -305,5 +304,5 @@ render () {
| defaultFileList | 带默认列表的上传 | Array[object] (object参见上面demo) | - | 无 |
| beforeUpload | 上传文件前的钩子,返回true继续上传,其他终止上传 | Function(files, fileList) | - | 一个返回true的空函数 |
| customUpload | 自定义上传,此时不会再触发onChange,所有上传逻辑转移到该函数 | Function(files) | - | - |
| onChange | 上传回调。当function返回false或者返回promise(如果promise resolve(false))则已上传的文件列表不会展示该文件 | Function(file, fileList, response) | - | - |
| onChange | 上传回调。当第四个参数回调false或者promise(如果promise resolve(false))则已上传的文件列表不会展示该文件 | Function(file, fileList, response, callback) | - | - |
| onRemove | 删除上传的文件,为false时不可删除。当function返回true或者返回promise(如果promise resolve(true))则会在前端删除文件(可参考demo:照片墙上传)| Function(file, fileList, index),boolean | - | 一个返回true的空函数,即前端删除 |