Files
monkey-ai-web/src/pages/ExperienceCenter/components/AICreation/ImageGenerationForm.jsx
T
qiubaishen 5463a0c772 merge: 同步 origin/ui-optimization(d224d5b6),保留 weiyuan 功能与 Semi 迁移
- 冲突以 weiyuan 功能(小程序登录、i18n 文案)为准,并保留远端 lint 重构与依赖收敛
- 删除 weiyuan 已移除、远端仅做 lint 修正的 3 个图片相关文件
- 适配远端零警告 ESLint:Monitoring/Subscription 改用 useEffectEvent,EditChannelModal 注明 t 依赖
- effect-events 单测补充 react-i18next mock
- 对合并后仍不符合 Prettier 的文件做纯格式化
2026-11-10 14:59:34 +08:00

857 lines
29 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useRef, useState } from 'react';
import {
Button,
Collapsible,
Dropdown,
Select,
Skeleton,
Tag,
TextArea,
Toast,
Tooltip,
Typography,
} from '@/components/ui';
import {
ChevronDown,
ChevronUp,
Command,
History as HistoryIcon,
Image as ImageIcon,
Lock,
RotateCcw,
Settings,
Sparkles,
Type,
Wallet,
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { MODEL_CATEGORY } from '../../../../constants';
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
import { useModelSelector } from '../../../../hooks/models/useModelSelector';
import { useOptimizePrompt } from '../../../../hooks/playground/useOptimizePrompt';
import { formatQuoteAmount } from '../../../../hooks/creation/useCreationQuote';
import { MODE_LABEL_KEYS } from '../../../../hooks/image/imageCreation';
import {
ImageSlot,
OptionGroup,
ParamRenderer,
} from '../../../../components/creation/params';
import ImageSizePicker from './Image/ImageSizePicker';
import './Image/ImageGenerationForm.css';
const { Title, Text } = Typography;
// sessionStorage prompt 历史 key
const PROMPT_HISTORY_KEY = 'expCenter.imageGen.promptHistory.v1';
const PROMPT_HISTORY_MAX = 10;
const PROMPT_TEMPLATES = [
{
label: '风景',
text: '一片壮丽的山水风景,远山起伏,湖面如镜,柔和自然光,超精细,4K,电影感',
},
{
label: '人像',
text: '一张专业人像摄影,自然光,柔焦背景,皮肤质感真实,电影质感色调',
},
{
label: '二次元',
text: '动漫风格人物,鲜明配色,精致线条,干净背景,高质量数字绘画',
},
{
label: '科幻',
text: '未来都市夜景,霓虹灯,飞行器,赛博朋克风格,高细节,电影感',
},
{
label: '极简',
text: '极简风格,纯色背景,几何构图,柔和色调,留白美学',
},
{
label: '产品',
text: '产品摄影,纯白背景,柔光,锐利对焦,专业商业摄影',
},
];
const MODE_ICONS = { text2image: Type, edit: ImageIcon };
// 与视频页一致的预算来源文案(估价 budget_source 的前缀)
const BUDGET_SOURCE_LABELS = {
org_budget: '部门 / 项目预算',
token: '令牌额度',
org_member: '成员额度',
org_gift: '企业赠送额度',
org: '企业额度',
membership: '会员额度',
gift: '赠送余额',
user: '账户余额',
};
const budgetSourceLabel = (source) =>
BUDGET_SOURCE_LABELS[String(source || '').split(':')[0]] || '';
const PRICE_UNIT_KEYS = { image: '/张', task: '/次' };
/** schema 单价:"¥0.2/张"。 */
const formatModelPrice = (t, model) => {
const pricing = model?.pricing;
if (!pricing || pricing.price === undefined || pricing.price === null) {
return '';
}
const amount = formatQuoteAmount(pricing.price, pricing.currency);
if (!amount) return '';
const unit = PRICE_UNIT_KEYS[pricing.unit];
return unit ? `${amount}${t(unit)}` : amount;
};
// 检测当前平台是否为 Mac(决定快捷键文案)
const IS_MAC =
typeof navigator !== 'undefined' &&
/Mac|iPod|iPhone|iPad/.test(navigator.platform);
// 检测 DataTransfer 是否携带历史卡片拖出的任务(兼容 Safari 老版本 DOMStringList)
const hasImageTaskType = (dataTransfer) =>
Boolean(
dataTransfer &&
dataTransfer.types &&
Array.from(dataTransfer.types).includes('application/x-image-task'),
);
const Section = ({ title, extra, children, className = '' }) => (
<div
className={`mb-4 rounded-3xl border border-white/[0.45] bg-white/[0.28] p-3 backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.045] ${className}`}
>
{title || extra ? (
<div className='flex items-center justify-between gap-2 mb-2'>
{title ? (
<Text strong className='text-sm text-gray-700 dark:text-gray-200'>
{title}
</Text>
) : null}
{extra}
</div>
) : null}
{children}
</div>
);
/**
* 体验中心图像生成表单(WP A2-3):模型、模式、参数全部来自 GET /api/creation/models?kind=image。
* 状态与提交逻辑在 hooks/image/useImageCreation,此处只做展示。
*/
const ImageGenerationForm = ({ creation }) => {
const { t } = useTranslation();
const navigate = useNavigate();
const isMobile = useIsMobile();
const [mobileCollapsed, setMobileCollapsed] = useState(false);
const [showAdvanced, setShowAdvanced] = useState(false);
const [dropActive, setDropActive] = useState(false);
const dragCounterRef = useRef(0);
const {
formData,
setPrompt,
setMode,
updateParam,
resetForm,
prefillSeq,
models,
modelsLoading,
modelsError,
reloadModels,
selectedModel,
setSelectedModel,
modeOptions,
visibleParams,
imageSlots,
pickImage,
removeImage,
retryImage,
applyAsReference,
quote,
quoteLoading,
quoteFailed,
estSeconds,
submitBlock,
submitting,
handleGenerate,
} = creation;
const prompt = formData.prompt || '';
// 文本模型(用于 prompt AI 优化)
const { models: textModels } = useModelSelector(
MODEL_CATEGORY.TEXT_GENERATION,
);
const { optimizing, optimize } = useOptimizePrompt();
// 会话内 prompt 历史
const [promptHistory, setPromptHistory] = useState(() => {
try {
const raw = sessionStorage.getItem(PROMPT_HISTORY_KEY);
const list = raw ? JSON.parse(raw) : [];
return Array.isArray(list) ? list : [];
} catch (e) {
return [];
}
});
// 外部回填(复用参数 / 用作参考图 / 示例提示词)时,移动端展开表单
useEffect(() => {
if (prefillSeq > 0 && isMobile) setMobileCollapsed(false);
}, [prefillSeq]); // eslint-disable-line react-hooks/exhaustive-deps
const pushPromptHistory = (p) => {
if (!p || !p.trim()) return;
const next = [p, ...promptHistory.filter((x) => x !== p)].slice(
0,
PROMPT_HISTORY_MAX,
);
setPromptHistory(next);
try {
sessionStorage.setItem(PROMPT_HISTORY_KEY, JSON.stringify(next));
} catch (e) {
// 会话存储不可用时只保留内存中的历史
}
};
const isButtonDisabled = Boolean(submitBlock);
// 余额 / 预算不足:按钮变为"去充值"(估价失败时不阻止提交)
const needTopUp = !isButtonDisabled && quote?.balance_enough === false;
const handleSubmit = async () => {
if (submitting || isButtonDisabled) return;
const text = prompt;
const ok = await handleGenerate();
if (ok) pushPromptHistory(text);
};
// Cmd/Ctrl + Enter 在 prompt 区生效
const handlePromptKeyDown = (e) => {
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
e.preventDefault();
if (needTopUp) return;
handleSubmit();
}
};
const handleReset = () => {
resetForm();
Toast.success({ content: t('已重置'), duration: 1.5 });
};
const handleApplyTemplate = (tpl) => {
setPrompt(
prompt && prompt.trim() ? `${prompt.trim()}\n${tpl.text}` : tpl.text,
);
};
// AI 优化提示词(按钮永远可点,所有失败都用 Toast 告诉用户原因)
const handleOptimizePrompt = async () => {
if (optimizing) return;
if (!prompt.trim()) {
Toast.warning({ content: t('请先输入提示词'), duration: 2 });
return;
}
const modelName = textModels?.[0]?.model_name;
if (!modelName) {
Toast.warning({
content: t(
'未配置文本模型,无法 AI 优化。请联系管理员开通文本模型权限',
),
duration: 3,
});
return;
}
const result = await optimize(prompt, modelName);
if (result?.content) {
setPrompt(result.content);
Toast.success({ content: t('已优化提示词'), duration: 2 });
} else if (result?.error) {
Toast.error({ content: result.error, duration: 3 });
}
};
// 拖拽:历史卡片拖入表单任意位置 → 用作参考图
const parseDroppedTask = (dataTransfer) => {
const raw =
dataTransfer.getData('application/x-image-task') ||
dataTransfer.getData('text/plain');
if (!raw) return null;
try {
const parsed = JSON.parse(raw);
return {
id: parsed.id,
imageUrl: parsed.imageUrl || parsed.url,
reusableAsInput: parsed.reusableAsInput === true,
};
} catch {
return null;
}
};
const handleDragEnter = (e) => {
if (!hasImageTaskType(e.dataTransfer)) return;
e.preventDefault();
dragCounterRef.current += 1;
if (!dropActive) setDropActive(true);
};
const handleDragOver = (e) => {
if (!hasImageTaskType(e.dataTransfer)) return;
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
};
const handleDragLeave = (e) => {
if (!hasImageTaskType(e.dataTransfer)) return;
dragCounterRef.current = Math.max(0, dragCounterRef.current - 1);
if (dragCounterRef.current === 0) setDropActive(false);
};
const handleDrop = async (e) => {
if (!hasImageTaskType(e.dataTransfer)) return;
e.preventDefault();
dragCounterRef.current = 0;
setDropActive(false);
const task = parseDroppedTask(e.dataTransfer);
if (task?.id) await applyAsReference(task);
};
// 估价文案:"预计 ¥x · 约 N 秒 · 失败自动退还"(与视频页一致)
const renderQuoteText = () => {
const parts = [];
const item = quote?.items?.[0];
const amount =
item && !item.error
? formatQuoteAmount(item.display_amount, item.currency)
: '';
if (quoteFailed || (quote && !amount)) {
parts.push(t('价格以实际扣费为准'));
} else if (amount) {
parts.push(
item.approximate
? t('预计约 {{amount}}', { amount })
: t('预计 {{amount}}', { amount }),
);
} else if (quoteLoading) {
parts.push(t('正在估价...'));
}
if (estSeconds > 0) parts.push(t('约 {{n}} 秒', { n: estSeconds }));
if (parts.length === 0) return null;
parts.push(t('失败自动退还'));
return parts.join(' · ');
};
const renderGenerateArea = () => (
<div className='igf-generate'>
{needTopUp ? (
<Button
type='warning'
theme='solid'
size='large'
block
icon={<Wallet size={16} />}
onClick={() => navigate('/console/topup')}
className='!rounded-2xl'
style={{ height: '48px', fontSize: '15px', fontWeight: 700 }}
>
{t('去充值')}
</Button>
) : (
<Button
theme='solid'
type='primary'
size='large'
block
loading={submitting}
onClick={handleSubmit}
disabled={isButtonDisabled}
className='!rounded-2xl !shadow-lg !shadow-brand/20 hover:!shadow-xl hover:!shadow-brand/25 !transition-all'
style={{
background: isButtonDisabled
? 'var(--ui-color-fill-1)'
: 'linear-gradient(135deg, var(--brand-gradient-from) 0%, var(--brand-primary) 52%, var(--brand-gradient-to) 100%)',
border: 'none',
color: isButtonDisabled ? 'var(--ui-color-text-3)' : 'white',
height: '48px',
fontSize: '15px',
fontWeight: '700',
}}
>
{submitting ? t('提交中...') : t('生成图片')}
</Button>
)}
<div
className={`igf-quote${needTopUp ? ' is-warning' : ''}`}
aria-live='polite'
role={isButtonDisabled ? 'note' : undefined}
>
{isButtonDisabled
? submitBlock
: needTopUp
? budgetSourceLabel(quote?.budget_source)
? t('{{source}}不足,请充值后再生成', {
source: t(budgetSourceLabel(quote.budget_source)),
})
: t('余额或预算不足,请充值后再生成')
: renderQuoteText()}
</div>
</div>
);
const renderModelSection = () => {
if (modelsLoading) {
return (
<Skeleton
active
placeholder={<Skeleton.Paragraph rows={2} />}
loading
/>
);
}
if (modelsError) {
return (
<div className='igf-state is-error' role='alert'>
<span className='igf-state-title'>{t('模型列表加载失败')}</span>
<Button size='small' onClick={() => reloadModels()}>
{t('重试')}
</Button>
</div>
);
}
if (models.length === 0) {
return (
<div className='igf-state'>
<span className='igf-state-title'>{t('暂无可用的图像模型')}</span>
<span className='igf-muted'>
{t('当前分组下没有可用的图像模型,请联系管理员开通')}
</span>
</div>
);
}
const allLocked = models.every((m) => m.level_locked);
const price = formatModelPrice(t, selectedModel);
return (
<>
<Select
value={selectedModel?.model}
onChange={(value) => setSelectedModel(value)}
placeholder={t('请选择模型')}
style={{ width: '100%' }}
filter
aria-label={t('选择模型')}
>
{models.map((m) => (
<Select.Option
key={m.model}
value={m.model}
label={m.display_name || m.model}
disabled={m.level_locked}
showTick={!m.level_locked}
>
<div className='igf-model-option'>
<Text
strong
type={m.level_locked ? 'tertiary' : undefined}
className='igf-model-name'
>
{m.display_name || m.model}
</Text>
{m.display_name && m.display_name !== m.model ? (
<span className='igf-model-id'>{m.model}</span>
) : null}
{m.level_locked ? (
<Tooltip
content={t('当前等级无权调用此模型,升级等级后可用')}
>
<Tag
size='small'
color='grey'
prefixIcon={<Lock size={12} />}
>
{t('仅可见')}
</Tag>
</Tooltip>
) : null}
</div>
</Select.Option>
))}
</Select>
{allLocked ? (
<div className='igf-muted igf-note' role='note'>
{t('当前等级无权调用图像模型,升级等级后可用')}
</div>
) : null}
{selectedModel && (price || estSeconds || selectedModel.description) ? (
<div className='igf-model-meta'>
{price ? (
<span>
{t('单价')} <strong>{price}</strong>
</span>
) : null}
{estSeconds ? (
<span>
{t('预计耗时')}{' '}
<strong>{t('约 {{n}} 秒', { n: estSeconds })}</strong>
</span>
) : null}
{selectedModel.description ? (
<span className='igf-model-desc'>
{selectedModel.description}
</span>
) : null}
</div>
) : null}
</>
);
};
const sizeParam = visibleParams.find(
(p) => p.key === 'size' && (p.placement || 'dock') !== 'hidden',
);
const otherParams = visibleParams.filter((p) => p.key !== 'size');
const dockParams = otherParams.filter(
(p) => (p.placement || 'dock') === 'dock',
);
const advancedParams = otherParams.filter((p) => p.placement === 'advanced');
const constraints = selectedModel?.constraints || [];
const hasUnusedImage = imageSlots.some((s) => s.slot && !s.active);
const formBodyHidden = isMobile && mobileCollapsed;
const slotLabel = (entry) => `${t(entry.label)} ${entry.labelIndex}`;
return (
<div
className={`image-generation-form relative flex h-full flex-col overflow-y-auto overflow-x-hidden rounded-[28px] border border-white/[0.55] bg-white/[0.42] p-4 shadow-[0_24px_80px_rgba(15,23,42,0.10)] backdrop-blur-2xl backdrop-saturate-150 transition-colors app-scrollbar dark:border-white/10 dark:bg-neutral-950/[0.40] dark:shadow-[0_24px_80px_rgba(0,0,0,0.35)]${dropActive ? ' is-drop-active' : ''}`}
onDragEnter={handleDragEnter}
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
>
{/* 标题 */}
<div className='mb-5 rounded-3xl border border-white/60 bg-white/[0.50] p-4 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.05]'>
<div className='flex items-center justify-between gap-2'>
<div className='flex-1 min-w-0'>
<div className='mb-2 inline-flex items-center gap-2 rounded-full border border-brand/25 bg-brand/10 px-2.5 py-1 text-[11px] font-medium text-brand-deep dark:border-brand/25 dark:bg-brand/15 dark:text-brand-from'>
<Sparkles size={12} />
{t('AI 图片创作')}
</div>
<Title
heading={4}
style={{ margin: 0 }}
className='text-gray-900 dark:text-white'
>
{t('图片生成')}
</Title>
<Text
type='secondary'
size='small'
className='text-gray-500 dark:text-gray-400 mt-1 block truncate'
>
{formBodyHidden && selectedModel
? selectedModel.display_name || selectedModel.model
: t('输入描述即可生成图片')}
</Text>
</div>
<div className='flex items-center gap-1'>
{!formBodyHidden && (
<Button
icon={<RotateCcw size={12} />}
size='small'
theme='borderless'
onClick={handleReset}
className='!text-gray-500 hover:!text-brand-deep dark:hover:!text-brand-from'
>
{t('重置')}
</Button>
)}
{isMobile && (
<Button
icon={
mobileCollapsed ? (
<ChevronDown size={14} />
) : (
<ChevronUp size={14} />
)
}
size='small'
theme='borderless'
onClick={() => setMobileCollapsed(!mobileCollapsed)}
className='!text-gray-500'
>
{mobileCollapsed ? t('展开') : t('收起')}
</Button>
)}
</div>
</div>
</div>
{/* 移动端折叠时只显示生成按钮 + 简略 */}
{formBodyHidden && (
<div className='mt-2'>
{renderGenerateArea()}
<Text type='tertiary' size='small' className='block mt-2 text-center'>
{prompt
? prompt.length > 50
? prompt.slice(0, 50) + '...'
: prompt
: t('点击展开编辑参数')}
</Text>
</div>
)}
{!formBodyHidden && (
<>
{/* 模型选择 */}
<Section title={t('选择模型')}>{renderModelSection()}</Section>
{/* 生成方式(来自 schema modes) */}
{selectedModel && modeOptions.length > 1 ? (
<Section title={t('生成方式')}>
<OptionGroup
options={modeOptions.map((o) => o.mode)}
value={formData.mode}
onChange={setMode}
ariaLabel={t('生成方式')}
optionDisabledReasons={Object.fromEntries(
modeOptions
.filter((o) => o.disabled)
.map((o) => [o.mode, t(o.reason || '当前不可用')]),
)}
renderOption={(mode) => {
const Icon = MODE_ICONS[mode] || Type;
return (
<span className='igf-mode-option'>
<Icon size={14} aria-hidden='true' />
{t(MODE_LABEL_KEYS[mode] || mode)}
</span>
);
}}
/>
</Section>
) : null}
{/* 提示词 + 模板 + 历史 */}
<Section
title={t('提示词')}
extra={
<div className='flex items-center gap-2'>
{/* AI 优化提示词 —— 按钮始终可点击,handler 内判断并 Toast 解释原因 */}
<button
type='button'
onClick={handleOptimizePrompt}
aria-label={t('AI 优化提示词')}
className={[
'flex items-center gap-1 text-[10px] transition-colors',
optimizing
? 'text-brand-from'
: 'text-gray-400 hover:text-brand-deep dark:hover:text-brand-from',
].join(' ')}
title={
textModels?.length
? t('AI 优化提示词 (使用 {{m}})', {
m: textModels[0].model_name,
})
: t('AI 优化提示词')
}
>
<Sparkles
size={10}
className={optimizing ? 'animate-pulse' : ''}
/>
<span>{optimizing ? t('优化中...') : t('AI 优化')}</span>
</button>
{promptHistory.length > 0 && (
<Dropdown
trigger='click'
position='bottomRight'
render={
<Dropdown.Menu style={{ maxWidth: 360 }}>
{promptHistory.map((p, idx) => (
<Dropdown.Item key={idx} onClick={() => setPrompt(p)}>
<div
style={{
maxWidth: 320,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}
title={p}
>
{p}
</div>
</Dropdown.Item>
))}
</Dropdown.Menu>
}
>
<button
type='button'
className='flex items-center gap-1 text-[10px] text-gray-400 hover:text-brand-deep dark:hover:text-brand-from transition-colors'
>
<HistoryIcon size={10} />
<span>{t('历史')}</span>
</button>
</Dropdown>
)}
<span className='flex items-center gap-1 text-[10px] text-gray-400'>
{IS_MAC ? <Command size={10} /> : <span>Ctrl</span>}
<span>+</span>
<span>Enter</span>
<span>{t('生成')}</span>
</span>
</div>
}
>
<TextArea
placeholder={t('描述你想要生成的图片内容...')}
value={prompt}
onChange={setPrompt}
onKeyDown={handlePromptKeyDown}
rows={3}
maxCount={2000}
showClear
className='[&_.ant-input-textarea]:!rounded-2xl [&_.ant-input-textarea]:!border-white/[0.55] [&_.ant-input-textarea]:!bg-white/[0.55] [&_.ant-input-textarea]:!shadow-inner dark:[&_.ant-input-textarea]:!border-white/10 dark:[&_.ant-input-textarea]:!bg-white/[0.06] [&_.ant-input-textarea:hover]:!border-brand/30 [&_.ant-input-textarea:focus]:!border-brand'
/>
<div className='flex flex-wrap items-center gap-1.5 mt-2'>
<div className='flex items-center gap-1 text-[10px] text-gray-400 mr-1'>
<Sparkles size={10} />
<span>{t('快速模板')}</span>
</div>
{PROMPT_TEMPLATES.map((tpl) => (
<Tag
key={tpl.label}
size='small'
color='grey'
onClick={() => handleApplyTemplate(tpl)}
className='!cursor-pointer !rounded-full !border-white/50 !bg-white/[0.45] !backdrop-blur hover:!bg-brand/10 dark:!border-white/10 dark:!bg-white/[0.06] dark:hover:!bg-brand/15 hover:!text-brand-deep dark:hover:!text-brand-from !transition-colors'
>
{t(tpl.label)}
</Tag>
))}
</div>
</Section>
{/* 参考图:编辑模式的带标签槽位;当前模型 / 模式用不到的图片置灰保留 */}
{selectedModel && imageSlots.length > 0 ? (
<Section
title={t('参考图片')}
extra={
<Text type='tertiary' className='!text-[10px]'>
{t('可从右侧历史拖拽图片到这里')}
</Text>
}
>
<div className='igf-slots'>
{imageSlots.map((entry) => {
const slot = entry.slot;
const value = slot
? {
previewUrl: slot.previewUrl,
status: entry.active
? slot.status || 'ready'
: 'unused',
error: slot.error,
}
: null;
return (
<ImageSlot
key={`ref-${entry.index}-${slot?.id || 'empty'}`}
label={slotLabel(entry)}
value={value}
onPick={(file) => pickImage(entry.index, file)}
onRemove={() => removeImage(entry.index)}
onRetry={() => retryImage(entry.index, slot)}
/>
);
})}
</div>
{hasUnusedImage ? (
<div className='igf-muted igf-note' role='note'>
{t('置灰的图片当前不会提交,切回支持的模型或模式后自动恢复')}
</div>
) : null}
</Section>
) : null}
{/* 尺寸 + 常用参数(画质 / 数量等) */}
{selectedModel && (sizeParam || dockParams.length > 0) ? (
<Section title={sizeParam ? t('尺寸') : t('生成参数')}>
{sizeParam ? (
<ImageSizePicker
param={sizeParam}
value={formData.params?.size}
onChange={(v) => updateParam('size', v)}
/>
) : null}
{dockParams.length > 0 ? (
<ParamRenderer
className={sizeParam ? 'igf-dock-params' : ''}
params={visibleParams}
values={formData.params}
onChange={updateParam}
placement='dock'
constraints={constraints}
/>
) : null}
</Section>
) : null}
{/* 高级选项 */}
{selectedModel && advancedParams.length > 0 ? (
<Section>
<button
type='button'
onClick={() => setShowAdvanced(!showAdvanced)}
aria-expanded={showAdvanced}
className='flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400 hover:text-brand-deep dark:hover:text-brand-from transition-colors'
>
<Settings size={12} />
<span>{t('高级选项')}</span>
{showAdvanced ? (
<ChevronUp size={12} />
) : (
<ChevronDown size={12} />
)}
</button>
<Collapsible isOpen={showAdvanced} keepDOM>
<div className='pt-3'>
<ParamRenderer
params={visibleParams}
values={formData.params}
onChange={updateParam}
placement='advanced'
constraints={constraints}
/>
</div>
</Collapsible>
</Section>
) : null}
{/* 生成按钮 + 估价 */}
<div className='sticky bottom-0 -mx-4 mt-auto bg-transparent px-4 pt-4 pb-1'>
{renderGenerateArea()}
</div>
</>
)}
</div>
);
};
export default ImageGenerationForm;