-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:config-components && add node status
- Loading branch information
summer
committed
Nov 14, 2023
1 parent
4785c12
commit 2fd21a1
Showing
3 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { Node } from '@antv/xflow'; | ||
import { useGraphInstance } from '@antv/xflow'; | ||
import { Drawer } from 'antd'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
interface NodeData { | ||
label?: string; | ||
status?: 'default' | 'running' | 'success' | 'failed'; | ||
} | ||
|
||
const ConfigDrawer = () => { | ||
const graph = useGraphInstance(); | ||
const [open, SetOpen] = useState(false); | ||
const [nodeData, setNodeData] = useState<NodeData>({}); | ||
|
||
const onClose = () => { | ||
SetOpen(false); | ||
setNodeData({}); | ||
}; | ||
|
||
useEffect(() => { | ||
if (graph) { | ||
graph.on('node:click', ({ node }: { node: Node }) => { | ||
const data = node.getData(); | ||
SetOpen(true); | ||
setNodeData(data); | ||
}); | ||
|
||
graph.on('blank:click', () => { | ||
onClose(); | ||
}); | ||
} | ||
}, [graph]); | ||
|
||
return ( | ||
<Drawer | ||
width={300} | ||
open={open} | ||
title="组件信息" | ||
destroyOnClose | ||
mask={false} | ||
onClose={onClose} | ||
> | ||
<div>组件名:{nodeData?.label}</div> | ||
</Drawer> | ||
); | ||
}; | ||
|
||
export { ConfigDrawer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { PlayCircleOutlined } from '@ant-design/icons'; | ||
import type { Edge, Node } from '@antv/xflow'; | ||
import { useGraphInstance } from '@antv/xflow'; | ||
import { Button } from 'antd'; | ||
import { useEffect } from 'react'; | ||
|
||
const ExecuteAll = () => { | ||
const graph = useGraphInstance(); | ||
|
||
useEffect(() => { | ||
if (graph) { | ||
graph.on('edge:connected', ({ edge }: { edge: Edge }) => { | ||
edge.attr({ | ||
line: { | ||
strokeDasharray: '', | ||
}, | ||
}); | ||
}); | ||
|
||
graph.on('node:change:data', ({ node }: { node: Node }) => { | ||
const edges = graph.getIncomingEdges(node); | ||
const { status } = node.getData(); | ||
edges?.forEach((edge: Edge) => { | ||
if (status === 'running') { | ||
edge.attr('line/strokeDasharray', 5); | ||
edge.attr('line/style/animation', 'running-line 30s infinite linear'); | ||
} else { | ||
edge.attr('line/strokeDasharray', ''); | ||
edge.attr('line/style/animation', ''); | ||
} | ||
}); | ||
}); | ||
} | ||
}, [graph]); | ||
|
||
const handleExcute = () => { | ||
if (graph) { | ||
const allNodes = graph.getNodes(); | ||
allNodes.forEach((node: Node, index: number) => { | ||
const edges = graph.getOutgoingEdges(node); | ||
node.setData({ | ||
...node.data, | ||
status: 'running', | ||
}); | ||
setTimeout(() => { | ||
node.setData({ | ||
...node.data, | ||
status: edges | ||
? 'success' | ||
: Number(node.id.slice(-1)) % 2 !== 0 | ||
? 'success' | ||
: 'failed', | ||
}); | ||
}, 1000 * index + 1); | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button type="primary" size="small" style={{ fontSize: 12 }} onClick={handleExcute}> | ||
<PlayCircleOutlined rev /> | ||
全部执行 | ||
</Button> | ||
); | ||
}; | ||
|
||
export { ExecuteAll }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters