|  |  |  | 
|---|
|  |  |  | 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 }) => { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | 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, | 
|---|
|  |  |  | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let cpValues = JSON.parse(JSON.stringify(values)) | 
|---|
|  |  |  | console.log(cpValues); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let searchIndex = 0; | 
|---|
|  |  |  | cpValues.forEach((value) => { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | obj.id = key; | 
|---|
|  |  |  | sortTmp[tmp[key].index] = obj; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | console.log(sortTmp); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 合并True和False | 
|---|
|  |  |  | sortTmp.forEach((item) => { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //         // 输出代码 | 
|---|
|  |  |  | //         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) { | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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)) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | 
|---|
|  |  |  | </Button> | 
|---|
|  |  |  | </div> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <Modal title="Basic Modal" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}> | 
|---|
|  |  |  | <Modal title="预览代码" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}> | 
|---|
|  |  |  | <SyntaxHighlighter language="java" style={solarizedlight}> | 
|---|
|  |  |  | {preCode} | 
|---|
|  |  |  | </SyntaxHighlighter> | 
|---|