feat: 同步精简接口并统一表单校验

This commit is contained in:
GJ committed 2026-09-10 22:34:47 +08:00
1 parent 82d7bde631
commit 2eea0ea72e
66 files changed
+1611 -1100

No files matched your search

@@ -1,4 +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 DetailDisclosure from '../../../components/ui/DetailDisclosure.vue'
import { NButton, NCheckbox, NInput, NTag } from 'naive-ui'
import { computed, reactive, ref, watch } from 'vue'
@@ -18,16 +21,6 @@ const form = reactive({
})
const baseline = ref('')
const dirty = computed(() => JSON.stringify(form) !== baseline.value)
const constraintsError = computed(() => {
try {
const value: unknown = JSON.parse(form.constraints)
return Array.isArray(value) && value.every(item => typeof item === 'string')
? ''
: '硬约束须为字符串数组,例如 ["真人写实", "禁止二次元"]。'
} catch {
return '硬约束 JSON 格式不正确,请修正后保存。'
}
})
watch(
() => props.visualStyle,
value => {
@@ -49,7 +42,7 @@ watch(dirty, value => emit('dirty', value), { immediate: true })
/** 显式校验 JSON 后保存结构化约束;不对错误结构做静默转换。 */
function save() {
if (props.disabled || constraintsError.value) return
if (props.disabled) return
emit('save', {
name: form.name.trim(),
prompt: form.prompt,
@@ -60,21 +53,28 @@ function save() {
isLocked: form.isLocked
})
}
const rules = { constraints: stringArrayJsonRule }
const constraintsDetails = ref<InstanceType<typeof DetailDisclosure> | null>(null)
</script>
<template>
<form class="panel p-5 sm:p-6" @submit.prevent="save">
<AppForm
:model="form"
:rules="rules"
:disabled="disabled"
class="panel p-5 sm:p-6"
@invalid="constraintsDetails?.expand()"
@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>
<label class="block"
><span class="field-label">风格名称</span
<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
></label>
<label class="block"
><span class="field-label">整体视觉语言</span
></NFormItem>
<NFormItem class="block" path="prompt" label="整体视觉语言" :label-props="{ for: 'style-prompt' }"
><NInput
:disabled="disabled"
placeholder="媒介、真实感、色彩和整体美术方向"
@@ -84,12 +84,12 @@ function save() {
type="textarea"
:autosize="{ minRows: 3, maxRows: 12 }"
></NInput>
</label>
<DetailDisclosure title="分类风格与硬约束"
</NFormItem>
<DetailDisclosure ref="constraintsDetails" display-directive="show" title="分类风格与硬约束"
><div class="grid gap-5 lg:grid-cols-3">
<label
><span class="field-label">人物风格与选角背景</span
<NFormItem path="characterPrompt" label="人物风格与选角背景"
><NInput
:input-props="{ 'aria-label': '人物风格与选角背景' }"
:disabled="disabled"
placeholder="人物质感、妆造与默认选角背景;留空时 AI 默认采用中国人物基线"
class="min-h-32"
@@ -97,30 +97,33 @@ function save() {
type="textarea"
:autosize="{ minRows: 3, maxRows: 12 }"
></NInput>
</label>
<label
><span class="field-label">场景风格补充</span
</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>
</label>
<label
><span class="field-label">道具风格补充</span
</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>
</label>
</NFormItem>
</div>
<label class="mt-4 block"
><span class="field-label">硬约束 · JSON 字符串数组</span
<NFormItem
class="mt-4 block"
path="constraints"
label="硬约束 · JSON 字符串数组"
:label-props="{ for: 'style-constraints' }"
><NInput
:disabled="disabled"
spellcheck="false"
@@ -130,9 +133,8 @@ function save() {
type="textarea"
:autosize="{ minRows: 3, maxRows: 12 }"
></NInput>
</label>
</NFormItem>
</DetailDisclosure>
<p v-if="constraintsError" class="text-xs text-danger" role="alert">{{ constraintsError }}</p>
<NCheckbox
:disabled="disabled"
id="style-lock"
@@ -144,10 +146,8 @@ function save() {
锁定后仍可人工编辑并保存。取消勾选并保存后,才能再次使用 AI 重生成。
</p>
<div class="flex justify-end">
<NButton :disabled="disabled || !!constraintsError" type="primary" attr-type="submit">
保存视觉风格
</NButton>
<NButton :disabled="disabled" type="primary" attr-type="submit"> 保存视觉风格 </NButton>
</div>
</fieldset>
</form>
</AppForm>
</template>