From cd00236563ef94012f4ba2d037e19568bed60970 Mon Sep 17 00:00:00 2001 From: GouJ Date: Sun, 27 Sep 2026 15:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=94=B6=E7=BC=A9=E5=BC=B9=E7=AA=97=E6=AD=A3=E6=96=87=E5=B9=B6?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E5=BA=95=E9=83=A8=E6=93=8D=E4=BD=9C=E6=A0=8F?= =?UTF-8?q?=E5=8F=AF=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ui/AppDialog.vue | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/ui/AppDialog.vue b/src/components/ui/AppDialog.vue index 30b98dd..018722a 100644 --- a/src/components/ui/AppDialog.vue +++ b/src/components/ui/AppDialog.vue @@ -6,22 +6,25 @@ import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue' defineProps<{ title: string; description: string; busy?: boolean; wide?: boolean }>() const open = defineModel('open', { default: false }) const bodyAnchor = ref(null) -const bodyMaxHeight = ref(0) +const bodyHeight = ref(0) let layoutObserver: ResizeObserver | undefined -/** 按视口与实际标题、底栏尺寸限制正文,短内容保持自然高度。 */ +/** 正文使用内容高度与剩余视口高度的较小值;为 NScrollbar 提供明确滚动高度。 */ function updateBodyHeight() { const card = bodyAnchor.value?.closest('.app-dialog') - if (!card) return + const scrollContent = bodyAnchor.value?.parentElement + if (!card || !scrollContent) return const header = card.querySelector('.n-card-header') const footer = card.querySelector('.n-card__footer') const content = card.querySelector('.n-card__content') const contentStyle = content ? getComputedStyle(content) : null - bodyMaxHeight.value = Math.max( - 48, + const available = Math.max( + 0, window.innerHeight - 32 - (header?.offsetHeight ?? 0) - (footer?.offsetHeight ?? 0) - (contentStyle ? parseFloat(contentStyle.paddingTop) + parseFloat(contentStyle.paddingBottom) : 0) + - 2 ) + bodyHeight.value = Math.min(scrollContent.scrollHeight, available) } watch(open, async shown => { layoutObserver?.disconnect() @@ -29,12 +32,14 @@ watch(open, async shown => { await nextTick() updateBodyHeight() const card = bodyAnchor.value?.closest('.app-dialog') - if (!card) return + const scrollContent = bodyAnchor.value?.parentElement + if (!card || !scrollContent) return layoutObserver = new ResizeObserver(updateBodyHeight) const header = card.querySelector('.n-card-header') const footer = card.querySelector('.n-card__footer') if (header) layoutObserver.observe(header) if (footer) layoutObserver.observe(footer) + layoutObserver.observe(scrollContent) }, { flush: 'post' }) onMounted(() => window.addEventListener('resize', updateBodyHeight)) onBeforeUnmount(() => { @@ -57,7 +62,7 @@ onBeforeUnmount(() => { role="dialog" :aria-label="title" > - +