feat(short-drama-agent-front): 完善质量规则确认与中文交互

This commit is contained in:
GJ committed 2026-10-17 22:09:28 +08:00
1 parent 190333d4f9
commit c4b43b9725
85 files changed
+2059 -480

No files matched your search

@@ -1,8 +1,7 @@
<script setup lang="ts">
import AppForm from '../../../components/ui/AppForm.vue'
import { NFormItem } from 'naive-ui'
import { stringArrayJsonRule } from '../../../lib/form-rules'
import { NButton, NCheckbox, NInput, NTag } from 'naive-ui'
import { NButton, NCheckbox, NCollapse, NCollapseItem, NInput, NTag } from 'naive-ui'
import { computed, reactive, ref, watch } from 'vue'
import type { SaveVisualStyleInput, VisualStyle } from '../types'
@@ -21,24 +20,33 @@ const form = reactive({
characterPrompt: '',
scenePrompt: '',
propPrompt: '',
constraints: '[]',
constraints: '',
isLocked: false
})
/** 上次成功读取的表单快照,用于识别未保存修改。 */
const baseline = ref('')
/** 已保存的要求原样保留,避免未编辑时拆开原有段落或丢失旧格式。 */
const savedConstraints = ref<unknown>([])
/** 与原始要求对应的文本,用于识别用户是否主动修改。 */
let savedConstraintsText = ''
/** 非文字列表的旧格式只读保留,不能用空白编辑器覆盖。 */
const legacyConstraints = ref(false)
/** 草稿变更时禁止 AI 覆盖现有输入。 */
const dirty = computed(() => JSON.stringify(form) !== baseline.value)
watch(
() => props.visualStyle,
value => {
if (baseline.value && dirty.value) return
savedConstraints.value = JSON.parse(JSON.stringify(value?.hardConstraints ?? []))
legacyConstraints.value = !Array.isArray(savedConstraints.value) || !savedConstraints.value.every(item => typeof item === 'string')
savedConstraintsText = legacyConstraints.value ? '' : (savedConstraints.value as string[]).join('\n')
Object.assign(form, {
name: value?.name ?? '默认视觉风格',
prompt: value?.prompt ?? '',
characterPrompt: value?.characterPrompt ?? '',
scenePrompt: value?.scenePrompt ?? '',
propPrompt: value?.propPrompt ?? '',
constraints: JSON.stringify(value?.hardConstraints ?? [], null, 2),
constraints: savedConstraintsText,
isLocked: value?.isLocked ?? false
})
baseline.value = JSON.stringify(form)
@@ -47,7 +55,7 @@ watch(
)
watch(dirty, value => emit('dirty', value), { immediate: true })
/** 显式校验 JSON 后保存结构化约束;不对错误结构做静默转换。 */
/** 每行一条的画面要求仍保存为原有文字列表,未编辑和旧格式内容原样保留。 */
function save() {
if (props.disabled) return
emit('save', {
@@ -56,15 +64,16 @@ function save() {
characterPrompt: form.characterPrompt,
scenePrompt: form.scenePrompt,
propPrompt: form.propPrompt,
hardConstraints: JSON.parse(form.constraints) as string[],
hardConstraints: legacyConstraints.value || form.constraints === savedConstraintsText
? savedConstraints.value
: form.constraints.split('\n').map(item => item.trim()).filter(Boolean),
isLocked: form.isLocked
})
}
const rules = { constraints: stringArrayJsonRule }
</script>
<template>
<AppForm :model="form" :rules="rules" :disabled="disabled" class="panel workspace-panel" @submit="save">
<AppForm :model="form" :disabled="disabled" class="panel workspace-panel" @submit="save">
<fieldset :disabled="disabled" class="space-y-5">
<div class="flex flex-wrap items-center justify-between gap-3">
<h3 class="font-medium">风格说明</h3>
@@ -86,7 +95,7 @@ const rules = { constraints: stringArrayJsonRule }
</NFormItem>
<!-- 以下是始终展开的分类风格模块,人物、场景、道具各占一行 -->
<section class="style-category-section" aria-labelledby="style-category-heading">
<h3 id="style-category-heading" class="font-medium mb-5">分类风格与硬约束</h3>
<h3 id="style-category-heading" class="font-medium mb-5">分类风格与画面要求</h3>
<div class="style-category-fields grid grid-cols-1 gap-5">
<NFormItem path="characterPrompt" label="人物风格与选角背景"
><NInput
@@ -123,19 +132,23 @@ const rules = { constraints: stringArrayJsonRule }
<NFormItem
class="mt-4 block"
path="constraints"
label="硬约束 · JSON 字符串数组"
label="必须遵守的画面要求"
:label-props="{ for: 'style-constraints' }"
><NInput
:disabled="disabled"
:disabled="disabled || legacyConstraints"
spellcheck="false"
:input-props="{ id: 'style-constraints' }"
class="min-h-24 font-mono text-xs"
class="min-h-24"
placeholder="每行一条,例如:只使用古代服装"
v-model:value="form.constraints"
type="textarea"
:autosize="{ minRows: 3, maxRows: 12 }"
></NInput>
</NFormItem>
</section>
<!-- 以下是要求填写说明;旧格式只读核对,不在普通编辑时丢失内容 -->
<p class="text-xs leading-6 text-muted">每行填写一条画面要求,留空表示没有补充要求。</p>
<NCollapse v-if="legacyConstraints"><NCollapseItem name="legacy-rules" title="查看已有要求(高级)"><p class="text-xs leading-6 text-muted">已有要求使用旧格式,保存风格时会原样保留。</p><pre class="whitespace-pre-wrap break-words text-xs">{{ JSON.stringify(savedConstraints, null, 2) }}</pre></NCollapseItem></NCollapse>
<NCheckbox
:disabled="disabled"
id="style-lock"