feat: 对接项目生成配置与单集成片

This commit is contained in:
GouJ committed 2026-09-21 10:03:50 +08:00
1 parent 1bbfd30627
commit 01f274cd8e
9 files changed
+722 -8

No files matched your search

@@ -0,0 +1,85 @@
<script setup lang="ts">
import { NCheckbox, NFormItem, NInput, NInputNumber, NSelect } from 'naive-ui'
import type { GenerationOptionSchema, GenerationOptions } from '../types'
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) {
const next = { ...model }
if (value === null || value === '') delete next[key]
else next[key] = value
emit('update:modelValue', next)
}
function selectValue(value: string | number | boolean | undefined) {
return typeof value === 'string' || typeof value === 'number' ? value : null
}
function selectOptions(schema: GenerationOptionSchema) {
return [...(schema.options || []), ...(schema.specialValues || [])].flatMap(option =>
typeof option.value === 'string' || typeof option.value === 'number'
? [{ label: option.label, value: option.value }]
: []
)
}
</script>
<template>
<div v-if="schemas.length" class="generation-option-grid">
<NFormItem
v-for="schema in schemas"
:key="schema.key"
:label="`${schema.label}${schema.required ? ' *' : ''}`"
:feedback="schema.description"
:show-feedback="!!schema.description"
>
<NCheckbox
v-if="schema.type === 'boolean'"
:checked="modelValue[schema.key] === true"
:disabled="disabled"
@update:checked="update(modelValue, schema.key, $event)"
>启用</NCheckbox
>
<NSelect
v-else-if="schema.type === 'select'"
:value="selectValue(modelValue[schema.key])"
:options="selectOptions(schema)"
:disabled="disabled"
clearable
@update:value="update(modelValue, schema.key, $event)"
/>
<NInputNumber
v-else-if="schema.type === 'integer' || schema.type === 'number'"
:value="typeof modelValue[schema.key] === 'number' ? (modelValue[schema.key] as number) : null"
:min="schema.min"
:max="schema.max"
:precision="schema.type === 'integer' ? 0 : undefined"
:disabled="disabled"
clearable
@update:value="update(modelValue, schema.key, $event)"
/>
<NInput
v-else
:value="typeof modelValue[schema.key] === 'string' ? (modelValue[schema.key] as string) : ''"
:disabled="disabled"
placeholder="例如 2048x2048 或 auto"
clearable
@update:value="update(modelValue, schema.key, $event)"
/>
</NFormItem>
</div>
<p v-else class="text-xs text-muted">当前模型没有开放额外生成参数。</p>
</template>
<style scoped>
@reference "../../../styles/styles.css";
.generation-option-grid {
@apply grid grid-cols-[repeat(2,_minmax(0,_1fr))] gap-x-4;
}
@media (max-width: 760px) {
.generation-option-grid {
@apply grid-cols-[minmax(0,_1fr)];
}
}
</style>