File tree 4 files changed +50
-4
lines changed
playground/src/api/examples
4 files changed +50
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { verifyAccessToken } from '~/utils/jwt-utils' ;
2
+ import { unAuthorizedResponse } from '~/utils/response' ;
3
+
4
+ export default eventHandler ( ( event ) => {
5
+ const userinfo = verifyAccessToken ( event ) ;
6
+ if ( ! userinfo ) {
7
+ return unAuthorizedResponse ( event ) ;
8
+ }
9
+ return useResponseSuccess ( {
10
+ url :
'https://unpkg.com/@vbenjs/[email protected] /source/logo-v1.webp' ,
11
+ } ) ;
12
+ // return useResponseError("test")
13
+ } ) ;
Original file line number Diff line number Diff line change @@ -91,14 +91,13 @@ const getIconRender = computed(() => {
91
91
});
92
92
93
93
function doCancel() {
94
- isConfirm . value = false ;
94
+ handleCancel () ;
95
95
handleOpenChange (false );
96
96
}
97
97
98
98
function doConfirm() {
99
- isConfirm . value = true ;
99
+ handleConfirm () ;
100
100
handleOpenChange (false );
101
- emits (' confirm' );
102
101
}
103
102
104
103
provideAlertContext ({
@@ -117,11 +116,13 @@ function handleCancel() {
117
116
118
117
const loading = ref (false );
119
118
async function handleOpenChange(val : boolean ) {
119
+ const confirmState = isConfirm .value ;
120
+ isConfirm .value = false ;
120
121
await nextTick ();
121
122
if (! val && props .beforeClose ) {
122
123
loading .value = true ;
123
124
try {
124
- const res = await props .beforeClose ({ isConfirm: isConfirm . value });
125
+ const res = await props .beforeClose ({ isConfirm: confirmState });
125
126
if (res !== false ) {
126
127
open .value = false ;
127
128
}
Original file line number Diff line number Diff line change @@ -70,6 +70,13 @@ export function useVbenModal<TParentModalProps extends ModalProps = ModalProps>(
70
70
injectData . options ?. onOpenChange ?.( isOpen ) ;
71
71
} ;
72
72
73
+ mergedOptions . onClosed = ( ) => {
74
+ options . onClosed ?.( ) ;
75
+ if ( options . destroyOnClose ) {
76
+ injectData . reCreateModal ?.( ) ;
77
+ }
78
+ } ;
79
+
73
80
const api = new ModalApi ( mergedOptions ) ;
74
81
75
82
const extendedApi : ExtendedModalApi = api as never ;
Original file line number Diff line number Diff line change
1
+ import { requestClient } from '#/api/request' ;
2
+
3
+ interface UploadFileParams {
4
+ file : File ;
5
+ onError ?: ( error : Error ) => void ;
6
+ onProgress ?: ( progress : { percent : number } ) => void ;
7
+ onSuccess ?: ( data : any , file : File ) => void ;
8
+ }
9
+ export async function upload_file ( {
10
+ file,
11
+ onError,
12
+ onProgress,
13
+ onSuccess,
14
+ } : UploadFileParams ) {
15
+ try {
16
+ onProgress ?.( { percent : 0 } ) ;
17
+
18
+ const data = await requestClient . upload ( '/upload' , { file } ) ;
19
+
20
+ onProgress ?.( { percent : 100 } ) ;
21
+ onSuccess ?.( data , file ) ;
22
+ } catch ( error ) {
23
+ onError ?.( error instanceof Error ? error : new Error ( String ( error ) ) ) ;
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments