Files
role-admin/src/components/DigitalMessageText.vue
T
湛兮 5dc709865a feat(content): 增加对白与叙述排版预览
- DigitalMessageText.vue: 为角色预览与聊天记录提供统一的受限文本展示
- content.vue: 增加首次问候、备用开场、示例对白的实时预览与格式说明
- users.vue: 按相同规则展示角色聊天记录,保留用户纯文本
- digital-message-format.ts、tests、README.md: 同步前台格式实现、兼容用例与目录说明
2026-10-27 22:19:16 +08:00

80 lines
1.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
/** 角色编辑预览与聊天记录共用的受限文本展示,用户消息和 HTML 字面量均不作为标签解释。 */
import { computed } from "vue";
import { parseDigitalMessage } from "@/utils/digital-message-format";
const props = withDefaults(
defineProps<{
text: string;
role?: "assistant" | "user";
incomplete?: boolean;
}>(),
{ role: "assistant", incomplete: false }
);
const blocks = computed(() =>
parseDigitalMessage(props.text, props.incomplete)
);
</script>
<template>
<div
class="digital-message-text"
:class="{ 'is-prose': role === 'assistant' }"
>
<template v-if="role === 'assistant' && blocks.length">
<p
v-for="(block, index) in blocks"
:key="index"
:class="[
block.kind,
{
'is-latin':
/[A-Za-z]/.test(block.text) && !/[\u3400-\u9fff]/.test(block.text)
}
]"
>
<strong v-if="block.kind === 'dialogue'">{{ block.text }}</strong>
<template v-else>{{ block.text }}</template>
</p>
</template>
<template v-else>{{ text || "(未生成正文)" }}</template>
</div>
</template>
<style scoped>
.digital-message-text {
line-height: 1.9;
overflow-wrap: anywhere;
white-space: pre-wrap;
}
.is-prose {
white-space: normal;
}
.is-prose > p {
margin: 0;
white-space: pre-wrap;
}
.is-prose > p + p {
margin-top: 12px;
}
.dialogue {
color: var(--digital-dialogue-ink, var(--el-text-color-primary));
}
.dialogue strong {
font-weight: 600;
}
.narration {
color: var(--digital-narration-ink, var(--el-text-color-regular));
}
.narration.is-latin {
font-style: italic;
}
</style>