|
| 1 | +import React, {useEffect, useRef} from "react"; |
| 2 | +import {FlowData} from "@/components/Flow/flow/data"; |
| 3 | +import {LogicFlow} from "@logicflow/core"; |
| 4 | +import {DndPanel, Menu, MiniMap, Snapshot} from "@logicflow/extension"; |
| 5 | +import Start from "@/components/Flow/nodes/Start"; |
| 6 | +import Node from "@/components/Flow/nodes/Node"; |
| 7 | +import Over from "@/components/Flow/nodes/Over"; |
| 8 | +import Circulate from "@/components/Flow/nodes/Circulate"; |
| 9 | +import '@logicflow/core/es/index.css'; |
| 10 | +import '@logicflow/extension/lib/style/index.css'; |
| 11 | +import "./FlowChart.scss"; |
| 12 | + |
| 13 | +interface FlowChartProps { |
| 14 | + flowData: FlowData |
| 15 | +} |
| 16 | + |
| 17 | +const FlowChart: React.FC<FlowChartProps> = (props) => { |
| 18 | + |
| 19 | + const flowData = props.flowData; |
| 20 | + |
| 21 | + const container = useRef<HTMLDivElement>(null); |
| 22 | + const lfRef = useRef<LogicFlow>(null); |
| 23 | + |
| 24 | + useEffect(() => { |
| 25 | + const SilentConfig = { |
| 26 | + isSilentMode: true, |
| 27 | + stopScrollGraph: false, |
| 28 | + stopMoveGraph: false, |
| 29 | + stopZoomGraph: false, |
| 30 | + edgeTextEdit: false, |
| 31 | + }; |
| 32 | + |
| 33 | + //@ts-ignore |
| 34 | + lfRef.current = new LogicFlow({ |
| 35 | + //@ts-ignore |
| 36 | + container: container.current, |
| 37 | + ...SilentConfig, |
| 38 | + background: { |
| 39 | + backgroundColor: '#f3f5f8' |
| 40 | + }, |
| 41 | + plugins: [Menu, DndPanel, MiniMap, Snapshot], |
| 42 | + grid: false, |
| 43 | + edgeType: 'bezier', |
| 44 | + }); |
| 45 | + |
| 46 | + lfRef.current.setTheme({ |
| 47 | + bezier: { |
| 48 | + stroke: '#8f94e3', |
| 49 | + strokeWidth: 1, |
| 50 | + }, |
| 51 | + }); |
| 52 | + lfRef.current.register(Start); |
| 53 | + lfRef.current.register(Node); |
| 54 | + lfRef.current.register(Over); |
| 55 | + lfRef.current.register(Circulate); |
| 56 | + |
| 57 | + lfRef.current.render(flowData.getFlowSchema()); |
| 58 | + }, []); |
| 59 | + |
| 60 | + return ( |
| 61 | + <> |
| 62 | + <div className="flow-chart-content"> |
| 63 | + <div className={"flow-view"} ref={container}/> |
| 64 | + </div> |
| 65 | + </> |
| 66 | + ) |
| 67 | +} |
| 68 | + |
| 69 | +export default FlowChart; |
0 commit comments