feat(short-drama-agent-front): 完善镜头定位与项目配置
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { NFormItem, NInputNumber, NSelect, NSwitch, NTag } from 'naive-ui'
|
||||
import FieldLabel from '../../../components/ui/FieldLabel.vue'
|
||||
import type { SelectOption } from 'naive-ui'
|
||||
import type {
|
||||
CreativeProfileAspectRatio,
|
||||
@@ -9,6 +10,7 @@ import type {
|
||||
GenerationOptions
|
||||
} from '../types'
|
||||
|
||||
/** 本次生成模型与参数控件,字段说明在标签图标中按需查看。 */
|
||||
const props = defineProps<{
|
||||
type: 'image' | 'video'
|
||||
catalog: GenerationModelCatalog
|
||||
@@ -17,15 +19,19 @@ const props = defineProps<{
|
||||
aspectRatio: CreativeProfileAspectRatio
|
||||
disabled?: boolean
|
||||
}>()
|
||||
/** 模型与参数编辑通知。 */
|
||||
const emit = defineEmits<{
|
||||
'update:provider': [value: string]
|
||||
'update:options': [value: GenerationOptions]
|
||||
}>()
|
||||
|
||||
/** 当前已启用的媒介模型。 */
|
||||
const models = computed(() =>
|
||||
(props.type === 'image' ? props.catalog.images : props.catalog.videos).filter(item => item.enabled)
|
||||
)
|
||||
/** 本次选择的实际模型。 */
|
||||
const model = computed(() => models.value.find(item => item.provider === props.provider) ?? models.value[0])
|
||||
/** 可用模型的下拉选项。 */
|
||||
const modelOptions = computed(() =>
|
||||
models.value.map(item => ({
|
||||
label: item.modelLabel ? `${item.providerLabel} · ${item.modelLabel}` : item.providerLabel,
|
||||
@@ -88,7 +94,10 @@ function selectValue(key: string): string | number | null {
|
||||
:key="item.key"
|
||||
class="generation-model-field"
|
||||
:label="item.label"
|
||||
:show-feedback="false"
|
||||
>
|
||||
<!-- 以下是生成参数标签与说明提示模块 -->
|
||||
<template #label><FieldLabel :label="item.label" :description="item.description" /></template>
|
||||
<div class="generation-model-field-control">
|
||||
<div v-if="item.type === 'boolean'" class="generation-model-toggle">
|
||||
<NSwitch
|
||||
@@ -120,14 +129,13 @@ function selectValue(key: string): string | number | null {
|
||||
:disabled="disabled || item.userEditable === false"
|
||||
@update:value="updateOption(item.key, $event)"
|
||||
/>
|
||||
<p v-if="item.description" class="generation-model-description">{{ item.description }}</p>
|
||||
</div>
|
||||
</NFormItem>
|
||||
|
||||
<NFormItem class="generation-model-field" label="画幅比例">
|
||||
<NFormItem class="generation-model-field" label="画幅比例" :show-feedback="false">
|
||||
<template #label><FieldLabel label="画幅比例" description="项目画幅 · 单次生成不可覆盖" /></template>
|
||||
<div class="generation-model-static">
|
||||
<NTag size="small">{{ aspectRatio }}</NTag>
|
||||
<span class="generation-model-description">项目画幅 · 单次生成不可覆盖</span>
|
||||
</div>
|
||||
</NFormItem>
|
||||
</template>
|
||||
@@ -165,9 +173,6 @@ function selectValue(key: string): string | number | null {
|
||||
.generation-model-static {
|
||||
@apply flex min-h-[34px] min-w-0 items-center gap-2.5;
|
||||
}
|
||||
.generation-model-description {
|
||||
@apply m-0 text-[11px] leading-5 text-muted;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.generation-model-controls {
|
||||
@apply grid-cols-[minmax(0,_1fr)] gap-y-4;
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { NCheckbox, NFormItem, NInput, NInputNumber, NSelect } from 'naive-ui'
|
||||
import FieldLabel from '../../../components/ui/FieldLabel.vue'
|
||||
import type { GenerationOptionSchema, GenerationOptions } from '../types'
|
||||
|
||||
defineProps<{ schemas: GenerationOptionSchema[]; modelValue: GenerationOptions; disabled?: boolean }>()
|
||||
/** 动态模型参数字段,实际说明由后端 schema 提供。 */
|
||||
defineProps<{
|
||||
/** 当前模型开放的参数列表。 */
|
||||
schemas: GenerationOptionSchema[]
|
||||
/** 本次实际参数值。 */
|
||||
modelValue: GenerationOptions
|
||||
/** 上游操作期间禁止编辑。 */
|
||||
disabled?: boolean
|
||||
}>()
|
||||
/** 字段编辑后通知上游更新参数。 */
|
||||
const emit = defineEmits<{ 'update:modelValue': [value: GenerationOptions] }>()
|
||||
|
||||
function update(model: GenerationOptions, key: string, value: string | number | boolean | null) {
|
||||
@@ -70,9 +80,15 @@ function constrainedOptions(schema: GenerationOptionSchema, current: string | nu
|
||||
v-for="schema in schemas"
|
||||
:key="schema.key"
|
||||
:label="`${schema.label}${schema.required ? ' *' : ''}`"
|
||||
:feedback="schema.description"
|
||||
:show-feedback="!!schema.description"
|
||||
:show-feedback="false"
|
||||
>
|
||||
<!-- 以下是参数标签与按需说明模块 -->
|
||||
<template #label>
|
||||
<FieldLabel
|
||||
:label="`${schema.label}${schema.required ? ' *' : ''}`"
|
||||
:description="schema.description"
|
||||
/>
|
||||
</template>
|
||||
<NCheckbox
|
||||
v-if="schema.type === 'boolean'"
|
||||
:checked="modelValue[schema.key] === true"
|
||||
@@ -131,11 +147,6 @@ function constrainedOptions(schema: GenerationOptionSchema, current: string | nu
|
||||
min-height: 34px;
|
||||
align-items: center;
|
||||
}
|
||||
.generation-option-grid :deep(.n-form-item-feedback-wrapper:not(:empty)) {
|
||||
min-height: 0;
|
||||
padding: 8px 0 0;
|
||||
line-height: 1.55;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.generation-option-grid {
|
||||
@apply grid-cols-[minmax(0,_1fr)];
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { NButton } from 'naive-ui'
|
||||
import { AppDialog } from '../../../components/ui'
|
||||
import type { CreativeProfileInput } from '../types'
|
||||
import CreativeProfileSettings from './CreativeProfileSettings.vue'
|
||||
|
||||
/** 项目全局配置弹窗参数。 */
|
||||
const props = defineProps<{
|
||||
/** 当前正式项目 ID。 */
|
||||
projectId: string
|
||||
/** 项目操作期间只读查看,禁止保存模型配置。 */
|
||||
disabled: boolean
|
||||
}>()
|
||||
/** 真实保存成功后通知项目布局更新就绪信息。 */
|
||||
const emit = defineEmits<{ saved: [profile: CreativeProfileInput] }>()
|
||||
/** 弹窗显隐状态。 */
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
/** 保存进行中时禁止关闭弹窗,避免重复写入。 */
|
||||
const saving = ref(false)
|
||||
/** 配置表单实例,footer 调用表单自身的校验与保存入口。 */
|
||||
const form = ref<InstanceType<typeof CreativeProfileSettings> | null>(null)
|
||||
</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 #footer>
|
||||
<NButton :disabled="saving" @click="open = false">取消</NButton>
|
||||
<NButton type="primary" :loading="saving" :disabled="!form?.canSave" @click="form?.save()"
|
||||
>保存配置</NButton
|
||||
>
|
||||
</template>
|
||||
</AppDialog>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { inject, ref, type InjectionKey, type Ref } from 'vue'
|
||||
|
||||
/** 项目内共享的配置修订号,成功保存后通知已挂载的生成表单重新读取。 */
|
||||
export const projectGenerationRevisionKey: InjectionKey<Ref<number>> = Symbol('project-generation-revision')
|
||||
|
||||
/**
|
||||
* 读取项目配置修订号,独立使用组件时保留本地修订状态。
|
||||
* @returns 当前项目的响应式配置修订号
|
||||
*/
|
||||
export function useProjectGenerationRevision() {
|
||||
return inject(projectGenerationRevisionKey, undefined) ?? ref(0)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import type { CreativeProfileInput, GenerationModelCatalog } from './types'
|
||||
|
||||
/**
|
||||
* 创建独立编辑或提交快照,原样保留后端已保存的生成参数。
|
||||
* @param profile 后端配置或当前编辑草稿
|
||||
* @returns 与原对象隔离的项目配置快照
|
||||
*/
|
||||
export function creativeProfileDraft(profile: CreativeProfileInput): CreativeProfileInput {
|
||||
return {
|
||||
aspectRatio: profile.aspectRatio,
|
||||
imageProvider: profile.imageProvider,
|
||||
imageModel: profile.imageModel,
|
||||
imageOptions: { ...profile.imageOptions },
|
||||
videoProvider: profile.videoProvider,
|
||||
videoModel: profile.videoModel,
|
||||
videoOptions: { ...profile.videoOptions }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按真实模型目录检查配置能否保存。
|
||||
* @param profile 当前项目配置草稿
|
||||
* @param catalog 后端实际模型目录
|
||||
* @returns 可展示的参数问题列表
|
||||
*/
|
||||
export function creativeProfileIssues(profile: CreativeProfileInput, catalog: GenerationModelCatalog): string[] {
|
||||
const issues: string[] = []
|
||||
for (const media of ['image', 'video'] as const) {
|
||||
const label = media === 'image' ? '图片配置' : '视频配置'
|
||||
const models = media === 'image' ? catalog.images : catalog.videos
|
||||
const model = models.find(
|
||||
item =>
|
||||
item.enabled && item.provider === profile[`${media}Provider`] && item.model === profile[`${media}Model`]
|
||||
)
|
||||
if (!model) {
|
||||
issues.push(`${label}:已保存的模型当前不可用,请重新选择模型。`)
|
||||
continue
|
||||
}
|
||||
const values = profile[`${media}Options`]
|
||||
for (const schema of model.generationOptions) {
|
||||
const value = values[schema.key]
|
||||
const field = `${label} · ${schema.label}`
|
||||
if (value === undefined || value === '') {
|
||||
if (schema.required) issues.push(`${field}:请填写必填参数。`)
|
||||
continue
|
||||
}
|
||||
const validType =
|
||||
schema.type === 'boolean'
|
||||
? typeof value === 'boolean'
|
||||
: schema.type === 'integer'
|
||||
? typeof value === 'number' && Number.isInteger(value)
|
||||
: schema.type === 'number'
|
||||
? typeof value === 'number' && Number.isFinite(value)
|
||||
: typeof value === 'string'
|
||||
if (!validType) {
|
||||
issues.push(`${field}:参数格式不正确。`)
|
||||
continue
|
||||
}
|
||||
if (schema.options?.length && !schema.options.some(option => option.value === value)) {
|
||||
issues.push(`${field}:当前值 ${String(value)} 已不在模型支持范围内,请重新选择。`)
|
||||
continue
|
||||
}
|
||||
if (typeof value === 'number' && !schema.specialValues?.some(option => option.value === value)) {
|
||||
if (schema.min !== undefined && value < schema.min) issues.push(`${field}:不能小于 ${schema.min}。`)
|
||||
if (schema.max !== undefined && value > schema.max) issues.push(`${field}:不能大于 ${schema.max}。`)
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues
|
||||
}
|
||||
Reference in new issue
Block a user