feat(short-drama-agent-front): 完善镜头定位与项目配置

This commit is contained in:
GJ committed 2026-10-08 19:45:26 +08:00
1 parent 470b52e26d
commit 5b134207b8
66 files changed
+2042 -984

No files matched your search

@@ -10,43 +10,86 @@ import type {
GenerationModelItem,
GenerationOptions
} from '../types'
import { creativeProfileDraft, creativeProfileIssues } from '../profile-draft'
import { useProjectGenerationRevision } from '../context'
import GenerationOptionFields from './GenerationOptionFields.vue'
const props = defineProps<{ projectId: string }>()
const emit = defineEmits<{ saved: [profile: CreativeProfileInput] }>()
/** 项目配置表单参数。 */
const props = withDefaults(
defineProps<{
/** 当前项目 ID。 */
projectId: string
/** 弹窗由公共 footer 提供保存操作,隐藏表单自身操作区。 */
hideActions?: boolean
/** 有项目操作时禁止编辑和保存配置。 */
disabled?: boolean
}>(),
{ hideActions: false, disabled: false }
)
/** 保存后的实际配置与保存状态通知。 */
const emit = defineEmits<{ saved: [profile: CreativeProfileInput]; busy: [saving: boolean] }>()
/** 成功保存后通知当前项目生成表单更新默认值。 */
const revision = useProjectGenerationRevision()
/** 配置和模型目录读取状态。 */
const loading = ref(false)
/** 配置保存状态。 */
const saving = ref(false)
/** 读取或保存错误。 */
const error = ref('')
/** 真实保存结果提示。 */
const notice = ref('')
/** 后端支持的图片与视频模型目录。 */
const catalog = ref<GenerationModelCatalog | null>(null)
/** 当前项目的独立编辑草稿。 */
const profile = ref<CreativeProfileInput | null>(null)
/** 当前读取请求控制器。 */
let controller: AbortController | null = null
/** 组件销毁后忽略迟到保存响应,不更新新项目配置修订号。 */
let disposed = false
/** 项目画布支持的宽高比选项。 */
const aspectRatios = ['9:16', '16:9', '1:1', '4:3', '3:4'].map(value => ({ label: value, value }))
/** 当前可用的图片模型。 */
const enabledImages = computed(() => catalog.value?.images?.filter(item => item.enabled && item.model) ?? [])
/** 当前可用的视频模型。 */
const enabledVideos = computed(() => catalog.value?.videos?.filter(item => item.enabled && item.model) ?? [])
/** 当前图片模型的组合选项值。 */
const imageSelection = computed(() =>
profile.value ? selectionValue(profile.value.imageProvider, profile.value.imageModel) : null
)
/** 当前视频模型的组合选项值。 */
const videoSelection = computed(() =>
profile.value ? selectionValue(profile.value.videoProvider, profile.value.videoModel) : null
)
/** 图片模型对应的参数 schema。 */
const imageModel = computed(() =>
enabledImages.value.find(item =>
profile.value ? item.provider === profile.value.imageProvider && item.model === profile.value.imageModel : false
)
)
/** 视频模型对应的参数 schema。 */
const videoModel = computed(() =>
enabledVideos.value.find(item =>
profile.value ? item.provider === profile.value.videoProvider && item.model === profile.value.videoModel : false
)
)
/**
* 组合供应方与模型,避免同名模型混淆。
* @param provider 模型供应方
* @param model 模型名称
* @returns 下拉选项唯一值
*/
function selectionValue(provider: string, model: string) {
return `${provider}\u0000${model}`
}
/**
* 将实际模型目录转成下拉选项。
* @param items 当前媒介模型列表
* @returns 模型下拉选项
*/
function modelOptions(items: GenerationModelItem[]) {
return items.map(item => ({
label: `${item.providerLabel} · ${item.modelLabel}`,
@@ -54,6 +97,11 @@ function modelOptions(items: GenerationModelItem[]) {
}))
}
/**
* 依据目标模型 schema 创建合法初始参数。
* @param item 当前模型
* @returns 模型初始参数
*/
function defaultOptions(item: GenerationModelItem): GenerationOptions {
return Object.fromEntries(
item.generationOptions.flatMap(schema => {
@@ -75,22 +123,11 @@ function defaultOptions(item: GenerationModelItem): GenerationOptions {
)
}
/** 把历史 Profile 中已不属于当前模型 Schema 的参数收敛为当前模型默认值。 */
function normalizeSavedOptions(item: GenerationModelItem | undefined, saved: GenerationOptions): GenerationOptions {
if (!item) return { ...saved }
const defaults = defaultOptions(item)
const normalized = { ...saved }
for (const schema of item.generationOptions) {
const value = normalized[schema.key]
if (schema.type !== 'size' || typeof value !== 'string' || !schema.options?.length) continue
if (schema.options.some(option => option.value === value)) continue
const fallback = defaults[schema.key]
if (fallback !== undefined) normalized[schema.key] = fallback
else delete normalized[schema.key]
}
return normalized
}
/**
* 切换模型时清空上一模型参数。
* @param type 图片或视频媒介
* @param value 下拉选项唯一值
*/
function selectModel(type: 'image' | 'video', value: string) {
if (!profile.value) return
const items = type === 'image' ? enabledImages.value : enabledVideos.value
@@ -107,6 +144,11 @@ function selectModel(type: 'image' | 'video', value: string) {
}
}
/**
* 未配置项目使用后端可用默认模型初始化草稿。
* @param nextCatalog 当前模型目录
* @returns 初始项目配置,无完整模型时返回 null
*/
function createInitial(nextCatalog: GenerationModelCatalog): CreativeProfileInput | null {
const image =
nextCatalog.images.find(item => item.enabled && item.isDefault && item.model) ??
@@ -126,139 +168,153 @@ function createInitial(nextCatalog: GenerationModelCatalog): CreativeProfileInpu
}
}
/** 读取实际目录与项目配置,取消旧目标请求并忽略迟到响应。 */
async function load() {
controller?.abort()
controller = new AbortController()
const signal = controller.signal
const projectId = props.projectId
profile.value = null
catalog.value = null
loading.value = true
error.value = ''
notice.value = ''
try {
const [nextCatalog, saved] = await Promise.all([
generationConfigApi.catalog(controller.signal),
generationConfigApi.profile(props.projectId, controller.signal)
generationConfigApi.catalog(signal),
generationConfigApi.profile(projectId, signal)
])
if (signal.aborted || props.projectId !== projectId) return
if (saved && saved.projectId !== projectId) throw new Error('项目配置返回了不匹配的项目。')
catalog.value = nextCatalog
const savedImageModel = saved
? nextCatalog.images.find(
item => item.provider === saved.imageProvider && item.model === saved.imageModel
)
: undefined
const savedVideoModel = saved
? nextCatalog.videos.find(
item => item.provider === saved.videoProvider && item.model === saved.videoModel
)
: undefined
profile.value = saved
? {
aspectRatio: saved.aspectRatio,
imageProvider: saved.imageProvider,
imageModel: saved.imageModel,
imageOptions: normalizeSavedOptions(savedImageModel, saved.imageOptions),
videoProvider: saved.videoProvider,
videoModel: saved.videoModel,
videoOptions: normalizeSavedOptions(savedVideoModel, saved.videoOptions)
}
: createInitial(nextCatalog)
profile.value = saved ? creativeProfileDraft(saved) : createInitial(nextCatalog)
} catch (cause) {
if (!controller.signal.aborted) error.value = errorMessage(cause)
if (!signal.aborted && props.projectId === projectId) error.value = errorMessage(cause)
} finally {
if (!controller.signal.aborted) loading.value = false
if (!signal.aborted && props.projectId === projectId) loading.value = false
}
}
/** 保存独立配置快照,不因路由变化把结果写入其它项目。 */
async function save() {
if (!profile.value || saving.value) return
if (!canSave.value || !profile.value) return
const projectId = props.projectId
const input = creativeProfileDraft(profile.value)
saving.value = true
error.value = ''
notice.value = ''
try {
const saved = await generationConfigApi.saveProfile(props.projectId, profile.value)
profile.value = {
aspectRatio: saved.aspectRatio,
imageProvider: saved.imageProvider,
imageModel: saved.imageModel,
imageOptions: { ...saved.imageOptions },
videoProvider: saved.videoProvider,
videoModel: saved.videoModel,
videoOptions: { ...saved.videoOptions }
}
const saved = await generationConfigApi.saveProfile(projectId, input)
if (disposed || props.projectId !== projectId) return
if (saved.projectId !== projectId) throw new Error('保存结果与当前项目不匹配,请重新读取配置。')
profile.value = creativeProfileDraft(saved)
notice.value = '项目生成配置已保存,后续首帧和视频生成会继承此配置。'
revision.value++
emit('saved', profile.value)
} catch (cause) {
error.value = errorMessage(cause)
if (!disposed && props.projectId === projectId) error.value = errorMessage(cause)
} finally {
saving.value = false
}
}
/** 按后端实际 schema 展示不兼容参数,不静默替换用户已保存的值。 */
const validationIssues = computed(() =>
profile.value && catalog.value ? creativeProfileIssues(profile.value, catalog.value) : []
)
/** 有实际项目草稿、完整可用模型且无进行中的项目操作才允许保存。 */
const canSave = computed(
() =>
!props.disabled &&
!loading.value &&
!saving.value &&
!!profile.value &&
!!enabledImages.value.length &&
!!enabledVideos.value.length &&
!validationIssues.value.length
)
/** 向弹窗 footer 暴露同一个保存入口,避免复制表单与请求逻辑。 */
defineExpose({ save, canSave })
/** 保存状态同步给弹窗,保存完成前禁止关闭。 */
watch(saving, value => emit('busy', value), { flush: 'sync' })
/** 项目变化时重新读取配置。 */
watch(() => props.projectId, load, { immediate: true })
onScopeDispose(() => controller?.abort())
onScopeDispose(() => {
disposed = true
controller?.abort()
})
</script>
<template>
<!-- 以下是项目画布与图片、视频模型配置模块 -->
<section class="production-tool-section creative-profile-settings workspace-panel">
<h3 class="text-sm font-semibold">项目画布与生成模型</h3>
<h3 v-if="!hideActions" class="text-sm font-semibold">项目画布与生成模型</h3>
<NSpin :show="loading">
<NAlert v-if="error" type="error" :show-icon="false" class="mb-3">{{ error }}</NAlert>
<NAlert v-if="notice" type="success" :show-icon="false" class="mb-3">{{ notice }}</NAlert>
<NAlert
v-if="!loading && (!enabledImages.length || !enabledVideos.length)"
type="warning"
:show-icon="false"
>
当前没有可用的完整图片和视频模型,暂时无法保存项目生成配置。
</NAlert>
<div v-if="profile" class="creative-profile-grid">
<NFormItem label="作品宽高比">
<NAlert v-if="disabled" type="info" :show-icon="false" class="mb-3"
>项目正在执行制作任务,完成后可以修改配置。</NAlert
>
<NAlert v-if="error" type="error" :show-icon="false" class="mb-3">{{ error }}</NAlert>
<NAlert v-if="validationIssues.length" type="warning" :show-icon="false" class="mb-3">
<p v-for="issue in validationIssues" :key="issue">{{ issue }}</p>
</NAlert>
<NAlert v-if="notice" type="success" :show-icon="false" class="mb-3">{{ notice }}</NAlert>
<NAlert
v-if="!loading && (!enabledImages.length || !enabledVideos.length)"
type="warning"
:show-icon="false"
>
当前没有可用的完整图片和视频模型,暂时无法保存项目生成配置。
</NAlert>
<div v-if="profile" class="creative-profile-grid">
<NFormItem label="作品宽高比">
<NSelect
:value="profile.aspectRatio"
:options="aspectRatios"
:disabled="saving || disabled"
@update:value="profile.aspectRatio = $event as CreativeProfileAspectRatio"
/>
</NFormItem>
<div></div>
<!-- 以下是项目图片生成配置模块 -->
<section class="model-section min-w-0 pt-5">
<h3 class="mb-4 text-sm font-semibold">图片配置</h3>
<NFormItem label="图片模型">
<NSelect
:value="profile.aspectRatio"
:options="aspectRatios"
:disabled="saving"
@update:value="profile.aspectRatio = $event as CreativeProfileAspectRatio"
:value="imageSelection"
:options="modelOptions(enabledImages)"
:disabled="saving || disabled"
@update:value="selectModel('image', $event)"
/>
</NFormItem>
<div></div>
<section class="model-section">
<NFormItem label="图片模型">
<NSelect
:value="imageSelection"
:options="modelOptions(enabledImages)"
:disabled="saving"
@update:value="selectModel('image', $event)"
/>
</NFormItem>
<GenerationOptionFields
v-model="profile.imageOptions"
:schemas="imageModel?.generationOptions || []"
:disabled="saving"
<GenerationOptionFields
v-model="profile.imageOptions"
:schemas="imageModel?.generationOptions || []"
:disabled="saving || disabled"
/>
</section>
<!-- 以下是项目视频生成配置模块 -->
<section class="model-section min-w-0 pt-5">
<h3 class="mb-4 text-sm font-semibold">视频配置</h3>
<NFormItem label="视频模型">
<NSelect
:value="videoSelection"
:options="modelOptions(enabledVideos)"
:disabled="saving || disabled"
@update:value="selectModel('video', $event)"
/>
</section>
<section class="model-section">
<NFormItem label="视频模型">
<NSelect
:value="videoSelection"
:options="modelOptions(enabledVideos)"
:disabled="saving"
@update:value="selectModel('video', $event)"
/>
</NFormItem>
<GenerationOptionFields
v-model="profile.videoOptions"
:schemas="videoModel?.generationOptions || []"
:disabled="saving"
/>
</section>
</div>
<div class="page-form-actions creative-profile-actions">
<NButton
type="primary"
:loading="saving"
:disabled="loading || !profile || !enabledImages.length || !enabledVideos.length"
@click="save"
>保存项目生成配置</NButton
>
<span class="text-xs text-muted">切换模型时会按新模型重置生成参数。</span>
</div>
</NFormItem>
<GenerationOptionFields
v-model="profile.videoOptions"
:schemas="videoModel?.generationOptions || []"
:disabled="saving || disabled"
/>
</section>
</div>
<div v-if="!hideActions" class="page-form-actions creative-profile-actions">
<NButton type="primary" :loading="saving" :disabled="!canSave" @click="save">保存项目生成配置</NButton>
<span class="text-xs text-muted">切换模型时会按新模型重置生成参数。</span>
</div>
</NSpin>
</section>
</template>
@@ -268,9 +324,6 @@ onScopeDispose(() => controller?.abort())
.creative-profile-grid {
@apply grid grid-cols-[repeat(2,_minmax(0,_1fr))] items-start gap-x-5 gap-y-6;
}
.model-section {
@apply min-w-0;
}
.model-section > :deep(.n-form-item) {
@apply mb-6;
}