perf: beforeClose of drawer support promise (#5932)

* perf: the beforeClose function of drawer is consistent with that of modal

* refactor: drawer test update
This commit is contained in:
LinaBell 2025-04-16 11:27:13 +08:00 committed by GitHub
parent 5252480b09
commit 8f3881eabf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View File

@ -54,7 +54,6 @@ describe('drawerApi', () => {
});
it('should close the drawer if onBeforeClose allows it', () => {
drawerApi.open();
drawerApi.close();
expect(drawerApi.store.state.isOpen).toBe(false);
});

View File

@ -86,12 +86,13 @@ export class DrawerApi {
}
/**
*
*
* @description onBeforeClose onBeforeClose false
*/
close() {
async close() {
// 通过 onBeforeClose 钩子函数来判断是否允许关闭弹窗
// 如果 onBeforeClose 返回 false则不关闭弹窗
const allowClose = this.api.onBeforeClose?.() ?? true;
const allowClose = (await this.api.onBeforeClose?.()) ?? true;
if (allowClose) {
this.store.setState((prev) => ({
...prev,

View File

@ -1,6 +1,6 @@
import type { Component, Ref } from 'vue';
import type { ClassType } from '@vben-core/typings';
import type { ClassType, MaybePromise } from '@vben-core/typings';
import type { DrawerApi } from './drawer-api';
@ -151,7 +151,7 @@ export interface DrawerApiOptions extends DrawerState {
* false
* @returns
*/
onBeforeClose?: () => void;
onBeforeClose?: () => MaybePromise<boolean | undefined>;
/**
*
*/