From 73502677ff315f4c398385b47ee031fe133f36d6 Mon Sep 17 00:00:00 2001 From: Netfan Date: Wed, 27 Nov 2024 11:29:25 +0800 Subject: [PATCH] feat: add `placement` for `Drawer` (#4958) --- docs/src/components/common-ui/vben-drawer.md | 1 + .../ui-kit/popup-ui/src/drawer/drawer-api.ts | 1 + .../@core/ui-kit/popup-ui/src/drawer/drawer.ts | 8 ++++++++ .../@core/ui-kit/popup-ui/src/drawer/drawer.vue | 5 ++++- playground/src/views/examples/drawer/index.vue | 17 ++++++++++++++--- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/src/components/common-ui/vben-drawer.md b/docs/src/components/common-ui/vben-drawer.md index e149b6aa..939593fa 100644 --- a/docs/src/components/common-ui/vben-drawer.md +++ b/docs/src/components/common-ui/vben-drawer.md @@ -88,6 +88,7 @@ const [Drawer, drawerApi] = useVbenDrawer({ | closeOnPressEscape | esc 关闭弹窗 | `boolean` | `true` | | confirmText | 确认按钮文本 | `string\|slot` | `确认` | | cancelText | 取消按钮文本 | `string\|slot` | `取消` | +| placement | 抽屉弹出位置 | `'left'\|'right'\|'top'\|'bottom'` | `right` | | showCancelButton | 显示取消按钮 | `boolean` | `true` | | showConfirmButton | 显示确认按钮文本 | `boolean` | `true` | | class | modal的class,宽度通过这个配置 | `string` | - | diff --git a/packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts b/packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts index 64d8d404..6ceee088 100644 --- a/packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts +++ b/packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts @@ -41,6 +41,7 @@ export class DrawerApi { loading: false, modal: true, openAutoFocus: false, + placement: 'right', showCancelButton: true, showConfirmButton: true, title: '', diff --git a/packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts b/packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts index 3b4ce4b7..a1992c87 100644 --- a/packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts +++ b/packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts @@ -4,6 +4,8 @@ import type { DrawerApi } from './drawer-api'; import type { Component, Ref } from 'vue'; +export type DrawerPlacement = 'bottom' | 'left' | 'right' | 'top'; + export interface DrawerProps { /** * 取消按钮文字 @@ -72,6 +74,12 @@ export interface DrawerProps { * 是否自动聚焦 */ openAutoFocus?: boolean; + + /** + * 抽屉位置 + * @default right + */ + placement?: DrawerPlacement; /** * 是否显示取消按钮 * @default true diff --git a/packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue b/packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue index bfed16ea..a0167099 100644 --- a/packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue +++ b/packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue @@ -62,6 +62,7 @@ const { loading: showLoading, modal, openAutoFocus, + placement, showCancelButton, showConfirmButton, title, @@ -119,11 +120,13 @@ function handleFocusOutside(e: Event) { -import { Page, useVbenDrawer } from '@vben/common-ui'; +import { type DrawerPlacement, Page, useVbenDrawer } from '@vben/common-ui'; import { Button, Card } from 'ant-design-vue'; @@ -13,6 +13,7 @@ import SharedDataDemo from './shared-data-demo.vue'; const [BaseDrawer, baseDrawerApi] = useVbenDrawer({ // 连接抽离的组件 connectedComponent: BaseDemo, + // placement: 'left', }); const [AutoHeightDrawer, autoHeightDrawerApi] = useVbenDrawer({ @@ -31,7 +32,8 @@ const [FormDrawer, formDrawerApi] = useVbenDrawer({ connectedComponent: FormDrawerDemo, }); -function openBaseDrawer() { +function openBaseDrawer(placement: DrawerPlacement = 'right') { + baseDrawerApi.setState({ placement }); baseDrawerApi.open(); } @@ -81,7 +83,16 @@ function openFormDrawer() {

一个基础的抽屉示例

- + + + +