182 lines
8.7 KiB
Vue
182 lines
8.7 KiB
Vue
<script setup lang="ts">
|
||
import AppForm from '../../../components/ui/AppForm.vue'
|
||
import { NFormItem } 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'
|
||
|
||
/** 编辑草稿独立于轮询结果,刷新不会覆盖尚未保存的输入。 */
|
||
const props = defineProps<{
|
||
visualStyle: VisualStyle | null
|
||
disabled: boolean
|
||
/** 当前表单保存请求。 */ saving?: boolean
|
||
}>()
|
||
/** 保存校验后的风格配置,并向父页面同步草稿状态。 */
|
||
const emit = defineEmits<{ save: [input: SaveVisualStyleInput]; dirty: [value: boolean] }>()
|
||
/** 整体风格、分类补充和硬约束保持在同一份编辑草稿中。 */
|
||
const form = reactive({
|
||
name: '',
|
||
prompt: '',
|
||
characterPrompt: '',
|
||
scenePrompt: '',
|
||
propPrompt: '',
|
||
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: savedConstraintsText,
|
||
isLocked: value?.isLocked ?? false
|
||
})
|
||
baseline.value = JSON.stringify(form)
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
watch(dirty, value => emit('dirty', value), { immediate: true })
|
||
|
||
/** 每行一条的画面要求仍保存为原有文字列表,未编辑和旧格式内容原样保留。 */
|
||
function save() {
|
||
if (props.disabled) return
|
||
emit('save', {
|
||
name: form.name.trim(),
|
||
prompt: form.prompt,
|
||
characterPrompt: form.characterPrompt,
|
||
scenePrompt: form.scenePrompt,
|
||
propPrompt: form.propPrompt,
|
||
hardConstraints:
|
||
legacyConstraints.value || form.constraints === savedConstraintsText
|
||
? savedConstraints.value
|
||
: form.constraints
|
||
.split('\n')
|
||
.map(item => item.trim())
|
||
.filter(Boolean),
|
||
isLocked: form.isLocked
|
||
})
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<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>
|
||
<NTag v-if="dirty" size="small" :bordered="false">有未保存修改</NTag>
|
||
</div>
|
||
<NFormItem class="block" path="name" label="风格名称" :label-props="{ for: 'style-name' }"
|
||
><NInput :disabled="disabled" :input-props="{ id: 'style-name' }" v-model:value="form.name"></NInput
|
||
></NFormItem>
|
||
<NFormItem class="block" path="prompt" label="整体视觉语言" :label-props="{ for: 'style-prompt' }"
|
||
><NInput
|
||
:disabled="disabled"
|
||
placeholder="媒介、真实感、色彩和整体美术方向"
|
||
:input-props="{ id: 'style-prompt' }"
|
||
class="min-h-32"
|
||
v-model:value="form.prompt"
|
||
type="textarea"
|
||
:autosize="{ minRows: 3, maxRows: 12 }"
|
||
></NInput>
|
||
</NFormItem>
|
||
<!-- 以下是始终展开的分类风格模块,人物、场景、道具各占一行 -->
|
||
<section class="style-category-section" aria-labelledby="style-category-heading">
|
||
<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
|
||
:input-props="{ 'aria-label': '人物风格与选角背景' }"
|
||
:disabled="disabled"
|
||
placeholder="人物质感、妆造与已明确的选角背景;未明确时保持地域与族裔中性"
|
||
class="min-h-32"
|
||
v-model:value="form.characterPrompt"
|
||
type="textarea"
|
||
:autosize="{ minRows: 3, maxRows: 12 }"
|
||
></NInput>
|
||
</NFormItem>
|
||
<NFormItem path="scenePrompt" label="场景风格补充"
|
||
><NInput
|
||
:input-props="{ 'aria-label': '场景风格补充' }"
|
||
:disabled="disabled"
|
||
class="min-h-32"
|
||
v-model:value="form.scenePrompt"
|
||
type="textarea"
|
||
:autosize="{ minRows: 3, maxRows: 12 }"
|
||
></NInput>
|
||
</NFormItem>
|
||
<NFormItem path="propPrompt" label="道具风格补充"
|
||
><NInput
|
||
:input-props="{ 'aria-label': '道具风格补充' }"
|
||
:disabled="disabled"
|
||
class="min-h-32"
|
||
v-model:value="form.propPrompt"
|
||
type="textarea"
|
||
:autosize="{ minRows: 3, maxRows: 12 }"
|
||
></NInput>
|
||
</NFormItem>
|
||
</div>
|
||
<NFormItem
|
||
class="mt-4 block"
|
||
path="constraints"
|
||
label="必须遵守的画面要求"
|
||
:label-props="{ for: 'style-constraints' }"
|
||
><NInput
|
||
:disabled="disabled || legacyConstraints"
|
||
spellcheck="false"
|
||
:input-props="{ id: 'style-constraints' }"
|
||
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"
|
||
v-model:checked="form.isLocked"
|
||
class="flex items-start gap-2 text-sm"
|
||
>确认并锁定风格,阻止后续 AI 自动覆盖</NCheckbox
|
||
>
|
||
<p class="text-xs leading-6 text-muted">
|
||
锁定后仍可人工编辑并保存。取消勾选并保存后,才能再次使用 AI 重生成。
|
||
</p>
|
||
<div class="page-form-actions">
|
||
<NButton :disabled="disabled" type="primary" attr-type="submit" :loading="saving">
|
||
保存视觉风格
|
||
</NButton>
|
||
</div>
|
||
</fieldset>
|
||
</AppForm>
|
||
</template>
|