Prechádzať zdrojové kódy

fix: 修复父子节点拖拽问题

liaojiaxing 3 dní pred
rodič
commit
af39df2e32

+ 0 - 8
apps/designer/src/models/mindMapModel.ts

@@ -64,14 +64,6 @@ export default function mindMapModel() {
     setProjectInfo(info);
     projectInfoRef.current = info;
     sessionStorage.setItem("mindMapProjectInfo", JSON.stringify(info));
-    console.log(
-      "setMindProjectInfo",
-      info,
-      init,
-      isSetting,
-      ignoreRender,
-      ignoreHistory
-    );
     
     // 初始化加载数据 清空画布
     if (init) {

+ 13 - 10
apps/designer/src/utils/mindmap/index.tsx

@@ -57,7 +57,7 @@ export const renderMindMap = ({
     }
     const offsetX = originPosition.x - result.x;
     const offsetY = originPosition.y - result.y;
-    const traverse = (hierarchyItem: HierarchyResult, parent?: Node) => {
+    const traverse = (hierarchyItem: HierarchyResult) => {
       if (hierarchyItem) {
         const { data, children, x, y } = hierarchyItem;
         const id = data?.id || uuid();
@@ -106,7 +106,6 @@ export const renderMindMap = ({
           cells.push(...(summaryCells || []));
         }
         cells.push(node);
-        parent && parent.addChild(node);
         if (data?.links) {
           cells.push(...data.links.map((item) => graph.createEdge(item)));
         }
@@ -127,7 +126,7 @@ export const renderMindMap = ({
               node.addChild(edge);
             }
             // 递归遍历
-            traverse(item, node);
+            traverse(item);
           });
         }
       }
@@ -163,6 +162,17 @@ export const renderMindMap = ({
   const edgeCells = cells.filter((cell) => cell.isEdge());
   graph.removeCells(edgeCells);
   graph.addCell(edgeCells);
+  // 处理父子节点关系
+  cells.forEach((cell) => {
+    const data = cell.getData();
+    if (data?.parentId) {
+      const parent = graph.getCellById(data.parentId);
+      const child = graph.getCellById(cell.id);
+      if(parent && child) {
+        parent.addChild(child);
+      }
+    }
+  });
 };
 
 // 渲染概要
@@ -325,13 +335,6 @@ export const addTopic = (
     projectInfo.topics.push(topic);
   }
 
-  // if(sessionStorage.getItem("projectId") && !topic.parentId) {
-  //   AddMindMapElement({
-  //     ...topic,
-  //     graphId: sessionStorage.getItem("projectId"),
-  //   });
-  // }
-
   setMindProjectInfo(projectInfo);
   
   return topic;