From b69e7d5ab4fc4449c9acbed912e6e03307d39491 Mon Sep 17 00:00:00 2001 From: Netfan Date: Wed, 4 Dec 2024 11:43:00 +0800 Subject: [PATCH 1/6] feat: `page` component support fixed header --- .../ui-kit/layout-ui/src/vben-layout.vue | 2 +- packages/effects/common-ui/package.json | 1 + .../common-ui/src/components/page/page.vue | 27 ++++++++++++++++++- playground/src/views/examples/modal/index.vue | 1 + pnpm-lock.yaml | 3 +++ 5 files changed, 32 insertions(+), 2 deletions(-) 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 3cdd3d1eae6..33624755736 100644 --- a/packages/@core/ui-kit/layout-ui/src/vben-layout.vue +++ b/packages/@core/ui-kit/layout-ui/src/vben-layout.vue @@ -503,7 +503,7 @@ function handleHeaderToggle() {
-import { computed, nextTick, onMounted, ref, useTemplateRef } from 'vue'; +import { + computed, + nextTick, + onMounted, + ref, + type StyleValue, + useTemplateRef, +} from 'vue'; + +import { preferences } from '@vben-core/preferences'; interface Props { title?: string; @@ -9,6 +18,8 @@ interface Props { * 根据content可见高度自适应 */ autoContentHeight?: boolean; + /** 头部固定 */ + fixedHeader?: boolean; } defineOptions({ @@ -20,6 +31,7 @@ const { description = '', autoContentHeight = false, title = '', + fixedHeader = false, } = defineProps(); const headerHeight = ref(0); @@ -29,6 +41,18 @@ const shouldAutoHeight = ref(false); const headerRef = useTemplateRef('headerRef'); const footerRef = useTemplateRef('footerRef'); +const headerStyle = computed(() => { + return fixedHeader + ? { + position: 'sticky', + zIndex: 200, + top: + preferences.header.mode === 'fixed' ? 'var(--vben-header-height)' : 0, + borderBottom: '1px solid hsl(240 5.9% 90%)', + } + : undefined; +}); + const contentStyle = computed(() => { if (autoContentHeight) { return { @@ -69,6 +93,7 @@ onMounted(() => { $slots.extra " ref="headerRef" + :style="headerStyle" class="bg-card relative px-6 py-4" > diff --git a/playground/src/views/examples/modal/index.vue b/playground/src/views/examples/modal/index.vue index d6db2fba294..22e9ed8c876 100644 --- a/playground/src/views/examples/modal/index.vue +++ b/playground/src/views/examples/modal/index.vue @@ -77,6 +77,7 @@ function openFormModal() {