From 0cb8696b2c2f9885e5bad9bf4b91ab03423a055f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期三, 13 三月 2024 15:05:12 +0800
Subject: [PATCH] Merge branch 'master' of http://47.97.1.152:5880/r/zy-asrs-master

---
 zy-asrs-flow/src/components/Flow/GraphTools.jsx |  170 ++++++++++++++++++++++----------------------------------
 1 files changed, 66 insertions(+), 104 deletions(-)

diff --git a/zy-asrs-flow/src/components/Flow/GraphTools.jsx b/zy-asrs-flow/src/components/Flow/GraphTools.jsx
index e8d6518..e93b74b 100644
--- a/zy-asrs-flow/src/components/Flow/GraphTools.jsx
+++ b/zy-asrs-flow/src/components/Flow/GraphTools.jsx
@@ -2,7 +2,8 @@
 import { Button, message, Modal } from 'antd';
 import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
 import { solarizedlight } from 'react-syntax-highlighter/dist/esm/styles/prism';
-import './GraphTools.less'
+import { exportDataToServer } from "../../services/flow/api";
+import './css/GraphTools.less'
 
 export const GraphTools = ({ graphRef, isReady }) => {
 
@@ -76,15 +77,16 @@
                 return;
             }
 
-            console.log(getDescendants(rootNode, nodes, graph));
-
-            const codeContent = transCode(rootNode, nodes, graph)
-            console.log(codeContent);
+            let result = sortNodes(rootNode, nodes, graph);
+            exportDataToServer({
+                data: result
+            }).then((res) => {
+                console.log(res);
+            })
         }
     }
 
-    const transCode = (rootNode, nodes, graph) => {
-        let codeContent = "";
+    const sortNodes = (rootNode, nodes, graph) => {
         let values = nodeDFS(rootNode, nodes, graph);
         const searchNode = {
             id: 1,
@@ -93,7 +95,6 @@
         };
 
         let cpValues = JSON.parse(JSON.stringify(values))
-        console.log(cpValues);
 
         let searchIndex = 0;
         cpValues.forEach((value) => {
@@ -131,6 +132,56 @@
             }
         })
 
+        return cpValues;
+    }
+
+    const transCode = (rootNode, nodes, graph) => {
+        let codeContent = "";
+
+        let values = nodeDFS(rootNode, nodes, graph);
+        const searchNode = {
+            id: 1,
+            parent: null,
+            logicBool: true
+        };
+
+        let cpValues = JSON.parse(JSON.stringify(values))
+
+        let searchIndex = 0;
+        cpValues.forEach((value) => {
+            if (value.data.isLogic) {
+                value.data.searchLogicId = searchNode.id;
+                value.data.searchLogicBool = searchNode.logicBool;
+                value.data.searchIndex = searchIndex++;
+
+                let tmpSearchNode = JSON.parse(JSON.stringify(searchNode))
+                searchNode.parent = tmpSearchNode;
+                searchNode.id = value.id;
+                searchNode.logicBool = null;
+                searchIndex = 0;
+            } else {
+                let id = searchNode.id;
+                let logicBool = searchNode.logicBool;
+
+                const connectedEdges = graph.getConnectedEdges(value);//鍙栬竟
+                connectedEdges.forEach((edge) => {
+                    let tmpSearchNode = JSON.parse(JSON.stringify(searchNode));
+                    while (tmpSearchNode.parent != null) {
+                        if (edge.source.cell == tmpSearchNode.id) {
+                            logicBool = edge.data.logicBool;//鏇存柊鏂瑰悜
+                            searchNode.logicBool = edge.data.logicBool;
+                            id = tmpSearchNode.id;
+                            break;
+                        }
+                        tmpSearchNode = tmpSearchNode.parent;
+                    }
+                })
+
+                value.data.searchLogicId = id;
+                value.data.searchLogicBool = logicBool;
+                value.data.searchIndex = searchIndex++;
+            }
+        })
         console.log(cpValues);
         console.log(searchNode);
 
@@ -197,6 +248,8 @@
             obj.id = key;
             sortTmp[tmp[key].index] = obj;
         }
+
+        console.log(sortTmp);
 
         // 鍚堝苟True鍜孎alse
         sortTmp.forEach((item) => {
@@ -287,104 +340,13 @@
         return formattedCode;
     }
 
-    // const transCode = (rootNode, nodes, graph) => {
-    //     let codeContent = "";
-    //     const descendants = [];
-    //     let stack = [rootNode];
-
-    //     let count = 0;
-    //     while (stack.length > 0) {
-    //         const current = stack.pop();
-    //         descendants.push(current);
-
-    //         const children = getChildren(current, nodes, graph);
-    //         stack.push(...children);
-
-    //         // 杈撳嚭浠g爜
-    //         if (!current.data.isLogic) {
-    //             const connectedEdges = graph.getConnectedEdges(current);//鍙栬竟
-    //             connectedEdges.forEach((edge) => {
-    //                 //杩囨护浠庤嚜韬妭鐐瑰嚭鍘荤殑杈�
-    //                 if(edge.source.cell != current.id){
-    //                     //鍙栦笂涓�鑺傜偣
-    //                     let lastNode = null;
-    //                     nodes.forEach((node) => {
-    //                         if(node.id == edge.source.cell){
-    //                             lastNode = node;
-    //                         }
-    //                     })
-
-    //                     if(lastNode != null) {
-    //                         //鍒ゆ柇鑺傜偣鏄惁閫昏緫鑺傜偣
-    //                         if(lastNode.data.isLogic){
-    //                             console.log(lastNode);
-    //                             let nestedIfCode = "";
-    //                             if(lastNode.data.logicBool == 'true') {
-    //                                 nestedIfCode = `
-    //                                 if (${lastNode.data.codeContent}) {
-    //                                     ${current.data.codeContent}
-    //                                 }
-    //                                 `;
-    //                             }else{
-    //                                 nestedIfCode = `
-    //                                 if (!(${lastNode.data.codeContent})) {
-    //                                     ${current.data.codeContent}
-    //                                 }
-    //                                 `;
-    //                             }
-
-
-    //                             codeContent += "\n" + nestedIfCode;
-    //                             console.log(codeContent);
-    //                         }else{
-    //                             if (current.data.codeContent != null) {
-    //                                 codeContent += "\n" + current.data.codeContent;
-    //                             }
-    //                         }
-    //                     }
-    //                 }
-    //                 console.log(current);
-    //             })
-    //         } else {
-    //             // if (current.data.codeContent != null) {
-    //             //     codeContent += "\n" + current.data.codeContent;
-    //             // }
-
-    //             // const connectedEdges = graph.getConnectedEdges(current);
-    //             // console.log(connectedEdges);
-    //             // stack = []
-    //             // let test = []
-    //             // connectedEdges.forEach((edge) => {
-    //             //     nodes.forEach((item) => {
-    //             //         if (item.id === edge.target.cell && item.id != current.id) {
-    //             //             test.push(item);
-    //             //         }
-    //             //     })
-    //             // });
-    //             // console.log(test);
-    //             // console.log();
-    //             // let nestedIfCode = `
-    //             // if (true}) {
-    //             //     ${current.data.codeContent}
-    //             // }
-    //             // `;
-
-    //             // codeContent += "\n" + nestedIfCode;
-    //             // console.log(codeContent);
-    //         }
-
-    //     }
-
-    //     console.log(codeContent);
-    // }
-
     const nodeDFS = (node, nodes, graph) => {
         let values = [];
         if (graph) {
             const connectedEdges = graph.getConnectedEdges(node);
             const children = [];
 
-            console.log(node);
+            // console.log(node);
             connectedEdges.forEach((edge) => {
                 nodes.forEach((item) => {
                     if (item.id === edge.target.cell && item.id != node.id) {
@@ -393,11 +355,11 @@
                 })
             });
 
-            console.log(connectedEdges);
+            // console.log(connectedEdges);
             if (children.length != 0) {
-                console.log(children);
+                // console.log(children);
                 children.forEach((node) => {
-                    console.log(node);
+                    // console.log(node);
                     values.push(node);
                     values = values.concat(nodeDFS(node, nodes, graph))
                 })
@@ -450,7 +412,7 @@
                 </Button>
             </div>
 
-            <Modal title="Basic Modal" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}>
+            <Modal title="棰勮浠g爜" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}>
                 <SyntaxHighlighter language="java" style={solarizedlight}>
                     {preCode}
                 </SyntaxHighlighter>

--
Gitblit v1.9.1