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:
parent
5252480b09
commit
8f3881eabf
@ -54,7 +54,6 @@ describe('drawerApi', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should close the drawer if onBeforeClose allows it', () => {
|
it('should close the drawer if onBeforeClose allows it', () => {
|
||||||
drawerApi.open();
|
|
||||||
drawerApi.close();
|
drawerApi.close();
|
||||||
expect(drawerApi.store.state.isOpen).toBe(false);
|
expect(drawerApi.store.state.isOpen).toBe(false);
|
||||||
});
|
});
|
||||||
|
@ -86,12 +86,13 @@ export class DrawerApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭弹窗
|
* 关闭抽屉
|
||||||
|
* @description 关闭抽屉时会调用 onBeforeClose 钩子函数,如果 onBeforeClose 返回 false,则不关闭弹窗
|
||||||
*/
|
*/
|
||||||
close() {
|
async close() {
|
||||||
// 通过 onBeforeClose 钩子函数来判断是否允许关闭弹窗
|
// 通过 onBeforeClose 钩子函数来判断是否允许关闭弹窗
|
||||||
// 如果 onBeforeClose 返回 false,则不关闭弹窗
|
// 如果 onBeforeClose 返回 false,则不关闭弹窗
|
||||||
const allowClose = this.api.onBeforeClose?.() ?? true;
|
const allowClose = (await this.api.onBeforeClose?.()) ?? true;
|
||||||
if (allowClose) {
|
if (allowClose) {
|
||||||
this.store.setState((prev) => ({
|
this.store.setState((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { Component, Ref } from 'vue';
|
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';
|
import type { DrawerApi } from './drawer-api';
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ export interface DrawerApiOptions extends DrawerState {
|
|||||||
* 关闭前的回调,返回 false 可以阻止关闭
|
* 关闭前的回调,返回 false 可以阻止关闭
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
onBeforeClose?: () => void;
|
onBeforeClose?: () => MaybePromise<boolean | undefined>;
|
||||||
/**
|
/**
|
||||||
* 点击取消按钮的回调
|
* 点击取消按钮的回调
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user