fix: DocAlert 显示导致页面的高度计算不准确:在 page.vue 增加 doc 区域

pull/83/MERGE
YunaiV 2025-04-25 21:42:56 +08:00
parent 3be2d4c87f
commit 4125265582
2 changed files with 21 additions and 3 deletions

View File

@ -6,7 +6,6 @@ import type {
import type { SystemRoleApi } from '#/api/system/role'; import type { SystemRoleApi } from '#/api/system/role';
import { Page, useVbenModal } from '@vben/common-ui'; import { Page, useVbenModal } from '@vben/common-ui';
import { isDocAlertEnable } from '@vben/hooks';
import { Download, Plus } from '@vben/icons'; import { Download, Plus } from '@vben/icons';
import { downloadFileFromBlobPart } from '@vben/utils'; import { downloadFileFromBlobPart } from '@vben/utils';
@ -142,7 +141,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template> <template>
<Page auto-content-height> <Page auto-content-height>
<template #description v-if="isDocAlertEnable()"> <template #doc>
<DocAlert <DocAlert
title="功能权限" title="功能权限"
url="https://doc.iocoder.cn/resource-permission" url="https://doc.iocoder.cn/resource-permission"

View File

@ -16,15 +16,17 @@ const { autoContentHeight = false } = defineProps<PageProps>();
const headerHeight = ref(0); const headerHeight = ref(0);
const footerHeight = ref(0); const footerHeight = ref(0);
const docHeight = ref(0);
const shouldAutoHeight = ref(false); const shouldAutoHeight = ref(false);
const headerRef = useTemplateRef<HTMLDivElement>('headerRef'); const headerRef = useTemplateRef<HTMLDivElement>('headerRef');
const footerRef = useTemplateRef<HTMLDivElement>('footerRef'); const footerRef = useTemplateRef<HTMLDivElement>('footerRef');
const docRef = useTemplateRef<HTMLDivElement>('docRef');
const contentStyle = computed<StyleValue>(() => { const contentStyle = computed<StyleValue>(() => {
if (autoContentHeight) { if (autoContentHeight) {
return { return {
height: `calc(var(${CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT}) - ${headerHeight.value}px)`, height: `calc(var(${CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT}) - ${headerHeight.value}px - ${docHeight.value}px)`,
overflowY: shouldAutoHeight.value ? 'auto' : 'unset', overflowY: shouldAutoHeight.value ? 'auto' : 'unset',
}; };
} }
@ -38,11 +40,16 @@ async function calcContentHeight() {
await nextTick(); await nextTick();
headerHeight.value = headerRef.value?.offsetHeight || 0; headerHeight.value = headerRef.value?.offsetHeight || 0;
footerHeight.value = footerRef.value?.offsetHeight || 0; footerHeight.value = footerRef.value?.offsetHeight || 0;
docHeight.value = docRef.value?.offsetHeight || 0;
setTimeout(() => { setTimeout(() => {
shouldAutoHeight.value = true; shouldAutoHeight.value = true;
}, 30); }, 30);
} }
function isDocAlertEnable(): boolean {
return import.meta.env.VITE_APP_DOCALERT_ENABLE !== 'false';
}
onMounted(() => { onMounted(() => {
calcContentHeight(); calcContentHeight();
}); });
@ -50,6 +57,18 @@ onMounted(() => {
<template> <template>
<div class="relative"> <div class="relative">
<div
v-if="$slots.doc && isDocAlertEnable()"
ref="docRef"
:class="
cn('bg-card border-border relative flex items-end border-b px-6 py-4')
"
>
<div class="flex-auto">
<slot name="doc"></slot>
</div>
</div>
<div <div
v-if=" v-if="
description || description ||