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
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { provide } from 'vue'
|
||||
import { useMessage } from 'naive-ui'
|
||||
import { actionMessageKey } from './useActionMessage'
|
||||
|
||||
/** 在应用消息层内取得实例,子页面和公共控件使用同一反馈区域。 */
|
||||
const message = useMessage()
|
||||
provide(actionMessageKey, message)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<slot />
|
||||
</template>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
import { h } from 'vue'
|
||||
import { NButton } from 'naive-ui'
|
||||
import { useActionMessage } from './useActionMessage'
|
||||
|
||||
/** 问题说明按需查看,页面不长期堆叠错误段落。 */
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 当前实际问题的中文说明。 */
|
||||
messages: string[]
|
||||
/** 操作按钮名称。 */
|
||||
label?: string
|
||||
/** 问题对应的反馈级别。 */
|
||||
type?: 'warning' | 'error' | 'info'
|
||||
}>(),
|
||||
{ label: '查看原因', type: 'warning' }
|
||||
)
|
||||
/** 统一使用应用的 Naive 消息层。 */
|
||||
const message = useActionMessage()
|
||||
|
||||
/** 点击后展示去重问题,不重新请求或生成内容。 */
|
||||
function showReasons() {
|
||||
const content = [...new Set(props.messages.map(item => item.trim()).filter(Boolean))].join(';')
|
||||
if (content)
|
||||
message?.[props.type](() => h('div', { class: 'max-w-[min(600px,calc(100vw-48px))] break-words' }, content), {
|
||||
duration: 7000,
|
||||
closable: true
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是按需查看问题说明的操作模块 -->
|
||||
<div v-if="messages.length" class="mt-3 flex items-center gap-2">
|
||||
<NButton text size="small" @click="showReasons">{{ label }}</NButton>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import FieldLabel from './FieldLabel.vue'
|
||||
import { NAlert, NButton } from 'naive-ui'
|
||||
|
||||
/** 只读诊断模块的展示参数。 */
|
||||
@@ -24,7 +25,7 @@ const emit = defineEmits<{ refresh: [] }>()
|
||||
<!-- 以下是只读诊断的标题、展开与手动刷新模块 -->
|
||||
<section class="workspace-panel text-xs leading-6" :aria-label="title">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<strong>{{ title }}</strong>
|
||||
<strong><FieldLabel :label="title" :description="description" /></strong>
|
||||
<div class="flex items-center gap-3">
|
||||
<NButton text size="small" :aria-label="`${open ? '收起' : '查看'}${title}`" @click="open = !open">
|
||||
{{ open ? '收起' : '查看' }}
|
||||
@@ -41,11 +42,10 @@ const emit = defineEmits<{ refresh: [] }>()
|
||||
</NButton>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="description" class="mt-1 text-muted">{{ description }}</p>
|
||||
<!-- 以下是读取状态、错误与实际诊断结果模块 -->
|
||||
<div v-if="open" class="mt-3">
|
||||
<NAlert v-if="error" type="error" :show-icon="false" role="alert">{{ error }}</NAlert>
|
||||
<p v-if="loading" class="text-muted" role="status">正在读取后端记录…</p>
|
||||
<p v-if="loading" class="text-muted" role="status">正在加载…</p>
|
||||
<slot v-else />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { inject, type InjectionKey } from 'vue'
|
||||
import type { MessageApi } from 'naive-ui'
|
||||
|
||||
/** 页面操作结果共用的 Naive Message 实例。 */
|
||||
export const actionMessageKey: InjectionKey<MessageApi> = Symbol('action-message')
|
||||
|
||||
/**
|
||||
* 读取应用提供的轻量反馈接口,独立使用组件时允许不提供消息层。
|
||||
* @returns 当前应用消息接口,没有消息层时返回 null
|
||||
*/
|
||||
export function useActionMessage() {
|
||||
return inject(actionMessageKey, null)
|
||||
}
|
||||
Reference in new issue
Block a user