From e419b03cab7ca55274cd52ef402ec45cd91cdd80 Mon Sep 17 00:00:00 2001 From: Netfan Date: Tue, 10 Dec 2024 17:37:06 +0800 Subject: [PATCH] feat: modal&drawer support appendToMain and zIndex (#5092) * feat: modal/drawer support append to main content * feat: modal zIndex support * fix: drawer prop define * chore: type * fix: modal/drawer position fixed while append to body * docs: typo * chore: add full-width drawer in content area * chore: remove unnecessary class --- docs/src/components/common-ui/vben-drawer.md | 8 +++ docs/src/components/common-ui/vben-modal.md | 8 +++ .../base/shared/src/constants/globals.ts | 3 + packages/@core/ui-kit/layout-ui/package.json | 1 + .../ui-kit/layout-ui/src/vben-layout.vue | 4 ++ .../ui-kit/popup-ui/src/drawer/drawer.ts | 13 +++- .../ui-kit/popup-ui/src/drawer/drawer.vue | 13 +++- .../@core/ui-kit/popup-ui/src/modal/modal.ts | 11 ++- .../@core/ui-kit/popup-ui/src/modal/modal.vue | 9 +++ .../shadcn-ui/src/ui/dialog/DialogContent.vue | 27 +++++-- .../shadcn-ui/src/ui/dialog/DialogOverlay.vue | 5 +- .../src/ui/dialog/DialogScrollContent.vue | 9 ++- .../shadcn-ui/src/ui/sheet/SheetContent.vue | 26 +++++-- .../shadcn-ui/src/ui/sheet/SheetOverlay.vue | 5 +- .../ui-kit/shadcn-ui/src/ui/sheet/sheet.ts | 4 +- .../common-ui/src/components/page/page.vue | 13 +++- .../views/examples/drawer/in-content-demo.vue | 21 ++++++ .../src/views/examples/drawer/index.vue | 71 +++++++++++++++++-- .../views/examples/modal/in-content-demo.vue | 25 +++++++ playground/src/views/examples/modal/index.vue | 17 +++++ .../src/views/examples/vxe-table/basic.vue | 6 ++ pnpm-lock.yaml | 3 + 22 files changed, 271 insertions(+), 31 deletions(-) create mode 100644 playground/src/views/examples/drawer/in-content-demo.vue create mode 100644 playground/src/views/examples/modal/in-content-demo.vue diff --git a/docs/src/components/common-ui/vben-drawer.md b/docs/src/components/common-ui/vben-drawer.md index 939593fa..7091570f 100644 --- a/docs/src/components/common-ui/vben-drawer.md +++ b/docs/src/components/common-ui/vben-drawer.md @@ -74,6 +74,7 @@ const [Drawer, drawerApi] = useVbenDrawer({ | 属性名 | 描述 | 类型 | 默认值 | | --- | --- | --- | --- | +| appendToMain | 是否挂载到内容区域(默认挂载到body) | `boolean` | `false` | | title | 标题 | `string\|slot` | - | | titleTooltip | 标题提示信息 | `string\|slot` | - | | description | 描述信息 | `string\|slot` | - | @@ -95,6 +96,13 @@ const [Drawer, drawerApi] = useVbenDrawer({ | contentClass | modal内容区域的class | `string` | - | | footerClass | modal底部区域的class | `string` | - | | headerClass | modal顶部区域的class | `string` | - | +| zIndex | 抽屉的ZIndex层级 | `number` | `1000` | + +::: info appendToMain + +`appendToMain`可以指定将抽屉挂载到内容区域,打开抽屉时,内容区域以外的部分(标签栏、导航菜单等等)不会被遮挡。默认情况下,抽屉会挂载到body上。但是:挂载到内容区域时,作为页面根容器的`Page`组件,需要设置`auto-content-height`属性,以便抽屉能够正确计算高度。 + +::: ### Event diff --git a/docs/src/components/common-ui/vben-modal.md b/docs/src/components/common-ui/vben-modal.md index 75f620ae..ced8feba 100644 --- a/docs/src/components/common-ui/vben-modal.md +++ b/docs/src/components/common-ui/vben-modal.md @@ -80,6 +80,7 @@ const [Modal, modalApi] = useVbenModal({ | 属性名 | 描述 | 类型 | 默认值 | | --- | --- | --- | --- | +| appendToMain | 是否挂载到内容区域(默认挂载到body) | `boolean` | `false` | | title | 标题 | `string\|slot` | - | | titleTooltip | 标题提示信息 | `string\|slot` | - | | description | 描述信息 | `string\|slot` | - | @@ -106,6 +107,13 @@ const [Modal, modalApi] = useVbenModal({ | footerClass | modal底部区域的class | `string` | - | | headerClass | modal顶部区域的class | `string` | - | | bordered | 是否显示border | `boolean` | `false` | +| zIndex | 弹窗的ZIndex层级 | `number` | `1000` | + +::: info appendToMain + +`appendToMain`可以指定将弹窗挂载到内容区域,打开带这招的弹窗时,内容区域以外的部分(标签栏、导航菜单等等)不会被遮挡。默认情况下,弹窗会挂载到body上。但是:挂载到内容区域时,作为页面根容器的`Page`组件,需要设置`auto-content-height`属性,以便弹窗能够正确计算高度。 + +::: ### Event diff --git a/packages/@core/base/shared/src/constants/globals.ts b/packages/@core/base/shared/src/constants/globals.ts index 17941de1..3c699570 100644 --- a/packages/@core/base/shared/src/constants/globals.ts +++ b/packages/@core/base/shared/src/constants/globals.ts @@ -7,6 +7,9 @@ export const CSS_VARIABLE_LAYOUT_HEADER_HEIGHT = `--vben-header-height`; /** layout footer 组件的高度 */ export const CSS_VARIABLE_LAYOUT_FOOTER_HEIGHT = `--vben-footer-height`; +/** 内容区域的组件ID */ +export const ELEMENT_ID_MAIN_CONTENT = `__vben_main_content`; + /** * @zh_CN 默认命名空间 */ diff --git a/packages/@core/ui-kit/layout-ui/package.json b/packages/@core/ui-kit/layout-ui/package.json index 1039a2fa..d249146f 100644 --- a/packages/@core/ui-kit/layout-ui/package.json +++ b/packages/@core/ui-kit/layout-ui/package.json @@ -40,6 +40,7 @@ "@vben-core/composables": "workspace:*", "@vben-core/icons": "workspace:*", "@vben-core/shadcn-ui": "workspace:*", + "@vben-core/shared": "workspace:*", "@vben-core/typings": "workspace:*", "@vueuse/core": "catalog:", "vue": "catalog:" diff --git a/packages/@core/ui-kit/layout-ui/src/vben-layout.vue b/packages/@core/ui-kit/layout-ui/src/vben-layout.vue index a598f291..fe9b1d85 100644 --- a/packages/@core/ui-kit/layout-ui/src/vben-layout.vue +++ b/packages/@core/ui-kit/layout-ui/src/vben-layout.vue @@ -11,6 +11,7 @@ import { } from '@vben-core/composables'; import { Menu } from '@vben-core/icons'; import { VbenIconButton } from '@vben-core/shadcn-ui'; +import { ELEMENT_ID_MAIN_CONTENT } from '@vben-core/shared/constants'; import { useMouse, useScroll, useThrottleFn } from '@vueuse/core'; @@ -457,6 +458,8 @@ function handleHeaderToggle() { emit('toggleSidebar'); } } + +const idMainContent = ELEMENT_ID_MAIN_CONTENT;