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 {
304304 } ,
305305 {
306306 name : 'http-request' ,
307- type : '(file: IFile ) => Promise<any>' ,
308- typeAnchorName : 'IFile ' ,
307+ type : '(file: ICustomParam ) => Promise<any>' ,
308+ typeAnchorName : 'ICustomParam ' ,
309309 defaultValue : '' ,
310310 desc : {
311311 'zh-CN' : '覆盖默认的上传行为,可以自定义上传的实现; 由于 TinyVue 官网为 Mock 上传不能执行上传' ,
@@ -1059,6 +1059,22 @@ interface IFile {
10591059}
10601060 `
10611061 } ,
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+ } ,
10621078 {
10631079 name : 'IEncryptConfig' ,
10641080 type : 'interface' ,
Original file line number Diff line number Diff line change 11<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 " >
33 <template #trigger >
44 <tiny-button >点击上传</tiny-button >
55 </template >
66 </tiny-file-upload >
77</template >
88
99<script setup>
10- import { ref , reactive } from ' vue'
10+ import { reactive } from ' vue'
1111import { TinyFileUpload , TinyButton , TinyModal } from ' @opentiny/vue'
1212
1313const fileList = reactive ([])
14- const httpRequest = ref (( files ) => {
14+ const httpRequest = reactive (({ onSuccess, file } ) => {
1515 return new Promise ((resolve ) => {
1616 // 此处为用户自定义的上传服务请求
1717 setTimeout (() => {
18- TinyModal . message (' 上传成功' )
19- fileList .push (files . file )
18+ onSuccess (' 上传成功' )
19+ this . fileList .push (file)
2020 }, 500 )
2121 })
2222})
23+ const handleSuccess = (res ) => {
24+ TinyModal .message (res)
25+ }
2326 </script >
Original file line number Diff line number Diff line change 11<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 " >
33 <template #trigger >
44 <tiny-button >点击上传</tiny-button >
55 </template >
@@ -17,16 +17,21 @@ export default {
1717 data () {
1818 return {
1919 fileList: [],
20- httpRequest : (files ) => {
20+ httpRequest : ({ onSuccess, file } ) => {
2121 return new Promise ((resolve ) => {
2222 // 此处为用户自定义的上传服务请求
2323 setTimeout (() => {
24- TinyModal . message (' 上传成功' )
25- this .fileList .push (files . file )
24+ onSuccess (' 上传成功' )
25+ this .fileList .push (file)
2626 }, 500 )
2727 })
2828 }
2929 }
30+ },
31+ methods: {
32+ handleSuccess (res ) {
33+ TinyModal .message (res)
34+ }
3035 }
3136}
3237 </script >
You can’t perform that action at this time.
0 commit comments