fix: 切换画布时清空状态并重新加载数据
This commit is contained in:
parent
1e557c620a
commit
97daaeeb36
@ -105,6 +105,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
const undo = useCanvasStore((state) => state.undo);
|
||||
const redo = useCanvasStore((state) => state.redo);
|
||||
const loadCanvas = useCanvasStore((state) => state.loadCanvas);
|
||||
const clearCanvas = useCanvasStore((state) => state.clearCanvas);
|
||||
const getCanvasState = useCanvasStore((state) => state.getCanvasState);
|
||||
const addNode = useCanvasStore((state) => state.addNode);
|
||||
const updateNode = useCanvasStore((state) => state.updateNode);
|
||||
@ -134,6 +135,10 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
useEffect(() => {
|
||||
const loadProject = async () => {
|
||||
setIsLoading(true);
|
||||
|
||||
// 🆕 先清空当前画布状态,确保切换时不会显示旧数据
|
||||
clearCanvas();
|
||||
|
||||
const result = await canvasService.getProject(id);
|
||||
|
||||
if (result.success && result.data) {
|
||||
@ -156,7 +161,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
};
|
||||
|
||||
loadProject();
|
||||
}, [id]);
|
||||
}, [id, clearCanvas, setProject, loadCanvas]);
|
||||
|
||||
// 自动保存逻辑
|
||||
useEffect(() => {
|
||||
|
||||
@ -52,7 +52,9 @@ export function CanvasFileListPanel({ currentId, onClose }: CanvasFileListPanelP
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
// 使用 router.push 并关闭面板,让页面组件的 useEffect 处理加载
|
||||
router.push(`/canvas/${id}`);
|
||||
onClose(); // 关闭文件列表面板,切换到聊天面板
|
||||
};
|
||||
|
||||
// 删除画布
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user