feat(short-drama-agent-front): 完善镜头定位与项目配置
This commit is contained in:
1 parent
470b52e26d
commit
5b134207b8
66 files changed
+2042
-984
No files matched your search
@@ -2,14 +2,29 @@
|
||||
import { NModal, NScrollbar } from 'naive-ui'
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
|
||||
/** Naive UI 管理焦点锁定、Esc、遮罩与主题;长弹窗只滚动内部正文。 */
|
||||
defineProps<{ title: string; description: string; busy?: boolean; wide?: boolean }>()
|
||||
/** 公共弹窗的标题、说明、操作状态和宽度。 */
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
/** 弹窗标题,同时作为可访问名称。 */
|
||||
title: string
|
||||
/** 标题下的默认说明,可使用 description slot 覆盖。 */
|
||||
description?: string
|
||||
/** 提交期间锁定关闭操作。 */
|
||||
busy?: boolean
|
||||
/** 使用宽弹窗布局。 */
|
||||
wide?: boolean
|
||||
}>(),
|
||||
{ description: '', busy: false, wide: false }
|
||||
)
|
||||
/** 弹窗显隐状态,关闭行为由 Naive 管理。 */
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
/** 正文测量锚点,不包含固定 header 与 footer。 */
|
||||
const bodyAnchor = ref<HTMLElement | null>(null)
|
||||
/** 可用正文滚动高度。 */
|
||||
const bodyHeight = ref(0)
|
||||
let layoutObserver: ResizeObserver | undefined
|
||||
|
||||
/** 正文使用内容高度与剩余视口高度的较小值;为 NScrollbar 提供明确滚动高度。 */
|
||||
/** 正文使用内容高度与剩余视口高度的较小值,扣除固定标题、说明与 footer。 */
|
||||
function updateBodyHeight() {
|
||||
const card = bodyAnchor.value?.closest('.app-dialog')
|
||||
const scrollContent = bodyAnchor.value?.parentElement
|
||||
@@ -20,27 +35,34 @@ function updateBodyHeight() {
|
||||
const contentStyle = content ? getComputedStyle(content) : null
|
||||
const available = Math.max(
|
||||
0,
|
||||
window.innerHeight - 32 - (header?.offsetHeight ?? 0) - (footer?.offsetHeight ?? 0)
|
||||
- (contentStyle ? parseFloat(contentStyle.paddingTop) + parseFloat(contentStyle.paddingBottom) : 0)
|
||||
- 2
|
||||
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()
|
||||
if (!shown) return
|
||||
await nextTick()
|
||||
updateBodyHeight()
|
||||
const card = bodyAnchor.value?.closest('.app-dialog')
|
||||
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' })
|
||||
watch(
|
||||
open,
|
||||
async shown => {
|
||||
layoutObserver?.disconnect()
|
||||
if (!shown) return
|
||||
await nextTick()
|
||||
updateBodyHeight()
|
||||
const card = bodyAnchor.value?.closest('.app-dialog')
|
||||
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', immediate: true }
|
||||
)
|
||||
onMounted(() => window.addEventListener('resize', updateBodyHeight))
|
||||
onBeforeUnmount(() => {
|
||||
layoutObserver?.disconnect()
|
||||
@@ -53,7 +75,6 @@ onBeforeUnmount(() => {
|
||||
<NModal
|
||||
v-model:show="open"
|
||||
preset="card"
|
||||
:title="title"
|
||||
:closable="!busy"
|
||||
:mask-closable="!busy"
|
||||
:close-on-esc="!busy"
|
||||
@@ -62,9 +83,18 @@ onBeforeUnmount(() => {
|
||||
role="dialog"
|
||||
:aria-label="title"
|
||||
>
|
||||
<!-- 以下是固定标题与说明模块,说明位于标题下并可自定义 -->
|
||||
<template #header>
|
||||
<div class="min-w-0">
|
||||
<div class="text-lg font-semibold">{{ title }}</div>
|
||||
<div v-if="description || $slots.description" class="mt-[2px] text-sm leading-6 font-normal text-muted">
|
||||
<slot name="description">{{ description }}</slot>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 以下是弹窗正文滚动模块 -->
|
||||
<NScrollbar class="dialog-body-scroll" :style="{ height: bodyHeight + 'px' }">
|
||||
<span ref="bodyAnchor" class="dialog-body-anchor" aria-hidden="true" />
|
||||
<p v-if="description" class="text-sm leading-6 text-muted">{{ description }}</p>
|
||||
<slot />
|
||||
</NScrollbar>
|
||||
<template v-if="$slots.footer" #footer>
|
||||
@@ -86,9 +116,8 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
|
||||
.app-dialog .n-card-header {
|
||||
@apply shrink-0;
|
||||
@apply shrink-0 items-start;
|
||||
}
|
||||
|
||||
/* 正文容器可收缩,滚动高度由内容与剩余视口共同确定。 */
|
||||
.app-dialog .n-card-content {
|
||||
@apply min-h-0 overflow-hidden;
|
||||
|
||||
Reference in new issue
Block a user