Skip to content

中文版 AI 姿势参考图库 · 1439 组 / 2878 张图片 / 完整汉化 · 零依赖静态画廊

feat: support reference slot uploads and ComfyUI workflow validation

H-Boled814252d2daa
diff --git a/GLOSSARY.md b/GLOSSARY.md
new file mode 100644
index 0000000..fb2524a
--- /dev/null
+++ b/GLOSSARY.md
@@ -0,0 +1,12 @@
+# 角色合成
+
+## Language
+
+**图片槽位**:配方中指定人像、服装或姿势用途的参考图位置。图片可以来自图库或本机上传。
+_Avoid_: 图片节点
+
+**节点映射**:图片槽位或提示词与 ComfyUI 工作流输入节点之间的对应关系。
+_Avoid_: 图片选择
+
+**附加参考图**:三个用途槽位之外,用于补充配饰、背景等信息的图片。它不自动替代某个槽位。
+_Avoid_: 人像槽、服装槽、姿势槽
diff --git a/src/components/layout/RecipeDock.tsx b/src/components/layout/RecipeDock.tsx
index 2f4126f..beeacb0 100644
--- a/src/components/layout/RecipeDock.tsx
+++ b/src/components/layout/RecipeDock.tsx
@@ -3,6 +3,7 @@ import { Link, useLocation } from '@tanstack/react-router'
import { CopyIcon, DicesIcon, LoaderCircleIcon, PersonStandingIcon, ShirtIcon, SparklesIcon, Trash2Icon, UserRoundIcon, XIcon } from 'lucide-react'
import { toast } from 'sonner'
import { costumesQuery, portraitsQuery, posesQuery } from '@/api/gallery'
+import { referenceImageUrl } from '@/lib/recipeImages'
import { Button } from '@/components/ui/button'
import { buildRecipePrompt } from '@/services/aiGenerator'
import { useStudio } from '@/store/studioStore'
@@ -47,7 +48,7 @@ export function RecipeDock() {
{recipe.portrait ? (
<>
<img
- src={`/${recipe.portrait.缩略图}`}
+ src={referenceImageUrl(recipe.portrait.缩略图)}
alt={recipe.portrait.标题}
className="h-8 w-7 shrink-0 rounded-md object-cover sm:h-10 sm:w-8"
/>
@@ -77,7 +78,7 @@ export function RecipeDock() {
{recipe.costume ? (
<>
<img
- src={`/${recipe.costume.缩略图}`}
+ src={referenceImageUrl(recipe.costume.缩略图)}
alt={recipe.costume.服装名称}
className="h-8 w-7 shrink-0 rounded-md object-cover sm:h-10 sm:w-8"
/>
@@ -107,7 +108,7 @@ export function RecipeDock() {
{recipe.pose ? (
<>
<img
- src={`/${recipe.pose.缩略图}`}
+ src={referenceImageUrl(recipe.pose.缩略图)}
alt={recipe.pose.姿势名称}
className="h-8 w-7 shrink-0 rounded-md object-cover sm:h-10 sm:w-8"
/>
diff --git a/src/lib/recipeImages.ts b/src/lib/recipeImages.ts
new file mode 100644
index 0000000..d3af00b
--- /dev/null
+++ b/src/lib/recipeImages.ts
@@ -0,0 +1,29 @@
+import type { CostumeItem, PortraitItem, PoseItem, RecipeState } from '@/types/gallery'
+
+export function referenceImageUrl(src: string): string {
+ return /^(data:|https?:\/\/|\/)/i.test(src) ? src : `/${src}`
+}
+
+export function uploadedReferences(name: string, url: string, width: number, height: number, bytes: number) {
+ const base = { id: crypto.randomUUID(), source: 'upload' as const, 原图: url, 缩略图: url, 检索: name }
+ const portrait: PortraitItem = {
+ ...base, 分区: '上传', 发长: '', 发型名称: name, 标题: name,
+ 宽: width, 高: height, 字节数: bytes, 精选: false, 热门: false,
+ }
+ const costume: CostumeItem = {
+ ...base, 分类: '上传', 服装名称: name, 标签: [], 关键词: '', 预览图: url,
+ }
+ const pose: PoseItem = {
+ ...base, 体系: '上传', 姿势编号: '', 分类: '上传', 姿势名称: name, 角度: '',
+ }
+ return { portrait, costume, pose }
+}
+
+export function recipeBackup(recipe: RecipeState): RecipeState {
+ return {
+ portrait: recipe.portrait?.source === 'upload' ? null : recipe.portrait,
+ costume: recipe.costume?.source === 'upload' ? null : recipe.costume,
+ pose: recipe.pose?.source === 'upload' ? null : recipe.pose,
+ extraImages: [],
+ }
+}
diff --git a/src/routes/settings.tsx b/src/routes/settings.tsx
index bc23358..fd6ee6b 100644
--- a/src/routes/settings.tsx
+++ b/src/routes/settings.tsx
@@ -167,25 +167,27 @@ function SettingsPage() {
</div>
</Field>
- <Field label="默认模型 ID">
- <Select
- value={pCfg.model}
- onValueChange={(v) => updateProviderConfig(pid, { model: v })}
- >
- <SelectTrigger className="w-full font-mono text-xs">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- {meta.models.map((m) => (
- <SelectItem key={m.value} value={m.value} className="font-mono text-xs">
- {m.label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- </Field>
+ {pid !== 'comfyui' && (
+ <Field label="默认模型 ID">
+ <Select
+ value={pCfg.model}
+ onValueChange={(v) => updateProviderConfig(pid, { model: v })}
+ >
+ <SelectTrigger className="w-full font-mono text-xs">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {meta.models.map((m) => (
+ <SelectItem key={m.value} value={m.value} className="font-mono text-xs">
+ {m.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </Field>
+ )}
- {pCfg.model === 'custom' && (
+ {pid !== 'comfyui' && pCfg.model === 'custom' && (
<Field label="自定义模型 ID">
<Input
value={pCfg.customModel}
@@ -197,35 +199,41 @@ function SettingsPage() {
)}
</Section>
+ {pid === 'comfyui' && (
+ <p className="text-sm text-muted-foreground">模型由工作流决定。请返回合成台导入工作流,并设置人像、服装和姿势节点。</p>
+ )}
+
{/* 全局传输设置 */}
- <Section title="全局请求选项">
- <Field label="参考图传参方式">
- <Select
- value={apiConfig.imagePassMode}
- onValueChange={(v) => updateApiConfig({ imagePassMode: v as ImagePassMode })}
- >
- <SelectTrigger className="w-full">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectItem value="url">传递图片 URL(免上传文件,推荐)</SelectItem>
- <SelectItem value="base64">转 Base64 编码传输</SelectItem>
- </SelectContent>
- </Select>
- </Field>
+ {pid !== 'comfyui' && (
+ <Section title="全局请求选项">
+ <Field label="参考图传参方式">
+ <Select
+ value={apiConfig.imagePassMode}
+ onValueChange={(v) => updateApiConfig({ imagePassMode: v as ImagePassMode })}
+ >
+ <SelectTrigger className="w-full">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="url">传递图片 URL(免上传文件,推荐)</SelectItem>
+ <SelectItem value="base64">转 Base64 编码传输</SelectItem>
+ </SelectContent>
+ </Select>
+ </Field>
- <Field label="服务端 CORS 代理 (/api/proxy)">
- <div className="flex h-9 items-center justify-between rounded-xl border bg-background px-3">
- <span className="text-xs text-muted-foreground">
- {apiConfig.useProxy ? '已启用(解决跨域限制)' : '已关闭(浏览器直连)'}
- </span>
- <Switch
- checked={apiConfig.useProxy}
- onCheckedChange={(v) => updateApiConfig({ useProxy: v })}
- />
- </div>
- </Field>
- </Section>
+ <Field label="服务端 CORS 代理 (/api/proxy)">
+ <div className="flex h-9 items-center justify-between rounded-xl border bg-background px-3">
+ <span className="text-xs text-muted-foreground">
+ {apiConfig.useProxy ? '已启用(解决跨域限制)' : '已关闭(浏览器直连)'}
+ </span>
+ <Switch
+ checked={apiConfig.useProxy}
+ onCheckedChange={(v) => updateApiConfig({ useProxy: v })}
+ />
+ </div>
+ </Field>
+ </Section>
+ )}
<div className="flex justify-end">
<Button size="sm" onClick={() => toast.success('配置已保存')}>
diff --git a/src/routes/studio.tsx b/src/routes/studio.tsx
index e45a60a..264975f 100644
--- a/src/routes/studio.tsx
+++ b/src/routes/studio.tsx
@@ -29,7 +29,7 @@ import { Field, Section } from '@/components/common/FormSection'
import { PageHeader } from '@/components/common/PageHeader'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
-import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
+import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { Switch } from '@/components/ui/switch'
@@ -44,6 +44,7 @@ import {
stitchRecipeCanvas,
STYLE_PRESETS,
} from '@/services/aiGenerator'
+import { referenceImageUrl, uploadedReferences } from '@/lib/recipeImages'
import { useStudio } from '@/store/studioStore'
import type {
ComfyUiParams,
@@ -94,6 +95,11 @@ function StudioPage() {
const qc = useQueryClient()
const fileInputRef = useRef<HTMLInputElement | null>(null)
const comfyFileInputRef = useRef<HTMLInputElement | null>(null)
+ const slotInputRef = useRef<HTMLInputElement | null>(null)
+ const uploadSlotRef = useRef<'portrait' | 'costume' | 'pose'>('portrait')
+ const [uploadingSlot, setUploadingSlot] = useState<string | null>(null)
+ const [showReferenceErrors, setShowReferenceErrors] = useState(false)
+ const referenceErrorsRef = useRef<HTMLDivElement | null>(null)
const activeProvider = apiConfig.activeProvider
const providerMeta = PROVIDER_META[activeProvider]
@@ -180,6 +186,39 @@ function StudioPage() {
}
}
+ const handleSlotUpload = async (e: ChangeEvent<HTMLInputElement>) => {
+ const file = e.target.files?.[0]
+ const slot = uploadSlotRef.current
+ e.target.value = ''
+ if (!file) return
+ if (!file.type.startsWith('image/')) {
+ toast.error('请选择图片文件')
+ return
+ }
+ setUploadingSlot(slot)
+ try {
+ const url = await fileToDataUrl(file)
+ const image = new Image()
+ image.src = url
+ await image.decode()
+ const name = file.name.replace(/\.[^.]+$/, '') || '上传图片'
+ const items = uploadedReferences(name, url, image.width, image.height, file.size)
+ if (slot === 'portrait') setPortrait(items.portrait)
+ if (slot === 'costume') setCostume(items.costume)
+ if (slot === 'pose') setPose(items.pose)
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : '图片读取失败')
+ } finally {
+ setUploadingSlot(null)
+ }
+ }
+
+ const missingReferences = activeProvider === 'comfyui' ? [
+ { label: '人像', node: apiConfig.comfyuiParams.portraitNodeId, image: recipe.portrait },
+ { label: '服装', node: apiConfig.comfyuiParams.costumeNodeId, image: recipe.costume },
+ { label: '姿势', node: apiConfig.comfyuiParams.poseNodeId, image: recipe.pose },
+ ].filter((slot) => slot.node && slot.node !== 'none' && parsedComfyNodes.imageNodes.some((node) => node.id === slot.node) && !slot.image).map((slot) => slot.label) : []
+
const extraImages = recipe.extraImages || []
const hasAnyRef = Boolean(
recipe.portrait || recipe.costume || recipe.pose || extraImages.length > 0
@@ -266,6 +305,11 @@ function StudioPage() {
}
const handleGenerate = () => {
+ if (missingReferences.length) {
+ setShowReferenceErrors(true)
+ requestAnimationFrame(() => referenceErrorsRef.current?.focus())
+ return
+ }
void startGeneration(prompt)
}
@@ -332,107 +376,149 @@ function StudioPage() {
}
>
+ <input ref={slotInputRef} type="file" accept="image/*" className="hidden" onChange={handleSlotUpload} />
+ {showReferenceErrors && missingReferences.length > 0 && (
+ <div id="reference-errors" ref={referenceErrorsRef} role="alert" tabIndex={-1} className="rounded-lg border border-destructive/50 bg-destructive/5 p-3 text-sm text-destructive focus-visible:outline-2">
+ 请先选择或上传:{missingReferences.join('、')}。这些槽位已绑定工作流节点。
+ </div>
+ )}
{/* 3 个核心图库槽位:手机端单列舒展展示,平板/桌面端三列并排 */}
<div className="grid grid-cols-1 gap-2 sm:grid-cols-3">
{/* 人像槽 */}
- <div className="relative flex items-center gap-2.5 rounded-xl bg-background p-2">
+ <div className={`relative flex min-w-0 items-center gap-2 rounded-xl bg-background p-2 ${showReferenceErrors && missingReferences.includes('人像') ? 'ring-1 ring-destructive' : ''}`}>
{recipe.portrait ? (
<>
- <img
- src={`/${recipe.portrait.缩略图}`}
- alt={recipe.portrait.标题}
- className="h-11 w-9 shrink-0 rounded-lg object-cover"
- />
+ <button type="button" aria-label="放大人像参考图" className="flex min-h-11 min-w-11 shrink-0 cursor-zoom-in items-center justify-center rounded-lg transition-opacity hover:opacity-80 focus-visible:outline-2 focus-visible:outline-ring" onClick={() => {
+ const item = recipe.portrait
+ if (item) setZoomImageUrl(referenceImageUrl(item.原图 || item.缩略图))
+ }}>
+ <img
+ src={referenceImageUrl(recipe.portrait.缩略图)}
+ alt={recipe.portrait.标题}
+ className="h-11 w-9 shrink-0 rounded-lg object-cover"
+ />
+ </button>
<div className="min-w-0 flex-1">
- <div className="text-[10px] text-muted-foreground">人像</div>
- <div className="truncate text-xs font-medium">{recipe.portrait.发型名称}</div>
+ <div className="text-xs text-muted-foreground">人像</div>
+ <div className="truncate text-xs font-medium" title={recipe.portrait.发型名称}>{recipe.portrait.发型名称}</div>
</div>
<button
type="button"
+ aria-label="清除人像参考图"
onClick={() => setPortrait(null)}
- className="shrink-0 rounded-full p-1 text-muted-foreground hover:bg-muted hover:text-foreground"
+ className="flex size-11 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
>
<XIcon className="size-3.5" />
</button>
</>
) : (
- <Link
- to="/portraits"
- className="flex flex-1 items-center gap-2.5 py-0.5 text-muted-foreground hover:text-foreground"
- >
- <div className="flex h-10 w-8 shrink-0 items-center justify-center rounded-lg bg-muted">
- <UserRoundIcon className="size-4" />
- </div>
- <span className="truncate text-xs">+ 选人像</span>
- </Link>
+ <>
+ <Link
+ to="/portraits"
+ className="flex min-h-11 min-w-0 flex-1 items-center gap-2 rounded-lg text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
+ >
+ <div className="flex h-10 w-8 shrink-0 items-center justify-center rounded-lg bg-muted">
+ <UserRoundIcon className="size-4" />
+ </div>
+ <span className="truncate text-xs">+ 选人像</span>
+ </Link>
+ <Button type="button" variant="ghost" size="sm" aria-label="上传人像参考图" aria-describedby={showReferenceErrors && missingReferences.includes('人像') ? 'reference-errors' : undefined} aria-busy={uploadingSlot === 'portrait'} disabled={uploadingSlot !== null} className="h-11 shrink-0 border-l px-2 text-xs" onClick={() => { uploadSlotRef.current = 'portrait'; slotInputRef.current?.click() }}>
+ {uploadingSlot === 'portrait' ? <LoaderCircleIcon className="size-3.5 animate-spin motion-reduce:animate-none" /> : <ImagePlusIcon className="size-3.5" />}
+ {uploadingSlot === 'portrait' ? '处理中' : '上传'}
+ </Button>
+ </>
)}
</div>
{/* 服装槽 */}
- <div className="relative flex items-center gap-2.5 rounded-xl bg-background p-2">
+ <div className={`relative flex min-w-0 items-center gap-2 rounded-xl bg-background p-2 ${showReferenceErrors && missingReferences.includes('服装') ? 'ring-1 ring-destructive' : ''}`}>
{recipe.costume ? (
<>
- <img
- src={`/${recipe.costume.缩略图}`}
- alt={recipe.costume.服装名称}
- className="h-11 w-9 shrink-0 rounded-lg object-cover"
- />
+ <button type="button" aria-label="放大服装参考图" className="flex min-h-11 min-w-11 shrink-0 cursor-zoom-in items-center justify-center rounded-lg transition-opacity hover:opacity-80 focus-visible:outline-2 focus-visible:outline-ring" onClick={() => {
+ const item = recipe.costume
+ if (item) setZoomImageUrl(referenceImageUrl(item.预览图 || item.原图 || item.缩略图))
+ }}>
+ <img
+ src={referenceImageUrl(recipe.costume.缩略图)}
+ alt={recipe.costume.服装名称}
+ className="h-11 w-9 shrink-0 rounded-lg object-cover"
+ />
+ </button>
<div className="min-w-0 flex-1">
- <div className="text-[10px] text-muted-foreground">服装</div>
- <div className="truncate text-xs font-medium">{recipe.costume.服装名称}</div>
+ <div className="text-xs text-muted-foreground">服装</div>
+ <div className="truncate text-xs font-medium" title={recipe.costume.服装名称}>{recipe.costume.服装名称}</div>
</div>
<button
type="button"
+ aria-label="清除服装参考图"
onClick={() => setCostume(null)}
- className="shrink-0 rounded-full p-1 text-muted-foreground hover:bg-muted hover:text-foreground"
+ className="flex size-11 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
>
<XIcon className="size-3.5" />
</button>
</>
) : (
- <Link
- to="/costumes"
- className="flex flex-1 items-center gap-2.5 py-0.5 text-muted-foreground hover:text-foreground"
- >
- <div className="flex h-10 w-8 shrink-0 items-center justify-center rounded-lg bg-muted">
- <ShirtIcon className="size-4" />
- </div>
- <span className="truncate text-xs">+ 选服装</span>
- </Link>
+ <>
+ <Link
+ to="/costumes"
+ className="flex min-h-11 min-w-0 flex-1 items-center gap-2 rounded-lg text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
+ >
+ <div className="flex h-10 w-8 shrink-0 items-center justify-center rounded-lg bg-muted">
+ <ShirtIcon className="size-4" />
+ </div>
+ <span className="truncate text-xs">+ 选服装</span>
+ </Link>
+ <Button type="button" variant="ghost" size="sm" aria-label="上传服装参考图" aria-describedby={showReferenceErrors && missingReferences.includes('服装') ? 'reference-errors' : undefined} aria-busy={uploadingSlot === 'costume'} disabled={uploadingSlot !== null} className="h-11 shrink-0 border-l px-2 text-xs" onClick={() => { uploadSlotRef.current = 'costume'; slotInputRef.current?.click() }}>
+ {uploadingSlot === 'costume' ? <LoaderCircleIcon className="size-3.5 animate-spin motion-reduce:animate-none" /> : <ImagePlusIcon className="size-3.5" />}
+ {uploadingSlot === 'costume' ? '处理中' : '上传'}
+ </Button>
+ </>
)}
</div>
{/* 姿势槽 */}
- <div className="relative flex items-center gap-2.5 rounded-xl bg-background p-2">
+ <div className={`relative flex min-w-0 items-center gap-2 rounded-xl bg-background p-2 ${showReferenceErrors && missingReferences.includes('姿势') ? 'ring-1 ring-destructive' : ''}`}>
{recipe.pose ? (
<>
- <img
- src={`/${recipe.pose.缩略图}`}
- alt={recipe.pose.姿势名称}
- className="h-11 w-9 shrink-0 rounded-lg object-cover"
- />
+ <button type="button" aria-label="放大姿势参考图" className="flex min-h-11 min-w-11 shrink-0 cursor-zoom-in items-center justify-center rounded-lg transition-opacity hover:opacity-80 focus-visible:outline-2 focus-visible:outline-ring" onClick={() => {
+ const item = recipe.pose
+ if (item) setZoomImageUrl(referenceImageUrl(item.原图 || item.缩略图))
+ }}>
+ <img
+ src={referenceImageUrl(recipe.pose.缩略图)}
+ alt={recipe.pose.姿势名称}
+ className="h-11 w-9 shrink-0 rounded-lg object-cover"
+ />
+ </button>
<div className="min-w-0 flex-1">
- <div className="text-[10px] text-muted-foreground">姿势 · {recipe.pose.角度}</div>
- <div className="truncate text-xs font-medium">{recipe.pose.姿势名称}</div>
+ <div className="text-xs text-muted-foreground">姿势{recipe.pose.source === 'upload' ? ' · 本机上传' : recipe.pose.角度 ? ` · ${recipe.pose.角度}` : ''}</div>
+ <div className="truncate text-xs font-medium" title={recipe.pose.姿势名称}>{recipe.pose.姿势名称}</div>
</div>
<button
type="button"
+ aria-label="清除姿势参考图"
onClick={() => setPose(null)}
- className="shrink-0 rounded-full p-1 text-muted-foreground hover:bg-muted hover:text-foreground"
+ className="flex size-11 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
>
<XIcon className="size-3.5" />
</button>
</>
) : (
- <Link
- to="/poses"
- className="flex flex-1 items-center gap-2.5 py-0.5 text-muted-foreground hover:text-foreground"
- >
- <div className="flex h-10 w-8 shrink-0 items-center justify-center rounded-lg bg-muted">
- <PersonStandingIcon className="size-4" />
- </div>
- <span className="truncate text-xs">+ 选姿势</span>
- </Link>
+ <>
+ <Link
+ to="/poses"
+ className="flex min-h-11 min-w-0 flex-1 items-center gap-2 rounded-lg text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
+ >
+ <div className="flex h-10 w-8 shrink-0 items-center justify-center rounded-lg bg-muted">
+ <PersonStandingIcon className="size-4" />
+ </div>
+ <span className="truncate text-xs">+ 选姿势</span>
+ </Link>
+ <Button type="button" variant="ghost" size="sm" aria-label="上传姿势参考图" aria-describedby={showReferenceErrors && missingReferences.includes('姿势') ? 'reference-errors' : undefined} aria-busy={uploadingSlot === 'pose'} disabled={uploadingSlot !== null} className="h-11 shrink-0 border-l px-2 text-xs" onClick={() => { uploadSlotRef.current = 'pose'; slotInputRef.current?.click() }}>
+ {uploadingSlot === 'pose' ? <LoaderCircleIcon className="size-3.5 animate-spin motion-reduce:animate-none" /> : <ImagePlusIcon className="size-3.5" />}
+ {uploadingSlot === 'pose' ? '处理中' : '上传'}
+ </Button>
+ </>
)}
</div>
</div>
@@ -1127,7 +1213,7 @@ function StudioPage() {
<Button
onClick={handleGenerate}
- disabled={isGenerating}
+ disabled={isGenerating || uploadingSlot !== null}
className="h-11 w-full text-sm font-semibold"
>
{isGenerating ? (
@@ -1153,7 +1239,7 @@ function StudioPage() {
actions={
previewUrl && !isGenerating ? (
<Button variant="outline" size="sm" asChild>
- <a href={previewUrl} download="character-result.png">
+ <a href={previewUrl} download="image.png">
<DownloadIcon className="size-3.5" />
下载图片
</a>
@@ -1274,10 +1360,10 @@ function StudioPage() {
<Dialog open={Boolean(zoomImageUrl)} onOpenChange={(o) => !o && setZoomImageUrl(null)}>
<DialogContent className="max-h-[92vh] w-[95vw] max-w-4xl overflow-y-auto p-4 sm:max-w-4xl">
<DialogHeader className="flex flex-row items-center justify-between pr-6">
- <DialogTitle className="text-base">生成结果大图预览</DialogTitle>
+ <div><DialogTitle className="text-base">图片大图预览</DialogTitle><DialogDescription className="sr-only">参考图片或生成结果的放大预览。按 Esc 或关闭按钮返回。</DialogDescription></div>
{zoomImageUrl && (
<Button size="sm" variant="outline" asChild>
- <a href={zoomImageUrl} download="character-result.png">
+ <a href={zoomImageUrl} download="image.png">
<DownloadIcon className="size-3.5" />
下载原图
</a>
diff --git a/src/services/aiGenerator.ts b/src/services/aiGenerator.ts
index cb8e6b6..c89be36 100644
--- a/src/services/aiGenerator.ts
+++ b/src/services/aiGenerator.ts
@@ -154,19 +154,25 @@ export function buildRecipePrompt(recipe: RecipeState, stylePreset = 'realistic'
? recipe.portrait.标题
: recipe.portrait.发长
clauses.push(
- `• 【图${idx}(人像参考)】:保持图${idx}人物的五官脸型、发色与「${hairDesc}」发型气质一致。`
+ recipe.portrait.source === 'upload'
+ ? `• 【图${idx}(人像参考)】:保持图${idx}人物的五官脸型、发色与发型一致。`
+ : `• 【图${idx}(人像参考)】:保持图${idx}人物的五官脸型、发色与「${hairDesc}」发型气质一致。`
)
idx++
}
if (recipe.costume) {
clauses.push(
- `• 【图${idx}(服装参考)】:穿上图${idx}中的完整服饰「${recipe.costume.服装名称}」,还原面料质感与剪裁。`
+ recipe.costume.source === 'upload'
+ ? `• 【图${idx}(服装参考)】:穿上图${idx}中的完整服饰,还原颜色、面料质感与剪裁。`
+ : `• 【图${idx}(服装参考)】:穿上图${idx}中的完整服饰「${recipe.costume.服装名称}」,还原面料质感与剪裁。`
)
idx++
}
if (recipe.pose) {
clauses.push(
- `• 【图${idx}(姿势参考)】:身体姿态与镜头透视遵循图${idx}「${recipe.pose.姿势名称}」【${recipe.pose.角度}】(仅参考骨架动作,忽略素体白模材质)。`
+ recipe.pose.source === 'upload'
+ ? `• 【图${idx}(姿势参考)】:身体姿态与镜头透视遵循图${idx},仅参考姿势,不复制人物外观与服装。`
+ : `• 【图${idx}(姿势参考)】:身体姿态与镜头透视遵循图${idx}「${recipe.pose.姿势名称}」【${recipe.pose.角度}】(仅参考骨架动作,忽略素体白模材质)。`
)
idx++
}
@@ -803,9 +809,8 @@ async function generateWithComfyUi(params: {
config: ApiConfig
baseUrl: string
apiKey: string
- model: string
}): Promise<{ imageUrl: string; modelUsed: string; providerUsed: ImageProviderId }> {
- const { recipe, prompt, config, baseUrl, apiKey, model } = params
+ const { recipe, prompt, config, baseUrl, apiKey } = params
const cp = config.comfyuiParams
const parsedInfo = parseComfyWorkflowNodes(cp.workflowJson)
if (!parsedInfo.valid) {
@@ -815,24 +820,36 @@ async function generateWithComfyUi(params: {
const workflow = JSON.parse(cp.workflowJson)
// 1. 按映射槽位上传参考图并注入节点
- const slotUploads: Array<{ nodeId: string; src: string | null; prefix: string }> = [
+ const slotUploads: Array<{ nodeId: string; src: string | null; prefix: string; label: string }> = [
{
nodeId: cp.portraitNodeId,
src: recipe.portrait ? recipe.portrait.原图 || recipe.portrait.缩略图 : null,
prefix: 'studio_portrait',
+ label: '人像',
},
{
nodeId: cp.costumeNodeId,
src: recipe.costume ? recipe.costume.预览图 || recipe.costume.原图 || recipe.costume.缩略图 : null,
prefix: 'studio_costume',
+ label: '服装',
},
{
nodeId: cp.poseNodeId,
src: recipe.pose ? recipe.pose.原图 || recipe.pose.缩略图 : null,
prefix: 'studio_pose',
+ label: '姿势',
},
]
+ const invalidSlots = slotUploads.filter((slot) => slot.nodeId && slot.nodeId !== 'none' && !parsedInfo.imageNodes.some((node) => node.id === slot.nodeId))
+ if (invalidSlots.length) {
+ throw new Error(`[ComfyUI] ${invalidSlots.map((slot) => slot.label).join('、')}节点映射已失效,请重新识别或选择节点`)
+ }
+ const missingSlots = slotUploads.filter((slot) => slot.nodeId && slot.nodeId !== 'none' && !slot.src)
+ if (missingSlots.length) {
+ throw new Error(`[ComfyUI] 请先选择或上传:${missingSlots.map((slot) => slot.label).join('、')}`)
+ }
+
for (const slot of slotUploads) {
if (slot.nodeId && slot.nodeId !== 'none' && slot.src && workflow[slot.nodeId]?.inputs) {
const uploadedName = await uploadImageToComfy(baseUrl, slot.src, slot.prefix, apiKey)
@@ -930,9 +947,9 @@ async function generateWithComfyUi(params: {
const viewUrl = `${baseUrl}/view?${qs.toString()}`
try {
const imgDataUrl = await srcToPngDataUrl(viewUrl)
- return { imageUrl: imgDataUrl, modelUsed: model || 'comfyui', providerUsed: 'comfyui' }
+ return { imageUrl: imgDataUrl, modelUsed: 'ComfyUI 工作流', providerUsed: 'comfyui' }
} catch {
- return { imageUrl: viewUrl, modelUsed: model || 'comfyui', providerUsed: 'comfyui' }
+ return { imageUrl: viewUrl, modelUsed: 'ComfyUI 工作流', providerUsed: 'comfyui' }
}
}
}
@@ -966,14 +983,14 @@ export async function generateCharacterImage(params: {
}
const model = pCfg.model === 'custom' ? pCfg.customModel.trim() : pCfg.model
- if (!model) {
+ if (provider !== 'comfyui' && !model) {
throw new Error('请选择或填写有效的模型名称')
}
const baseUrl = (pCfg.baseUrl.trim() || PROVIDER_META[provider].defaultBaseUrl).replace(/\/+$/, '')
if (provider === 'comfyui') {
- return generateWithComfyUi({ recipe, prompt, config, baseUrl, apiKey, model })
+ return generateWithComfyUi({ recipe, prompt, config, baseUrl, apiKey })
}
// 判断当前请求是否需要转换为本地 Base64:
diff --git a/src/store/studioStore.tsx b/src/store/studioStore.tsx
index 185d6e3..edafaf2 100644
--- a/src/store/studioStore.tsx
+++ b/src/store/studioStore.tsx
@@ -12,6 +12,7 @@ import {
AlertDialogTitle,
} from '@/components/ui/alert-dialog'
import { idbGet, idbSet } from '@/lib/idbStorage'
+import { recipeBackup } from '@/lib/recipeImages'
import {
buildRecipePrompt,
COMFYUI_WORKFLOW_TEMPLATES,
@@ -236,7 +237,7 @@ export function StudioProvider({ children }: { children: ReactNode }) {
const [isGenerating, setIsGenerating] = useState(false)
const [generatingModel, setGeneratingModel] = useState('')
const isGeneratingRef = useRef(false)
- const idbHydratedRef = useRef(false)
+ const [idbHydrated, setIdbHydrated] = useState(false)
// 从 IndexedDB 异步恢复大容量历史记录与含附图的配方
useEffect(() => {
@@ -258,7 +259,7 @@ export function StudioProvider({ children }: { children: ReactNode }) {
setHistory(savedHistory)
setPreviewUrl((prev) => prev || savedHistory[0]?.imageUrl || '')
}
- idbHydratedRef.current = true
+ setIdbHydrated(true)
})
return () => {
active = false
@@ -266,15 +267,16 @@ export function StudioProvider({ children }: { children: ReactNode }) {
}, [])
useEffect(() => {
+ if (!idbHydrated) return
void idbSet(RECIPE_KEY, recipe)
try {
- // localStorage 仅保存轻量槽位备份,不存体积较大的 extraImages Base64
+ // 上传图片和附图完整保存在 IndexedDB,轻量备份不包含它们。
localStorage.setItem(
RECIPE_KEY,
- JSON.stringify({ ...recipe, extraImages: [] })
+ JSON.stringify(recipeBackup(recipe))
)
} catch {}
- }, [recipe])
+ }, [recipe, idbHydrated])
useEffect(() => {
try {
@@ -316,9 +318,9 @@ export function StudioProvider({ children }: { children: ReactNode }) {
}
useEffect(() => {
- if (!idbHydratedRef.current && history.length === 0) return
+ if (!idbHydrated) return
void idbSet(HISTORY_KEY, history.slice(0, 30))
- }, [history])
+ }, [history, idbHydrated])
const setPortrait = (portrait: PortraitItem | null) => setRecipe((r) => ({ ...r, portrait }))
const setCostume = (costume: CostumeItem | null) => setRecipe((r) => ({ ...r, costume }))
@@ -471,7 +473,9 @@ export function StudioProvider({ children }: { children: ReactNode }) {
const recipeSnapshot = recipe
const configSnapshot = apiConfig
const pCfg = configSnapshot.providers[configSnapshot.activeProvider]
- const modelName = pCfg.model === 'custom' ? pCfg.customModel || 'custom' : pCfg.model
+ const modelName = configSnapshot.activeProvider === 'comfyui'
+ ? 'ComfyUI 工作流'
+ : pCfg.model === 'custom' ? pCfg.customModel || 'custom' : pCfg.model
const finalPrompt =
overridePrompt ?? customPrompt ?? buildRecipePrompt(recipeSnapshot, configSnapshot.stylePreset)
@@ -489,8 +493,8 @@ export function StudioProvider({ children }: { children: ReactNode }) {
const extraCount = (recipeSnapshot.extraImages || []).length
const summary = [
recipeSnapshot.portrait?.发型名称,
- recipeSnapshot.costume?.分类,
- recipeSnapshot.pose ? `${recipeSnapshot.pose.姿势名称}(${recipeSnapshot.pose.角度})` : null,
+ recipeSnapshot.costume?.source === 'upload' ? recipeSnapshot.costume.服装名称 : recipeSnapshot.costume?.分类,
+ recipeSnapshot.pose ? `${recipeSnapshot.pose.姿势名称}${recipeSnapshot.pose.角度 ? `(${recipeSnapshot.pose.角度})` : ''}` : null,
extraCount ? `+${extraCount}附图` : null,
]
.filter(Boolean)
diff --git a/src/types/gallery.ts b/src/types/gallery.ts
index 5088efa..97bd937 100644
--- a/src/types/gallery.ts
+++ b/src/types/gallery.ts
@@ -1,4 +1,5 @@
export interface PoseItem {
+ source?: 'upload'
id: string
体系: string
姿势编号: string
@@ -22,6 +23,7 @@ export interface PoseGroup {
}
export interface CostumeItem {
+ source?: 'upload'
id: string
分类: string
服装名称: string
@@ -34,6 +36,7 @@ export interface CostumeItem {
}
export interface PortraitItem {
+ source?: 'upload'
id: string
分区: string
发长: string