fix(short-drama-agent-front): 优化工作区提示与弹窗布局
This commit is contained in:
1 parent
5b134207b8
commit
72a86171dc
35 files changed
+586
-378
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { NModal, NScrollbar } from 'naive-ui'
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
|
||||
/** 公共弹窗的标题、说明、操作状态和宽度。 */
|
||||
withDefaults(
|
||||
@@ -18,55 +18,61 @@ withDefaults(
|
||||
)
|
||||
/** 弹窗显隐状态,关闭行为由 Naive 管理。 */
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
/** 正文测量锚点,不包含固定 header 与 footer。 */
|
||||
const bodyAnchor = ref<HTMLElement | null>(null)
|
||||
/** 可用正文滚动高度。 */
|
||||
const bodyHeight = ref(0)
|
||||
/** 正文容器隔离子元素外边距,保留完整的自然内容高度。 */
|
||||
const bodyContent = ref<HTMLElement | null>(null)
|
||||
/** 正文最大可用高度;未挂载时不限制自然高度。 */
|
||||
const maxBodyHeight = ref<number | undefined>(undefined)
|
||||
/** 监听正文和固定区域的尺寸变化,适配异步内容与换行。 */
|
||||
let layoutObserver: ResizeObserver | undefined
|
||||
|
||||
/** 正文使用内容高度与剩余视口高度的较小值,扣除固定标题、说明与 footer。 */
|
||||
/** 扣除视口上下间距、标题、底栏、正文内边距和边框,只限制正文最大高度。 */
|
||||
function updateBodyHeight() {
|
||||
const card = bodyAnchor.value?.closest('.app-dialog')
|
||||
const scrollContent = bodyAnchor.value?.parentElement
|
||||
if (!card || !scrollContent) return
|
||||
const card = bodyContent.value?.closest('.app-dialog')
|
||||
if (!card) return
|
||||
const header = card.querySelector<HTMLElement>('.n-card-header')
|
||||
const footer = card.querySelector<HTMLElement>('.n-card__footer')
|
||||
const content = card.querySelector<HTMLElement>('.n-card-content')
|
||||
const contentStyle = content ? getComputedStyle(content) : null
|
||||
const available = Math.max(
|
||||
const cardStyle = getComputedStyle(card)
|
||||
maxBodyHeight.value = Math.max(
|
||||
0,
|
||||
window.innerHeight -
|
||||
(window.visualViewport?.height ?? window.innerHeight) -
|
||||
32 -
|
||||
(header?.offsetHeight ?? 0) -
|
||||
(footer?.offsetHeight ?? 0) -
|
||||
(contentStyle ? parseFloat(contentStyle.paddingTop) + parseFloat(contentStyle.paddingBottom) : 0) -
|
||||
2
|
||||
parseFloat(cardStyle.borderTopWidth) -
|
||||
parseFloat(cardStyle.borderBottomWidth)
|
||||
)
|
||||
bodyHeight.value = Math.min(scrollContent.scrollHeight, available)
|
||||
}
|
||||
watch(
|
||||
open,
|
||||
async shown => {
|
||||
[open, bodyContent],
|
||||
([shown]) => {
|
||||
layoutObserver?.disconnect()
|
||||
if (!shown) return
|
||||
await nextTick()
|
||||
if (!shown) {
|
||||
maxBodyHeight.value = undefined
|
||||
return
|
||||
}
|
||||
updateBodyHeight()
|
||||
const card = bodyAnchor.value?.closest('.app-dialog')
|
||||
const scrollContent = bodyAnchor.value?.parentElement
|
||||
if (!card || !scrollContent) return
|
||||
const card = bodyContent.value?.closest('.app-dialog')
|
||||
if (!card || !bodyContent.value) 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)
|
||||
layoutObserver.observe(bodyContent.value)
|
||||
},
|
||||
{ flush: 'post', immediate: true }
|
||||
)
|
||||
onMounted(() => window.addEventListener('resize', updateBodyHeight))
|
||||
onMounted(() => {
|
||||
window.addEventListener('resize', updateBodyHeight)
|
||||
window.visualViewport?.addEventListener('resize', updateBodyHeight)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
layoutObserver?.disconnect()
|
||||
window.removeEventListener('resize', updateBodyHeight)
|
||||
window.visualViewport?.removeEventListener('resize', updateBodyHeight)
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -92,10 +98,12 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 以下是弹窗正文滚动模块 -->
|
||||
<NScrollbar class="dialog-body-scroll" :style="{ height: bodyHeight + 'px' }">
|
||||
<span ref="bodyAnchor" class="dialog-body-anchor" aria-hidden="true" />
|
||||
<slot />
|
||||
<!-- 以下是自然高度正文模块,仅超过剩余视口高度时滚动 -->
|
||||
<NScrollbar
|
||||
class="dialog-body-scroll"
|
||||
:style="{ height: 'auto', maxHeight: maxBodyHeight === undefined ? undefined : maxBodyHeight + 'px' }"
|
||||
>
|
||||
<div ref="bodyContent" class="flow-root"><slot /></div>
|
||||
</NScrollbar>
|
||||
<template v-if="$slots.footer" #footer>
|
||||
<div class="dialog-footer"><slot name="footer" /></div>
|
||||
@@ -118,7 +126,7 @@ onBeforeUnmount(() => {
|
||||
.app-dialog .n-card-header {
|
||||
@apply shrink-0 items-start;
|
||||
}
|
||||
/* 正文容器可收缩,滚动高度由内容与剩余视口共同确定。 */
|
||||
/* 正文自然撑开,超过剩余视口高度后由 NScrollbar 内部滚动。 */
|
||||
.app-dialog .n-card-content {
|
||||
@apply min-h-0 overflow-hidden;
|
||||
display: block;
|
||||
@@ -128,17 +136,6 @@ onBeforeUnmount(() => {
|
||||
@apply min-h-0;
|
||||
}
|
||||
|
||||
/* 仅隐藏 NScrollbar 的视觉滚动条,不影响鼠标滚轮、触控板与内容拖动滚动。 */
|
||||
.dialog-body-anchor {
|
||||
display: block;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.dialog-body-scroll.n-scrollbar .n-scrollbar-rail {
|
||||
opacity: 0 !important;
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
.app-dialog .n-card-header__close {
|
||||
@apply grid place-items-center w-10 h-10 -m-2 rounded-none bg-transparent;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user