File tree Expand file tree Collapse file tree 3 files changed +35
-11
lines changed Expand file tree Collapse file tree 3 files changed +35
-11
lines changed Original file line number Diff line number Diff line change @@ -304,8 +304,8 @@ export default {
304
304
} ,
305
305
{
306
306
name : 'http-request' ,
307
- type : '(file: IFile ) => Promise<any>' ,
308
- typeAnchorName : 'IFile ' ,
307
+ type : '(file: ICustomParam ) => Promise<any>' ,
308
+ typeAnchorName : 'ICustomParam ' ,
309
309
defaultValue : '' ,
310
310
desc : {
311
311
'zh-CN' : '覆盖默认的上传行为,可以自定义上传的实现; 由于 TinyVue 官网为 Mock 上传不能执行上传' ,
@@ -1059,6 +1059,22 @@ interface IFile {
1059
1059
}
1060
1060
`
1061
1061
} ,
1062
+ {
1063
+ name : 'ICustomParam' ,
1064
+ type : 'interface' ,
1065
+ code : `
1066
+ interface ICustomParam {
1067
+ action: string
1068
+ data: IData // 上传时附带的额外参数
1069
+ file: IFile
1070
+ filename: string
1071
+ headers: object // 头部请求信息
1072
+ onError: (error: any) => void // 上传失败回调函数,自定义入参
1073
+ onProgress: (event: any) => void // 上传中回调函数
1074
+ onSuccess: (res: any) => void // 上传成功回调函数
1075
+ withCredentials: boolean // 是否支持发送 cookie 凭证信息
1076
+ }`
1077
+ } ,
1062
1078
{
1063
1079
name : 'IEncryptConfig' ,
1064
1080
type : 'interface' ,
Original file line number Diff line number Diff line change 1
1
<template >
2
- <tiny-file-upload ref =" uploadRef" :http-request =" httpRequest" :file-list =" fileList" >
2
+ <tiny-file-upload ref =" uploadRef" :http-request =" httpRequest" :file-list =" fileList" @success = " handleSuccess " >
3
3
<template #trigger >
4
4
<tiny-button >点击上传</tiny-button >
5
5
</template >
6
6
</tiny-file-upload >
7
7
</template >
8
8
9
9
<script setup>
10
- import { ref , reactive } from ' vue'
10
+ import { reactive } from ' vue'
11
11
import { TinyFileUpload , TinyButton , TinyModal } from ' @opentiny/vue'
12
12
13
13
const fileList = reactive ([])
14
- const httpRequest = ref (( files ) => {
14
+ const httpRequest = reactive (({ onSuccess, file } ) => {
15
15
return new Promise ((resolve ) => {
16
16
// 此处为用户自定义的上传服务请求
17
17
setTimeout (() => {
18
- TinyModal . message (' 上传成功' )
19
- fileList .push (files . file )
18
+ onSuccess (' 上传成功' )
19
+ this . fileList .push (file)
20
20
}, 500 )
21
21
})
22
22
})
23
+ const handleSuccess = (res ) => {
24
+ TinyModal .message (res)
25
+ }
23
26
</script >
Original file line number Diff line number Diff line change 1
1
<template >
2
- <tiny-file-upload ref =" upload" :http-request =" httpRequest" :file-list =" fileList" >
2
+ <tiny-file-upload ref =" upload" :http-request =" httpRequest" :file-list =" fileList" @success = " handleSuccess " >
3
3
<template #trigger >
4
4
<tiny-button >点击上传</tiny-button >
5
5
</template >
@@ -17,16 +17,21 @@ export default {
17
17
data () {
18
18
return {
19
19
fileList: [],
20
- httpRequest : (files ) => {
20
+ httpRequest : ({ onSuccess, file } ) => {
21
21
return new Promise ((resolve ) => {
22
22
// 此处为用户自定义的上传服务请求
23
23
setTimeout (() => {
24
- TinyModal . message (' 上传成功' )
25
- this .fileList .push (files . file )
24
+ onSuccess (' 上传成功' )
25
+ this .fileList .push (file)
26
26
}, 500 )
27
27
})
28
28
}
29
29
}
30
+ },
31
+ methods: {
32
+ handleSuccess (res ) {
33
+ TinyModal .message (res)
34
+ }
30
35
}
31
36
}
32
37
</script >
You can’t perform that action at this time.
0 commit comments