File tree 3 files changed +6
-6
lines changed
3 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,6 @@ describe('drawerApi', () => {
54
54
} ) ;
55
55
56
56
it ( 'should close the drawer if onBeforeClose allows it' , ( ) => {
57
- drawerApi . open ( ) ;
58
57
drawerApi . close ( ) ;
59
58
expect ( drawerApi . store . state . isOpen ) . toBe ( false ) ;
60
59
} ) ;
Original file line number Diff line number Diff line change @@ -86,12 +86,13 @@ export class DrawerApi {
86
86
}
87
87
88
88
/**
89
- * 关闭弹窗
89
+ * 关闭抽屉
90
+ * @description 关闭抽屉时会调用 onBeforeClose 钩子函数,如果 onBeforeClose 返回 false,则不关闭弹窗
90
91
*/
91
- close ( ) {
92
+ async close ( ) {
92
93
// 通过 onBeforeClose 钩子函数来判断是否允许关闭弹窗
93
94
// 如果 onBeforeClose 返回 false,则不关闭弹窗
94
- const allowClose = this . api . onBeforeClose ?.( ) ?? true ;
95
+ const allowClose = ( await this . api . onBeforeClose ?.( ) ) ?? true ;
95
96
if ( allowClose ) {
96
97
this . store . setState ( ( prev ) => ( {
97
98
...prev ,
Original file line number Diff line number Diff line change 1
1
import type { Component , Ref } from 'vue' ;
2
2
3
- import type { ClassType } from '@vben-core/typings' ;
3
+ import type { ClassType , MaybePromise } from '@vben-core/typings' ;
4
4
5
5
import type { DrawerApi } from './drawer-api' ;
6
6
@@ -151,7 +151,7 @@ export interface DrawerApiOptions extends DrawerState {
151
151
* 关闭前的回调,返回 false 可以阻止关闭
152
152
* @returns
153
153
*/
154
- onBeforeClose ?: ( ) => void ;
154
+ onBeforeClose ?: ( ) => MaybePromise < boolean | undefined > ;
155
155
/**
156
156
* 点击取消按钮的回调
157
157
*/
You can’t perform that action at this time.
0 commit comments