From fa2b1ec24358e1e91945be66f437e90bc26d9154 Mon Sep 17 00:00:00 2001 From: Dream <1012377328@qq.com> Date: Wed, 12 Aug 2026 10:42:23 +0800 Subject: [PATCH] refactor(@vben/common-ui): simplify page content sizing --- .../components/page/__tests__/page.test.ts | 43 ++++++++++++ .../common-ui/src/components/page/page.vue | 68 ++++++++----------- 2 files changed, 73 insertions(+), 38 deletions(-) diff --git a/packages/effects/common-ui/src/components/page/__tests__/page.test.ts b/packages/effects/common-ui/src/components/page/__tests__/page.test.ts index a89061f5c..7047aa7bc 100644 --- a/packages/effects/common-ui/src/components/page/__tests__/page.test.ts +++ b/packages/effects/common-ui/src/components/page/__tests__/page.test.ts @@ -59,6 +59,49 @@ describe('page.vue', () => { expect(contentDiv.classes()).toContain('custom-class'); }); + it('uses flex layout for automatic content height', () => { + const wrapper = mount(Page, { + props: { + autoContentHeight: true, + heightOffset: 12, + title: 'Auto height page', + }, + }); + + const content = wrapper.find('[data-layout-region="page-content"]'); + const header = wrapper.find('.border-b'); + + expect(wrapper.classes()).toContain('min-h-0'); + expect(wrapper.classes()).toContain('overflow-hidden'); + expect(header.classes()).toContain('shrink-0'); + expect(content.exists()).toBe(true); + expect(content.classes()).toContain('min-h-0'); + expect(content.classes()).toContain('flex-1'); + expect(content.classes()).toContain('overflow-y-auto'); + expect(content.attributes('style')).toContain( + '--page-content-height-offset: 12px', + ); + expect(content.attributes('style')).not.toContain('--vben-content-height'); + }); + + it('positions the footer according to footerFixed', async () => { + const wrapper = mount(Page, { + slots: { + footer: '
Footer
', + }, + }); + + const footer = wrapper.find('.bg-card'); + expect(footer.classes()).toContain('shrink-0'); + expect(footer.classes()).not.toContain('absolute'); + + await wrapper.setProps({ footerFixed: true }); + + expect(footer.classes()).toContain('absolute'); + expect(footer.classes()).toContain('bottom-0'); + expect(footer.classes()).not.toContain('shrink-0'); + }); + it('does not render title slot if title prop is provided', () => { const wrapper = mount(Page, { props: { diff --git a/packages/effects/common-ui/src/components/page/page.vue b/packages/effects/common-ui/src/components/page/page.vue index 55146b934..ef8c08270 100644 --- a/packages/effects/common-ui/src/components/page/page.vue +++ b/packages/effects/common-ui/src/components/page/page.vue @@ -3,9 +3,8 @@ import type { StyleValue } from 'vue'; import type { PageProps } from './types'; -import { computed, nextTick, onMounted, ref, useTemplateRef } from 'vue'; +import { computed } from 'vue'; -import { CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT } from '@vben-core/shared/constants'; import { cn } from '@vben-core/shared/utils'; defineOptions({ @@ -18,45 +17,27 @@ const { footerFixed = false, } = defineProps