feat: 优化生成配置布局与选项控件

This commit is contained in:
GouJ committed 2026-09-22 22:17:09 +08:00
1 parent 1c5b1e448a
commit 94ae147250
3 files changed
+108 -8

No files matched your search

@@ -167,7 +167,7 @@ onScopeDispose(() => controller?.abort())
</script>
<template>
<NCollapse class="production-tool-section" :default-expanded-names="['creative-profile']">
<NCollapse class="production-tool-section creative-profile-settings" :default-expanded-names="['creative-profile']">
<NCollapseItem name="creative-profile" title="项目画布与生成模型">
<NSpin :show="loading">
<NAlert v-if="error" type="error" :show-icon="false" class="mb-3">{{ error }}</NAlert>
@@ -220,7 +220,7 @@ onScopeDispose(() => controller?.abort())
/>
</section>
</div>
<div class="page-form-actions mt-4">
<div class="page-form-actions creative-profile-actions">
<NButton
type="primary"
:loading="saving"
@@ -238,11 +238,17 @@ onScopeDispose(() => controller?.abort())
<style scoped>
@reference "../../../styles/styles.css";
.creative-profile-grid {
@apply grid grid-cols-[repeat(2,_minmax(0,_1fr))] gap-x-5;
@apply grid grid-cols-[repeat(2,_minmax(0,_1fr))] gap-x-5 gap-y-5;
}
.model-section {
@apply min-w-0 p-4 bg-(--app-subtle);
}
.creative-profile-settings {
@apply mb-7;
}
.creative-profile-actions {
@apply mt-5 pt-1;
}
@media (max-width: 900px) {
.creative-profile-grid {
@apply grid-cols-[minmax(0,_1fr)];
@@ -23,6 +23,45 @@ function selectOptions(schema: GenerationOptionSchema) {
: []
)
}
function isDuration(schema: GenerationOptionSchema) {
return /duration|时长/i.test(`${schema.key} ${schema.label}`)
}
function optionKey(value: string | number) {
return `${typeof value}:${value}`
}
/** 尺寸和时长使用有限选项,避免用户输入 Provider 不支持的自由值。 */
function constrainedOptions(schema: GenerationOptionSchema, current: string | number | boolean | undefined) {
const options = selectOptions(schema)
if (schema.type === 'size') {
for (const value of ['1K', '1.5K', '2K']) options.push({ label: value, value })
} else if (
isDuration(schema) &&
Number.isInteger(schema.min) &&
Number.isInteger(schema.max) &&
schema.max! >= schema.min! &&
schema.max! - schema.min! <= 60
) {
for (let value = schema.min!; value <= schema.max!; value++) {
options.push({ label: `${value} 秒`, value })
}
}
if (typeof schema.providerDefault === 'string' || typeof schema.providerDefault === 'number') {
options.push({ label: String(schema.providerDefault), value: schema.providerDefault })
}
if (typeof current === 'string' || typeof current === 'number') {
options.push({ label: String(current), value: current })
}
const seen = new Set<string>()
return options.filter(option => {
const key = optionKey(option.value)
if (seen.has(key)) return false
seen.add(key)
return true
})
}
</script>
<template>
@@ -42,11 +81,11 @@ function selectOptions(schema: GenerationOptionSchema) {
>启用</NCheckbox
>
<NSelect
v-else-if="schema.type === 'select'"
v-else-if="schema.type === 'select' || schema.type === 'size' || isDuration(schema)"
:value="selectValue(modelValue[schema.key])"
:options="selectOptions(schema)"
:options="constrainedOptions(schema, modelValue[schema.key])"
:disabled="disabled"
clearable
:clearable="!schema.required"
@update:value="update(modelValue, schema.key, $event)"
/>
<NInputNumber
@@ -75,8 +114,10 @@ function selectOptions(schema: GenerationOptionSchema) {
<style scoped>
@reference "../../../styles/styles.css";
.generation-option-grid {
grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
@apply grid gap-x-5 gap-y-1;
@apply grid grid-cols-[repeat(2,_minmax(0,_1fr))] gap-x-4 gap-y-5;
}
.generation-option-grid :deep(.n-form-item) {
@apply min-w-0 mb-0;
}
@media (max-width: 760px) {
.generation-option-grid {