diff --git a/src/pages/flowEditor/index.tsx b/src/pages/flowEditor/index.tsx new file mode 100644 index 0000000..a1dfe02 --- /dev/null +++ b/src/pages/flowEditor/index.tsx @@ -0,0 +1,94 @@ +import React, { useState, useCallback } from 'react'; +import { + ReactFlow, + applyNodeChanges, + applyEdgeChanges, + addEdge, + Background, + Controls, + Node, + Edge +} from '@xyflow/react'; +import '@xyflow/react/dist/style.css'; +import TextUpdaterNode from './node/textUpdateNode/TextUpdaterNode'; + +const nodeTypes = { + textUpdater: TextUpdaterNode +}; + +const initialNodes: Node[] = [ + { + id: 'n1', + position: { x: 0, y: 0 }, + data: { label: 'Node 1' }, + type: 'input' + }, + { + id: 'node-1', + type: 'textUpdater', + position: { x: 150, y: 0 }, + data: { value: 123 } + }, + { + id: 'n2', + position: { x: 100, y: 100 }, + data: { label: 'Custom Node' } + } +]; + +const initialEdges: Edge[] = [ + { + id: 'n1-n2', + source: 'n1', + target: 'n2' + }, + { + id: 'n1-node-1', + source: 'n1', + target: 'node-1', + targetHandle: 'a' + }, + { + id: 'n2-node-1', + source: 'n2', + target: 'node-1', + targetHandle: 'a1' + } +]; + +const FlowEditor: React.FC = () => { + const [nodes, setNodes] = useState(initialNodes); + const [edges, setEdges] = useState(initialEdges); + + const onNodesChange = useCallback( + (changes: any) => setNodes((nodesSnapshot) => applyNodeChanges(changes, nodesSnapshot)), + [] + ); + const onEdgesChange = useCallback( + (changes: any) => setEdges((edgesSnapshot) => applyEdgeChanges(changes, edgesSnapshot)), + [] + ); + const onConnect = useCallback( + (params: any) => setEdges((edgesSnapshot) => addEdge(params, edgesSnapshot)), + [] + ); + + return ( +
+ + + + +
+ ); +}; + +export default React.memo(FlowEditor); \ No newline at end of file diff --git a/src/pages/flowEditor/node/handleNode/handleNode.tsx b/src/pages/flowEditor/node/handleNode/handleNode.tsx new file mode 100644 index 0000000..99dd2c2 --- /dev/null +++ b/src/pages/flowEditor/node/handleNode/handleNode.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { Handle, Position } from '@xyflow/react'; + +const CustomNode = ({ data }) => { + return ( + <> +
+ {data.label} +
+ + ); +}; + +export default CustomNode; \ No newline at end of file diff --git a/src/pages/flowEditor/node/textUpdateNode/TextUpdaterNode.module.less b/src/pages/flowEditor/node/textUpdateNode/TextUpdaterNode.module.less new file mode 100644 index 0000000..99e34e4 --- /dev/null +++ b/src/pages/flowEditor/node/textUpdateNode/TextUpdaterNode.module.less @@ -0,0 +1,8 @@ +.text-updater-node { + //width: 150px; + //height: 80px; + padding: 20px; + border-radius: 15px; + border: 1px solid #cccccc; + background-color: #fff; +} \ No newline at end of file diff --git a/src/pages/flowEditor/node/textUpdateNode/TextUpdaterNode.tsx b/src/pages/flowEditor/node/textUpdateNode/TextUpdaterNode.tsx new file mode 100644 index 0000000..a9f8a49 --- /dev/null +++ b/src/pages/flowEditor/node/textUpdateNode/TextUpdaterNode.tsx @@ -0,0 +1,30 @@ +import React, { useCallback } from 'react'; +import style from './TextUpdaterNode.module.less'; +import { Handle, NodeProps, Position } from '@xyflow/react'; + +interface TextUpdaterNodeData { + data?: string; + id?: string; +} + const TextUpdaterNode: React.FC = (props) => { + const onChange = useCallback((evt: React.ChangeEvent) => { + console.log(evt.target.value); + }, []); + + return ( +
+
+ + +
+ + + + + + +
+ ); +}; + +export default TextUpdaterNode; \ No newline at end of file diff --git a/src/pages/ideContainer/index.tsx b/src/pages/ideContainer/index.tsx index 6c86cea..260c659 100644 --- a/src/pages/ideContainer/index.tsx +++ b/src/pages/ideContainer/index.tsx @@ -4,6 +4,7 @@ import SideBar from './sideBar'; import LogBar from './logBar'; import RightSideBar from './rightSideBar'; import { getUrlParams } from '@/utils/common'; +import ProjectContainer from '@/pages/orchestration/project'; interface Selected { currentPath?: string; @@ -15,7 +16,6 @@ type UrlParamsOptions = { [key: string]: string }; -const AppFlowComponent = () =>
应用编排
; const CompListComponent = () =>
组件列表
; const AppInstanceComponent = () =>
应用实例
; const EventComponent = () =>
事件
; @@ -40,7 +40,7 @@ function IDEContainer() { const renderContent = () => { switch (selected.currentPath) { case 'appFlow': - return ; + return ; case 'compList': return ; case 'appInstance': diff --git a/src/pages/orchestration/project/index.tsx b/src/pages/orchestration/project/index.tsx new file mode 100644 index 0000000..21842d4 --- /dev/null +++ b/src/pages/orchestration/project/index.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import FlowEditor from '@/pages/flowEditor/index'; + +const ProjectContainer = () => { + return ( + + ); +}; + +export default ProjectContainer; \ No newline at end of file