diff --git a/app/canvas/[id]/page.tsx b/app/canvas/[id]/page.tsx index 02658ed1f..911ee17fb 100644 --- a/app/canvas/[id]/page.tsx +++ b/app/canvas/[id]/page.tsx @@ -347,6 +347,7 @@ export default function CanvasEditorPage({ params }: PageProps) { const [agentProjectDeletedResultCollections, setAgentProjectDeletedResultCollections] = useState({}); const [isAgentProjectLoading, setIsAgentProjectLoading] = useState(false); + const [loadedAgentProjectId, setLoadedAgentProjectId] = useState(null); const [isAgentProjectSaving, setIsAgentProjectSaving] = useState(false); const [isAgentProjectSheetOpen, setIsAgentProjectSheetOpen] = useState(false); const [isAgentProjectMenuOpen, setIsAgentProjectMenuOpen] = useState(false); @@ -408,6 +409,8 @@ export default function CanvasEditorPage({ params }: PageProps) { const isCanvasAgentModeEnabled = siteSettingsData?.canvasAgentModeEnabled !== false; const isAgentMode = isAgentWorkspaceEnabled && requestedAgentMode; + const hasLoadedCurrentAgentProject = + !requestedAgentMode || !agentProjectId || loadedAgentProjectId === agentProjectId; const resolvedBrandModelConfig = useMemo( () => normalizeAgentWorkflowBrandModelConfig(siteSettingsData?.agentWorkflowBrandModelConfig), [siteSettingsData?.agentWorkflowBrandModelConfig] @@ -526,6 +529,7 @@ export default function CanvasEditorPage({ params }: PageProps) { setAgentProjectThumbnail(null); setAgentProjectResultCollections({}); setAgentProjectDeletedResultCollections({}); + setLoadedAgentProjectId(null); // 🆕 先清空当前画布状态,确保切换时不会显示旧数据 useCanvasStore.getState().clearCanvas(); @@ -886,6 +890,7 @@ export default function CanvasEditorPage({ params }: PageProps) { const loadAgentProject = async () => { setIsAgentProjectMenuOpen(false); setIsAgentProjectLoading(true); + setLoadedAgentProjectId(null); try { const result = await agentProjectService.getProject(agentProjectId); if (!result.success || !result.data) { @@ -921,6 +926,7 @@ export default function CanvasEditorPage({ params }: PageProps) { setAgentProjectDeletedResultCollections( persistedState.deletedResultCollections || {} ); + setLoadedAgentProjectId(agentProjectId); } catch (error) { if (!cancelled) { toast.error(error instanceof Error ? error.message : "加载生图项目失败"); @@ -945,7 +951,14 @@ export default function CanvasEditorPage({ params }: PageProps) { }, [isAgentProjectSheetOpen]); useEffect(() => { - if (!isAgentMode || !agentProjectId || isAgentProjectLoading) return; + if ( + !isAgentMode || + !agentProjectId || + isAgentProjectLoading || + !hasLoadedCurrentAgentProject + ) { + return; + } const timer = window.setTimeout(async () => { setIsAgentProjectSaving(true); @@ -967,6 +980,7 @@ export default function CanvasEditorPage({ params }: PageProps) { currentAgentStage, isAgentMode, isAgentProjectLoading, + hasLoadedCurrentAgentProject, persistAgentProject, selectedAgentPresetId, selectedBrandModel, diff --git a/components/agents/AgentGenerationWorkspaceDarkV2.tsx b/components/agents/AgentGenerationWorkspaceDarkV2.tsx index 8ab6e3bf0..58a89efb4 100644 --- a/components/agents/AgentGenerationWorkspaceDarkV2.tsx +++ b/components/agents/AgentGenerationWorkspaceDarkV2.tsx @@ -1053,8 +1053,6 @@ export function AgentGenerationWorkspaceDarkV2({ detailReplacementState.method === "ai_detail_generate" ? "ai_detail_generate" : "reference_replace"; - const isDetailAiGenerationMethod = - Boolean(selectedAgentPresetId) && detailReplacementMethod === "ai_detail_generate"; const presetModeConfig = useMemo( () => normalizeAgentPresetModeConfig(selectedAgentPreset?.defaultParams), [selectedAgentPreset?.defaultParams] @@ -1065,6 +1063,8 @@ export function AgentGenerationWorkspaceDarkV2({ selectedAgentPreset?.type === "image" && presetModeConfig.modeType === "detail_replacement"; const isSkuReplacementPreset = selectedAgentPreset?.type === "image" && presetModeConfig.modeType === "sku_replacement"; + const isDetailAiGenerationMethod = + isDetailReplacementPreset && detailReplacementMethod === "ai_detail_generate"; const isReplacementPreset = (isDetailReplacementPreset && !isDetailAiGenerationMethod) || isSkuReplacementPreset; const currentResultModeType: AgentGenerationResultModeType = diff --git a/components/agents/AgentProjectListSheet.tsx b/components/agents/AgentProjectListSheet.tsx index 338fb5d9a..90d85e32f 100644 --- a/components/agents/AgentProjectListSheet.tsx +++ b/components/agents/AgentProjectListSheet.tsx @@ -19,6 +19,23 @@ import { cn } from "@/lib/utils"; import { buildImageProxyUrl } from "@/lib/image-delivery"; import type { AgentGenerationProject } from "@/types/agent"; +function getProjectPreviewUrl(project: AgentGenerationProject) { + const explicitThumbnail = String(project.thumbnail || "").trim(); + if (explicitThumbnail) { + return explicitThumbnail; + } + + const resultCollections = project.projectState?.resultCollections; + const fallbackUrl = + resultCollections?.scene_generation?.[0] || + resultCollections?.detail_generation?.[0] || + resultCollections?.detail_replacement?.[0] || + resultCollections?.sku_replacement?.[0] || + ""; + + return String(fallbackUrl || "").trim() || null; +} + interface AgentProjectListSheetProps { open: boolean; onOpenChange: (open: boolean) => void; @@ -98,7 +115,10 @@ export function AgentProjectListSheet({ ) : projects.length > 0 ? ( - projects.map((project) => ( + projects.map((project) => { + const previewUrl = getProjectPreviewUrl(project); + + return ( - )) + ); + }) ) : (
还没有生图项目