Skip to content

Commit 5232e77

Browse files
committed
fix: layout and Page style adjustment, fixed vbenjs#5021 vbenjs#5027
1 parent 4c1fc4a commit 5232e77

File tree

3 files changed

+70
-27
lines changed

3 files changed

+70
-27
lines changed

packages/@core/ui-kit/layout-ui/src/vben-layout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ function handleHeaderToggle() {
503503

504504
<div
505505
ref="contentRef"
506-
class="flex flex-1 flex-col transition-all duration-300 ease-in"
506+
class="flex flex-1 flex-col overflow-hidden transition-all duration-300 ease-in"
507507
>
508508
<div
509509
:class="[

packages/effects/common-ui/src/components/page/page.vue

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ import {
99
} from 'vue';
1010
1111
import { preferences } from '@vben-core/preferences';
12+
import {
13+
CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT,
14+
CSS_VARIABLE_LAYOUT_CONTENT_WIDTH,
15+
CSS_VARIABLE_LAYOUT_FOOTER_HEIGHT,
16+
CSS_VARIABLE_LAYOUT_HEADER_HEIGHT,
17+
} from '@vben-core/shared/constants';
1218
import { cn } from '@vben-core/shared/utils';
1319
20+
import { useElementSize } from '@vueuse/core';
21+
1422
interface Props {
1523
title?: string;
1624
description?: string;
@@ -37,34 +45,65 @@ const {
3745
fixedHeader = false,
3846
} = defineProps<Props>();
3947
40-
const headerHeight = ref(0);
41-
const footerHeight = ref(0);
4248
const shouldAutoHeight = ref(false);
4349
4450
const headerRef = useTemplateRef<HTMLDivElement>('headerRef');
4551
const footerRef = useTemplateRef<HTMLDivElement>('footerRef');
52+
const { height: headerHeight } = useElementSize(
53+
headerRef,
54+
{
55+
height: 0,
56+
width: 0,
57+
},
58+
{ box: 'border-box' },
59+
);
60+
const { height: footerHeight } = useElementSize(
61+
footerRef,
62+
{
63+
height: 0,
64+
width: 0,
65+
},
66+
{ box: 'border-box' },
67+
);
4668
4769
const headerStyle = computed<StyleValue>(() => {
4870
return fixedHeader
4971
? {
50-
position: 'sticky',
72+
position: 'fixed',
5173
zIndex: 200,
74+
width: `var(${CSS_VARIABLE_LAYOUT_CONTENT_WIDTH})`,
5275
top:
53-
preferences.header.mode === 'fixed' ? 'var(--vben-header-height)' : 0,
76+
preferences.header.mode === 'fixed'
77+
? `var(${CSS_VARIABLE_LAYOUT_HEADER_HEIGHT})`
78+
: 0,
5479
}
5580
: undefined;
5681
});
5782
83+
const footerStyle = computed<StyleValue>(() => {
84+
return {
85+
bottom:
86+
preferences.footer.enable && preferences.footer.fixed
87+
? `var(${CSS_VARIABLE_LAYOUT_FOOTER_HEIGHT})`
88+
: 0,
89+
width: `var(${CSS_VARIABLE_LAYOUT_CONTENT_WIDTH})`,
90+
};
91+
});
92+
5893
const contentStyle = computed(() => {
94+
const style: StyleValue = {};
95+
if (headerHeight.value > 0 && fixedHeader) {
96+
style.marginTop = `${headerHeight.value}px`;
97+
}
98+
if (footerHeight.value > 0) {
99+
style.marginBottom = `${footerHeight.value}px`;
100+
}
59101
if (autoContentHeight) {
60-
return {
61-
height: shouldAutoHeight.value
62-
? `calc(var(--vben-content-height) - ${headerHeight.value}px - ${footerHeight.value}px)`
63-
: '0',
64-
// 'overflow-y': shouldAutoHeight.value?'auto':'unset',
65-
};
102+
style.height = shouldAutoHeight.value
103+
? `calc(var(${CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT}) - ${headerHeight.value}px - ${footerHeight.value}px)`
104+
: '0';
66105
}
67-
return {};
106+
return style;
68107
});
69108
70109
async function calcContentHeight() {
@@ -97,7 +136,7 @@ onMounted(() => {
97136
ref="headerRef"
98137
:class="
99138
cn(
100-
'bg-card relative px-6 py-4',
139+
'bg-card relative flex gap-2 px-6 py-4',
101140
headerClass,
102141
fixedHeader
103142
? 'border-border border-b transition-all duration-200'
@@ -106,19 +145,21 @@ onMounted(() => {
106145
"
107146
:style="headerStyle"
108147
>
109-
<slot name="title">
110-
<div v-if="title" class="mb-2 flex text-lg font-semibold">
111-
{{ title }}
112-
</div>
113-
</slot>
114-
115-
<slot name="description">
116-
<p v-if="description" class="text-muted-foreground">
117-
{{ description }}
118-
</p>
119-
</slot>
120-
121-
<div v-if="$slots.extra" class="absolute bottom-4 right-4">
148+
<div class="flex-auto">
149+
<slot name="title">
150+
<div v-if="title" class="mb-2 flex text-lg font-semibold">
151+
{{ title }}
152+
</div>
153+
</slot>
154+
155+
<slot name="description">
156+
<p v-if="description" class="text-muted-foreground">
157+
{{ description }}
158+
</p>
159+
</slot>
160+
</div>
161+
162+
<div v-if="$slots.extra" class="mb-2 self-end">
122163
<slot name="extra"></slot>
123164
</div>
124165
</div>
@@ -133,9 +174,10 @@ onMounted(() => {
133174
:class="
134175
cn(
135176
footerClass,
136-
'bg-card align-center absolute bottom-0 left-0 right-0 flex px-6 py-4',
177+
'bg-card align-center border-border fixed right-0 flex border-t px-6 py-4 transition-all duration-200',
137178
)
138179
"
180+
:style="footerStyle"
139181
>
140182
<slot name="footer"></slot>
141183
</div>

playground/src/views/examples/vxe-table/basic.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function changeLoading() {
7171
<template>
7272
<Page
7373
description="表格组件常用于快速开发数据展示与交互界面,示例数据为静态数据。该组件是对vxe-table进行简单的二次封装,大部分属性与方法与vxe-table保持一致。"
74+
fixed-header
7475
title="表格基础示例"
7576
>
7677
<template #extra>

0 commit comments

Comments
 (0)