feat(short-drama-agent-front): 新增拆解候选与质量修订
This commit is contained in:
1 parent
49ad08a63e
commit
3414cc8232
32 files changed
+2319
-454
No files matched your search
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { NButton } from 'naive-ui'
|
||||
import { computed, ref } from 'vue'
|
||||
import { NButton, NTabs, NTabPane } from 'naive-ui'
|
||||
import { AppDialog } from '../../../components/ui'
|
||||
import type { CreativeProfileInput } from '../types'
|
||||
import CreativeProfileSettings from './CreativeProfileSettings.vue'
|
||||
import QualityPolicySettings from './QualityPolicySettings.vue'
|
||||
|
||||
/** 项目全局配置弹窗参数。 */
|
||||
const props = defineProps<{
|
||||
@@ -20,28 +21,48 @@ const open = defineModel<boolean>('open', { default: false })
|
||||
const saving = ref(false)
|
||||
/** 配置表单实例,footer 调用表单自身的校验与保存入口。 */
|
||||
const form = ref<InstanceType<typeof CreativeProfileSettings> | null>(null)
|
||||
/** 项目级配置分类保持同一个弹窗与底栏。 */
|
||||
const tab = ref('generation')
|
||||
/** 质量策略表单实例。 */
|
||||
const qualityForm = ref<InstanceType<typeof QualityPolicySettings> | null>(null)
|
||||
/** 当前标签的独立保存入口,避免跨接口混合保存。 */
|
||||
const activeForm = computed(() => (tab.value === 'quality' ? qualityForm.value : form.value))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是项目图片与视频全局配置弹窗模块 -->
|
||||
<AppDialog v-model:open="open" title="项目全局配置" :busy="saving" wide>
|
||||
<template #description>设置项目画布、图片和视频生成模型,后续生成默认使用这里保存的配置。</template>
|
||||
<CreativeProfileSettings
|
||||
v-if="open"
|
||||
ref="form"
|
||||
:key="props.projectId"
|
||||
:project-id="props.projectId"
|
||||
:disabled="props.disabled"
|
||||
hide-actions
|
||||
@busy="saving = $event"
|
||||
@saved="emit('saved', $event)"
|
||||
/>
|
||||
<template #description>设置生成模型、画布与质量规则,后续制作使用已保存的项目配置。</template>
|
||||
<!-- 以下是生成配置与质量规则分类导航,保存期间禁止切换 -->
|
||||
<NTabs v-if="open" v-model:value="tab" type="line" size="small">
|
||||
<NTabPane name="generation" tab="生成配置" :disabled="saving" display-directive="show:lazy">
|
||||
<CreativeProfileSettings
|
||||
v-if="open"
|
||||
ref="form"
|
||||
:key="props.projectId"
|
||||
:project-id="props.projectId"
|
||||
:disabled="props.disabled"
|
||||
hide-actions
|
||||
@busy="saving = $event"
|
||||
@saved="emit('saved', $event)"
|
||||
/>
|
||||
</NTabPane>
|
||||
<NTabPane name="quality" tab="质量规则" :disabled="saving" display-directive="show:lazy">
|
||||
<QualityPolicySettings
|
||||
ref="qualityForm"
|
||||
:key="props.projectId"
|
||||
:project-id="props.projectId"
|
||||
:disabled="props.disabled"
|
||||
@busy="saving = $event"
|
||||
/>
|
||||
</NTabPane>
|
||||
</NTabs>
|
||||
<!-- 以下是固定底栏取消与保存配置模块 -->
|
||||
<template #footer>
|
||||
<NButton :disabled="saving" @click="open = false">取消</NButton>
|
||||
<NButton type="primary" :loading="saving" :disabled="!form?.canSave" @click="form?.save()"
|
||||
>保存配置</NButton
|
||||
>
|
||||
<NButton type="primary" :loading="saving" :disabled="!activeForm?.canSave" @click="activeForm?.save()">{{
|
||||
tab === 'quality' ? '保存质量规则' : '保存配置'
|
||||
}}</NButton>
|
||||
</template>
|
||||
</AppDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,234 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onScopeDispose, ref, watch } from 'vue'
|
||||
import { NButton, NCheckbox, NFormItem, NInput, NSelect } from 'naive-ui'
|
||||
import { projectsApi } from '../../projects/api'
|
||||
import { actionResourceOptions, policyDraft, policyIssue } from '../../projects/quality-policy'
|
||||
import type { ProjectQualityPolicy } from '../../projects/types'
|
||||
import { errorMessage } from '../../../lib/http'
|
||||
|
||||
/** 项目质量策略独立编辑表单。 */
|
||||
const props = defineProps<{
|
||||
/** 当前正式项目编号。 */
|
||||
projectId: string
|
||||
/** 项目有活动操作时禁止保存。 */
|
||||
disabled: boolean
|
||||
}>()
|
||||
/** 保存状态交给弹窗锁定关闭与标签切换。 */
|
||||
const emit = defineEmits<{ busy: [value: boolean]; saved: [] }>()
|
||||
/** 读取期间不以本地默认值覆盖服务端。 */
|
||||
const loading = ref(false)
|
||||
/** 保存状态。 */
|
||||
const saving = ref(false)
|
||||
/** 实际读取或保存错误。 */
|
||||
const error = ref('')
|
||||
/** 真实保存成功提示。 */
|
||||
const notice = ref('')
|
||||
/** 服务端策略的独立草稿。 */
|
||||
const policy = ref<ProjectQualityPolicy | null>(null)
|
||||
/** 模式选择不自动修改允许范围。 */
|
||||
const physicsOptions = [
|
||||
{ value: 'realistic', label: '写实物理' },
|
||||
{ value: 'stylized', label: '风格化表现' },
|
||||
{ value: 'fantasy', label: '幻想表现' }
|
||||
]
|
||||
/** 草稿校验错误。 */
|
||||
const issue = computed(() => (policy.value ? policyIssue(policy.value) : ''))
|
||||
/** 只有已读取真实策略且没有活动操作才允许提交。 */
|
||||
const canSave = computed(() => !!policy.value && !issue.value && !props.disabled && !loading.value && !saving.value)
|
||||
/** 规则文本仅做逐行编辑,空行不作为规则提交。 */
|
||||
const rulesText = ref('')
|
||||
/** 保留输入中的换行,仅在策略草稿中去除空白规则。 */
|
||||
watch(rulesText, value => {
|
||||
if (policy.value)
|
||||
policy.value.customRules = value
|
||||
.split('\n')
|
||||
.map(item => item.trim())
|
||||
.filter(Boolean)
|
||||
})
|
||||
/** 读取与保存使用递增版本隔离项目切换和组件卸载。 */
|
||||
let version = 0
|
||||
/** 当前读取的取消控制器。 */
|
||||
let controller: AbortController | undefined
|
||||
|
||||
/** 从真实接口读取完整策略,失败后提供重试。 */
|
||||
async function load() {
|
||||
const current = ++version
|
||||
const id = props.projectId
|
||||
controller?.abort()
|
||||
controller = new AbortController()
|
||||
policy.value = null
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
notice.value = ''
|
||||
try {
|
||||
const result = await projectsApi.qualityPolicy(id, controller.signal)
|
||||
if (current !== version) return
|
||||
if (result.projectId !== id) throw new Error('质量策略所属项目不一致,请重新读取。')
|
||||
policy.value = policyDraft(result.policy)
|
||||
rulesText.value = policy.value.customRules.join('\n')
|
||||
} catch (cause) {
|
||||
if (current === version) error.value = errorMessage(cause)
|
||||
} finally {
|
||||
if (current === version) loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 新增一项精确例外,必须填写主体和依据后才可保存。 */
|
||||
function addException() {
|
||||
if (!policy.value || props.disabled || saving.value) return
|
||||
const items = (policy.value.actionExceptions ??= [])
|
||||
if (items.length < 30)
|
||||
items.push({ code: 'action_resource_conflict', ownerRef: '', resource: 'left_hand', reason: '' })
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除当前草稿中的精确例外,保存前不改变后端。
|
||||
* @param index 例外在草稿中的位置
|
||||
*/
|
||||
function removeException(index: number) {
|
||||
policy.value?.actionExceptions?.splice(index, 1)
|
||||
}
|
||||
|
||||
/** 保存完整策略,保留项目和请求归属检查。 */
|
||||
async function save() {
|
||||
if (!canSave.value || !policy.value) return
|
||||
const id = props.projectId
|
||||
const current = version
|
||||
const input = policyDraft(policy.value)
|
||||
saving.value = true
|
||||
error.value = ''
|
||||
notice.value = ''
|
||||
try {
|
||||
const result = await projectsApi.saveQualityPolicy(id, input)
|
||||
if (current !== version) return
|
||||
if (result.projectId !== id) throw new Error('质量策略保存回执所属项目不一致。')
|
||||
policy.value = policyDraft(result.policy)
|
||||
rulesText.value = policy.value.customRules.join('\n')
|
||||
notice.value = '质量策略已保存,后续创作、拆解和生成使用此策略。'
|
||||
emit('saved')
|
||||
} catch (cause) {
|
||||
if (current === version) error.value = errorMessage(cause)
|
||||
} finally {
|
||||
if (current === version) saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => props.projectId, load, { immediate: true })
|
||||
watch(saving, value => emit('busy', value), { flush: 'sync' })
|
||||
onScopeDispose(() => {
|
||||
version++
|
||||
controller?.abort()
|
||||
})
|
||||
/** 弹窗底栏复用同一个保存入口。 */
|
||||
defineExpose({ save, canSave })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是质量策略读取反馈模块 -->
|
||||
<div class="quality-policy-settings">
|
||||
<p v-if="loading" role="status" class="text-sm text-muted">正在读取项目质量策略……</p>
|
||||
<div v-if="error" role="alert" class="flex flex-wrap items-center gap-3 text-sm text-danger">
|
||||
<span>{{ error }}</span
|
||||
><NButton v-if="!policy" text @click="load">重新读取</NButton>
|
||||
</div>
|
||||
<template v-if="policy">
|
||||
<!-- 以下是物理表现与明确动作许可模块 -->
|
||||
<section class="space-y-4" aria-label="动作与物理规则">
|
||||
<div>
|
||||
<h3 class="text-sm font-medium">动作与物理规则</h3>
|
||||
<p class="mt-2 text-xs leading-6 text-muted">
|
||||
选择表现方式后,仍需明确勾选允许的动作范围。保存不会重新生成已有资产。
|
||||
</p>
|
||||
</div>
|
||||
<NFormItem label="物理表现方式" :label-props="{ id: 'quality-physics-mode-label' }">
|
||||
<NSelect
|
||||
v-model:value="policy.physicsMode"
|
||||
aria-labelledby="quality-physics-mode-label"
|
||||
:options="physicsOptions"
|
||||
:disabled="disabled || saving"
|
||||
/>
|
||||
</NFormItem>
|
||||
<div class="grid gap-4 sm:grid-cols-3">
|
||||
<NCheckbox v-model:checked="policy.allowExaggeratedMotion" :disabled="disabled || saving"
|
||||
>允许夸张动作</NCheckbox
|
||||
>
|
||||
<NCheckbox v-model:checked="policy.allowNonPhysicalActions" :disabled="disabled || saving"
|
||||
>允许非物理动作</NCheckbox
|
||||
>
|
||||
<NCheckbox v-model:checked="policy.allowSupernaturalAbilities" :disabled="disabled || saving"
|
||||
>允许超自然能力</NCheckbox
|
||||
>
|
||||
</div>
|
||||
</section>
|
||||
<!-- 以下是逐行声明的自定义规则模块 -->
|
||||
<NFormItem label="自定义规则" :label-props="{ for: 'quality-custom-rules' }">
|
||||
<NInput
|
||||
v-model:value="rulesText"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 3, maxRows: 8 }"
|
||||
:input-props="{ id: 'quality-custom-rules' }"
|
||||
placeholder="每行一条,最多 30 条;请写明具体允许的例外"
|
||||
:disabled="disabled || saving"
|
||||
/>
|
||||
</NFormItem>
|
||||
<!-- 以下是主体和具体动作资源的精确例外模块 -->
|
||||
<section class="space-y-4" aria-label="精确动作例外">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<h3 class="text-sm font-medium">精确动作例外</h3>
|
||||
<NButton
|
||||
size="small"
|
||||
:disabled="disabled || saving || (policy.actionExceptions?.length ?? 0) >= 30"
|
||||
@click="addException"
|
||||
>添加例外</NButton
|
||||
>
|
||||
</div>
|
||||
<p class="text-xs leading-6 text-muted">仅对填写的主体与资源放宽动作资源冲突,需记录明确依据。</p>
|
||||
<div v-for="(item, index) in policy.actionExceptions" :key="index" class="quality-exception-row">
|
||||
<NFormItem label="主体引用"
|
||||
><NInput
|
||||
v-model:value="item.ownerRef"
|
||||
:aria-label="`例外 ${index + 1} 主体引用`"
|
||||
placeholder="填写镜头中的主体引用"
|
||||
:disabled="disabled || saving"
|
||||
/></NFormItem>
|
||||
<NFormItem label="动作资源"
|
||||
><NSelect
|
||||
v-model:value="item.resource"
|
||||
:aria-label="`例外 ${index + 1} 动作资源`"
|
||||
:options="actionResourceOptions"
|
||||
:disabled="disabled || saving"
|
||||
/></NFormItem>
|
||||
<NFormItem label="确认依据"
|
||||
><NInput
|
||||
v-model:value="item.reason"
|
||||
:aria-label="`例外 ${index + 1} 确认依据`"
|
||||
:disabled="disabled || saving"
|
||||
/></NFormItem>
|
||||
<NButton :disabled="disabled || saving" @click="removeException(index)">移除</NButton>
|
||||
</div>
|
||||
</section>
|
||||
<p v-if="issue" role="status" class="text-xs leading-6 text-danger">{{ issue }}</p>
|
||||
</template>
|
||||
<p v-if="notice" role="status" class="text-xs leading-6 text-muted">{{ notice }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.quality-policy-settings {
|
||||
display: grid;
|
||||
gap: 24px;
|
||||
padding-top: 20px;
|
||||
}
|
||||
.quality-exception-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(120px, 1fr) minmax(100px, 0.7fr) minmax(160px, 1.5fr) auto;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.quality-exception-row {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user