Przeglądaj źródła

fix: 修改流程图连线问题

liaojiaxing 4 miesięcy temu
rodzic
commit
af772ac929

+ 15 - 0
apps/designer/src/components/ExportImage.tsx

@@ -25,6 +25,7 @@ const ExportComponent = ({
   const printGraph = useRef<Graph>();
   const data = graph.toJSON();
   console.log(data)
+  const pageNode = data.cells.filter((cell) => cell?.data?.isPage)?.[0];
   data.cells = data.cells.filter((cell) => !cell?.data?.isPage);
   data.cells.forEach((cell) => {
     if(cell.data) {
@@ -46,6 +47,20 @@ const ExportComponent = ({
         minScale: 0.2,
         maxScale: 2,
       },
+      embedding: {
+        enabled: true,
+        findParent({ node }) {
+          const bbox = node.getBBox();
+          return this.getNodes().filter((node) => {
+            const data = node.getData<{ isPage: boolean }>();
+            if (data && data.isPage) {
+              const targetBBox = node.getBBox();
+              return bbox.isIntersectWithRect(targetBBox);
+            }
+            return false;
+          });
+        },
+      },
       interacting: {
         edgeLabelMovable: false,
         edgeMovable: false,

+ 13 - 14
apps/designer/src/models/graphModel.ts

@@ -77,14 +77,15 @@ export default function GraphModel() {
         },
       ],
     });
+    return pageNodeRef.current;
   };
 
   const initCells = (cells: Cell.Properties[]) => {
     if (graphRef.current) {
       // 添加节点
-      (cells || []).forEach((item) => {
+      const list = (cells || []).map((item) => {
         if (item.shape !== "edge")  {
-          graphRef.current?.addNode({
+          return {
             ...item,
             data: JSON.parse(item?.data),
             ports: JSON.parse(item?.ports  || "{}"),
@@ -96,22 +97,19 @@ export default function GraphModel() {
                 menu: nodeMenu,
               },
             }]
-          });
+          };
         }
-      });
-      // 添加边
-      (cells || []).forEach((item) => {
         if (item.shape === "edge") {
-          graphRef.current?.addEdge({
+          return {
             ...item,
             data: JSON.parse(item?.data),
             attrs: JSON.parse(item?.attrs as unknown as string || "{}"),
             source: JSON.parse(item?.source),
             target: JSON.parse(item?.target),
-            connector: item?.connector ? JSON.parse(item.connector) : undefined,
-            labels: item?.labels ? JSON.parse(item.labels) : undefined,
-            router: 'manhattan',
-            // router: JSON.parse(item?.router || "{}"),
+            ...(item?.connector ? {connector: JSON.parse(item.connector)} : {}),
+            ...(item?.labels ? {labels: JSON.parse(item.labels)} : {}),
+            // router: 'manhattan',
+            router: item.router,
             tools: [
               {
                 name: "contextmenu",
@@ -120,10 +118,11 @@ export default function GraphModel() {
                 },
               },
             ]
-          });
+          };
         }
-      })
-
+      });
+      graphRef.current.fromJSON({ cells: list as any });
+      addPageNode();
       graphRef.current.on("cell:change:*", handleChangeAll);
       handleGraphApiEvent(graphRef.current);
     }