Merge branch 'main' of https://github.com/vbenjs/vue-vben-admin into warmflow

This commit is contained in:
dap
2025-01-12 10:07:39 +08:00
42 changed files with 848 additions and 131 deletions

View File

@@ -4,6 +4,12 @@ import { Store } from '@vben-core/shared/store';
import { bindMethods, isFunction } from '@vben-core/shared/utils';
export class DrawerApi {
// 共享数据
public sharedData: Record<'payload', any> = {
payload: {},
};
public store: Store<DrawerState>;
private api: Pick<
DrawerApiOptions,
| 'onBeforeClose'
@@ -13,16 +19,10 @@ export class DrawerApi {
| 'onOpenChange'
| 'onOpened'
>;
// private prevState!: DrawerState;
private state!: DrawerState;
// 共享数据
public sharedData: Record<'payload', any> = {
payload: {},
};
public store: Store<DrawerState>;
constructor(options: DrawerApiOptions = {}) {
const {
connectedComponent: _,
@@ -149,6 +149,7 @@ export class DrawerApi {
setData<T>(payload: T) {
this.sharedData.payload = payload;
return this;
}
setState(
@@ -161,5 +162,6 @@ export class DrawerApi {
} else {
this.store.setState((prev) => ({ ...prev, ...stateOrFn }));
}
return this;
}
}

View File

@@ -1,6 +1,7 @@
import type { ClassType } from '@vben-core/typings';
import type { Component, Ref } from 'vue';
import type { ClassType } from '@vben-core/typings';
import type { DrawerApi } from './drawer-api';
export type DrawerPlacement = 'bottom' | 'left' | 'right' | 'top';
@@ -84,12 +85,16 @@ export interface DrawerProps {
* 是否自动聚焦
*/
openAutoFocus?: boolean;
/**
* 弹窗遮罩模糊效果
*/
overlayBlur?: number;
/**
* 抽屉位置
* @default right
*/
placement?: DrawerPlacement;
/**
* 是否显示取消按钮
* @default true
@@ -123,11 +128,11 @@ export interface DrawerState extends DrawerProps {
sharedData?: Record<string, any>;
}
export type ExtendedDrawerApi = {
export type ExtendedDrawerApi = DrawerApi & {
useStore: <T = NoInfer<DrawerState>>(
selector?: (state: NoInfer<DrawerState>) => T,
) => Readonly<Ref<T>>;
} & DrawerApi;
};
export interface DrawerApiOptions extends DrawerState {
/**

View File

@@ -68,6 +68,7 @@ const {
loading: showLoading,
modal,
openAutoFocus,
overlayBlur,
placement,
showCancelButton,
showConfirmButton,
@@ -140,6 +141,7 @@ const getAppendTo = computed(() => {
:open="state?.isOpen"
:side="placement"
:z-index="zIndex"
:overlay-blur="overlayBlur"
@close-auto-focus="handleFocusOutside"
@closed="() => drawerApi?.onClosed()"
@escape-key-down="escapeKeyDown"

View File

@@ -4,6 +4,12 @@ import { Store } from '@vben-core/shared/store';
import { bindMethods, isFunction } from '@vben-core/shared/utils';
export class ModalApi {
// 共享数据
public sharedData: Record<'payload', any> = {
payload: {},
};
public store: Store<ModalState>;
private api: Pick<
ModalApiOptions,
| 'onBeforeClose'
@@ -13,16 +19,10 @@ export class ModalApi {
| 'onOpenChange'
| 'onOpened'
>;
// private prevState!: ModalState;
private state!: ModalState;
// 共享数据
public sharedData: Record<'payload', any> = {
payload: {},
};
public store: Store<ModalState>;
constructor(options: ModalApiOptions = {}) {
const {
connectedComponent: _,
@@ -159,6 +159,7 @@ export class ModalApi {
setData<T>(payload: T) {
this.sharedData.payload = payload;
return this;
}
setState(
@@ -171,5 +172,6 @@ export class ModalApi {
} else {
this.store.setState((prev) => ({ ...prev, ...stateOrFn }));
}
return this;
}
}

View File

@@ -99,6 +99,10 @@ export interface ModalProps {
* 是否自动聚焦
*/
openAutoFocus?: boolean;
/**
* 弹窗遮罩模糊效果
*/
overlayBlur?: number;
/**
* 是否显示取消按钮
* @default true
@@ -132,11 +136,11 @@ export interface ModalState extends ModalProps {
sharedData?: Record<string, any>;
}
export type ExtendedModalApi = {
export type ExtendedModalApi = ModalApi & {
useStore: <T = NoInfer<ModalState>>(
selector?: (state: NoInfer<ModalState>) => T,
) => Readonly<Ref<T>>;
} & ModalApi;
};
export interface ModalApiOptions extends ModalState {
/**

View File

@@ -77,6 +77,7 @@ const {
loading: showLoading,
modal,
openAutoFocus,
overlayBlur,
showCancelButton,
showConfirmButton,
title,
@@ -196,6 +197,7 @@ const getAppendTo = computed(() => {
:open="state?.isOpen"
:show-close="closable"
:z-index="zIndex"
:overlay-blur="overlayBlur"
close-class="top-3"
@close-auto-focus="handleFocusOutside"
@closed="() => modalApi?.onClosed()"