feat: 添加通用生成模型参数控件
This commit is contained in:
1 parent
2d690548e3
commit
6341911abd
1 file changed
+92
@@ -0,0 +1,92 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { NFormItem, NInputNumber, NSelect, NSwitch, NTag } from 'naive-ui'
|
||||
import type { CreativeProfileAspectRatio, GenerationModelCatalog, GenerationModelItem, GenerationOptions } from '../types'
|
||||
|
||||
const props = defineProps<{
|
||||
type: 'image' | 'video'
|
||||
catalog: GenerationModelCatalog
|
||||
provider: string
|
||||
options: GenerationOptions
|
||||
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,
|
||||
value: item.provider
|
||||
}))
|
||||
)
|
||||
|
||||
function selectProvider(provider: string) {
|
||||
const next = models.value.find(item => item.provider === provider)
|
||||
if (!next) return
|
||||
emit('update:provider', provider)
|
||||
emit('update:options', { ...next.defaults })
|
||||
}
|
||||
|
||||
function updateOption(key: string, value: string | number | boolean | null) {
|
||||
const next = { ...props.options }
|
||||
if (value === null) delete next[key]
|
||||
else next[key] = value
|
||||
emit('update:options', next)
|
||||
}
|
||||
|
||||
function choices(item: GenerationModelItem['generationOptions'][number]) {
|
||||
return [...(item.options ?? []), ...(item.specialValues ?? [])]
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="generation-model-controls">
|
||||
<NFormItem label="模型">
|
||||
<NSelect
|
||||
:value="model?.provider"
|
||||
:options="modelOptions"
|
||||
:disabled="disabled || !modelOptions.length"
|
||||
@update:value="selectProvider"
|
||||
/>
|
||||
</NFormItem>
|
||||
|
||||
<template v-if="model">
|
||||
<NFormItem v-for="item in model.generationOptions" :key="item.key" :label="item.label">
|
||||
<NSwitch
|
||||
v-if="item.type === 'boolean'"
|
||||
:value="Boolean(options[item.key])"
|
||||
:disabled="disabled || item.userEditable === false"
|
||||
@update:value="updateOption(item.key, $event)"
|
||||
/>
|
||||
<NInputNumber
|
||||
v-else-if="item.type === 'integer' || item.type === 'number'"
|
||||
:value="typeof options[item.key] === 'number' ? Number(options[item.key]) : null"
|
||||
:min="item.min"
|
||||
:max="item.max"
|
||||
:disabled="disabled || item.userEditable === false"
|
||||
@update:value="updateOption(item.key, $event)"
|
||||
/>
|
||||
<NSelect
|
||||
v-else
|
||||
:value="options[item.key] ?? null"
|
||||
:options="choices(item)"
|
||||
:disabled="disabled || item.userEditable === false"
|
||||
@update:value="updateOption(item.key, $event)"
|
||||
/>
|
||||
<p v-if="item.description" class="mt-1 text-xs text-muted">{{ item.description }}</p>
|
||||
</NFormItem>
|
||||
|
||||
<NFormItem label="画幅比例">
|
||||
<div class="flex items-center gap-2">
|
||||
<NTag size="small">{{ aspectRatio }}</NTag>
|
||||
<span class="text-xs text-muted">项目画幅 · 单次生成不可覆盖</span>
|
||||
</div>
|
||||
</NFormItem>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user