From 92a78abd639af9b2eed4391cc235fb4843c04ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=81=E6=B6=9B?= Date: Sun, 14 Sep 2025 06:21:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=BB=93=E6=9E=9C=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useImageGeneration.ts | 13 ------------- src/store/useAppStore.ts | 11 ++++++++++- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/hooks/useImageGeneration.ts b/src/hooks/useImageGeneration.ts index 7bda117..d03724e 100644 --- a/src/hooks/useImageGeneration.ts +++ b/src/hooks/useImageGeneration.ts @@ -53,19 +53,6 @@ export const useImageGeneration = () => { addGeneration(generation); setCanvasImage(outputAssets[0].url); - - // 如果没有项目则创建项目 - if (!currentProject) { - const newProject = { - id: generateId(), - title: '未命名项目', - generations: [generation], - edits: [], - createdAt: Date.now(), - updatedAt: Date.now() - }; - setCurrentProject(newProject); - } } setIsGenerating(false); }, diff --git a/src/store/useAppStore.ts b/src/store/useAppStore.ts index 33bc433..b564797 100644 --- a/src/store/useAppStore.ts +++ b/src/store/useAppStore.ts @@ -1,6 +1,7 @@ import { create } from 'zustand'; import { devtools } from 'zustand/middleware'; import { Project, Generation, Edit, SegmentationMask, BrushStroke } from '../types'; +import { generateId } from '../utils/imageUtils'; interface AppState { // 当前项目 @@ -140,7 +141,15 @@ export const useAppStore = create()( ...state.currentProject, generations: [...state.currentProject.generations, generation], updatedAt: Date.now() - } : null + } : { + // 如果没有项目,创建一个新项目包含此生成记录 + id: generateId(), + title: '未命名项目', + generations: [generation], + edits: [], + createdAt: Date.now(), + updatedAt: Date.now() + } })), addEdit: (edit) => set((state) => ({