fix agent project persistence recovery
This commit is contained in:
parent
cd44deb8c4
commit
243e12cc0e
@ -347,6 +347,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
const [agentProjectDeletedResultCollections, setAgentProjectDeletedResultCollections] =
|
||||
useState<AgentGenerationProjectResultCollections>({});
|
||||
const [isAgentProjectLoading, setIsAgentProjectLoading] = useState(false);
|
||||
const [loadedAgentProjectId, setLoadedAgentProjectId] = useState<string | null>(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,
|
||||
|
||||
@ -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 =
|
||||
|
||||
@ -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({
|
||||
<Loader2 className="h-6 w-6 animate-spin text-white/50" />
|
||||
</div>
|
||||
) : projects.length > 0 ? (
|
||||
projects.map((project) => (
|
||||
projects.map((project) => {
|
||||
const previewUrl = getProjectPreviewUrl(project);
|
||||
|
||||
return (
|
||||
<button
|
||||
key={project.id}
|
||||
type="button"
|
||||
@ -114,9 +134,9 @@ export function AgentProjectListSheet({
|
||||
)}
|
||||
>
|
||||
<div className="h-14 w-14 shrink-0 overflow-hidden rounded-xl border border-white/10 bg-black/30">
|
||||
{project.thumbnail ? (
|
||||
{previewUrl ? (
|
||||
<img
|
||||
src={buildImageProxyUrl(project.thumbnail, {
|
||||
src={buildImageProxyUrl(previewUrl, {
|
||||
width: 160,
|
||||
quality: 82,
|
||||
format: "webp",
|
||||
@ -197,7 +217,8 @@ export function AgentProjectListSheet({
|
||||
)}
|
||||
</Button>
|
||||
</button>
|
||||
))
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<div className="rounded-2xl border border-dashed border-white/10 bg-white/[0.02] px-4 py-12 text-center">
|
||||
<div className="text-sm text-white/70">还没有生图项目</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user