Files
short-drama-agent-front/src/features/subject-identity/components/CastingCandidateDialog.vue
T

123 lines
5.3 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">
import { NAlert, NButton, NCheckbox, NFormItem, NInput } from 'naive-ui'
import { computed, ref, watch } from 'vue'
import { AppDialog } from '../../../components/ui'
import AppForm from '../../../components/ui/AppForm.vue'
import GenerationModelControls from '../../generation-config/components/GenerationModelControls.vue'
import type {
CreativeProfile,
GenerationModelCatalog,
GenerationOptions
} from '../../generation-config/types'
import type { GenerateCastingCandidateInput } from '../types'
/** Character 选角候选表单固定使用 primary,每次独立生成且不会自动选择演员。 */
const props = defineProps<{
subjectId: string
subjectName: string
disabled: boolean
catalog: GenerationModelCatalog
profile: CreativeProfile
}>()
const open = defineModel<boolean>('open', { default: false })
const emit = defineEmits<{ generate: [input: GenerateCastingCandidateInput] }>()
const prompt = ref('')
const provider = ref('')
const generationOptions = ref<GenerationOptions>({})
const acknowledged = ref(false)
const valid = computed(() => Boolean(provider.value))
/** 每次切换角色或重新打开都恢复项目当前图片模型与参数。 */
function reset() {
prompt.value = ''
provider.value = props.profile.imageProvider
const selected = props.catalog.images.find(item => item.provider === props.profile.imageProvider && item.enabled) ??
props.catalog.images.find(item => item.enabled)
provider.value = selected?.provider ?? ''
generationOptions.value = {
...selected?.defaults,
...(selected?.provider === props.profile.imageProvider ? props.profile.imageOptions : {})
}
const sizeSchema = selected?.generationOptions.find(item => item.key === 'size')
if (sizeSchema?.options?.length && !sizeSchema.options.some(option => option.value === generationOptions.value.size)) {
generationOptions.value.size = selected?.defaults.size ?? sizeSchema.options[0]?.value ?? ''
}
acknowledged.value = false
}
watch([() => props.subjectId, open, () => props.profile], reset, { immediate: true })
/** 候选生成显式携带当前图片 Provider 与动态参数,避免 Seedream 尺寸污染 Qwen。 */
function submit() {
if (props.disabled || !valid.value || !acknowledged.value) return
emit('generate', {
...(prompt.value.trim() ? { prompt: prompt.value.trim() } : {}),
provider: provider.value,
generationOptions: generationOptions.value
})
}
const formModel = computed(() => ({ prompt: prompt.value }))
</script>
<template>
<AppDialog v-model:open="open" title="生成角色选角候选" :description="`${subjectName} · 候选不会自动成为身份母版`">
<AppForm
:model="formModel"
:disabled="disabled"
:reset-key="`${open}:${subjectId}`"
validate-on-change
class="mt-5 space-y-4"
@submit="submit"
>
<NAlert type="info" :show-icon="false" class="text-xs">
后端会依据角色 Identity、项目视觉风格和默认选角约束独立生成一张 primary
候选,不会复用当前身份母版。生成完成后仍需人工点击“确认选角”。
</NAlert>
<NFormItem
class="block"
path="prompt"
label="覆盖本次完整提示词(可选)"
:label-props="{ for: 'casting-candidate-prompt' }"
>
<NInput
placeholder="建议留空,使用后端编译的稳定身份和选角约束;未明确人物背景时默认中国人物"
:input-props="{ id: 'casting-candidate-prompt' }"
class="min-h-24"
v-model:value="prompt"
type="textarea"
:autosize="{ minRows: 3, maxRows: 12 }"
></NInput>
</NFormItem>
<p v-if="prompt.trim()" class="text-xs text-danger">
自定义文本会替换后端完整提示词,请自行包含人物身份、基础服装和中性参考图要求。
</p>
<GenerationModelControls
type="image"
:catalog="catalog"
:provider="provider"
:options="generationOptions"
:aspect-ratio="profile.aspectRatio"
:disabled="disabled"
@update:provider="provider = $event"
@update:options="generationOptions = $event"
/>
<NCheckbox
id="casting-candidate-cost"
v-model:checked="acknowledged"
class="flex items-start gap-2 text-xs leading-6"
>我已确认调用图片模型可能产生费用,且当前没有同项目生成任务。
</NCheckbox>
<div class="dialog-footer">
<NButton @click="open = false">取消</NButton>
<NButton
:disabled="disabled || !valid || !acknowledged"
:loading="disabled"
type="primary"
attr-type="submit"
>
{{ disabled ? '生成中…' : '确认生成候选' }}
</NButton>
</div>
</AppForm>
</AppDialog>
</template>