增加节点验证。
This commit is contained in:
parent
19ee89418a
commit
17acef1529
@ -20,6 +20,7 @@ import NodeConfig from './components/NodeConfig';
|
|||||||
import Toolbar from './components/Toolbar';
|
import Toolbar from './components/Toolbar';
|
||||||
import {NodeType, getNodeTypes} from './service';
|
import {NodeType, getNodeTypes} from './service';
|
||||||
import {DeleteOutlined, CopyOutlined, SettingOutlined, ClearOutlined, FullscreenOutlined} from '@ant-design/icons';
|
import {DeleteOutlined, CopyOutlined, SettingOutlined, ClearOutlined, FullscreenOutlined} from '@ant-design/icons';
|
||||||
|
import { validateFlow, hasCycle } from './validate';
|
||||||
|
|
||||||
const {Sider, Content} = Layout;
|
const {Sider, Content} = Layout;
|
||||||
|
|
||||||
@ -99,7 +100,7 @@ const FlowDesigner: React.FC = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'config',
|
key: 'config',
|
||||||
label: '配置节点',
|
label: '<EFBFBD><EFBFBD><EFBFBD>置节点',
|
||||||
icon: <SettingOutlined />,
|
icon: <SettingOutlined />,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
if (contextMenu.cell && contextMenu.cell.isNode()) {
|
if (contextMenu.cell && contextMenu.cell.isNode()) {
|
||||||
@ -247,9 +248,7 @@ const FlowDesigner: React.FC = () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
keyboard: {
|
keyboard: true,
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
clipboard: {
|
clipboard: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
@ -310,7 +309,7 @@ const FlowDesigner: React.FC = () => {
|
|||||||
minWidth: 1,
|
minWidth: 1,
|
||||||
minHeight: 1,
|
minHeight: 1,
|
||||||
orthogonal: true,
|
orthogonal: true,
|
||||||
restricted: true,
|
restrict: true,
|
||||||
},
|
},
|
||||||
rotating: {
|
rotating: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@ -597,7 +596,7 @@ const FlowDesigner: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取详情
|
// 获取<EFBFBD><EFBFBD>情
|
||||||
const fetchDetail = async () => {
|
const fetchDetail = async () => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -615,11 +614,34 @@ const FlowDesigner: React.FC = () => {
|
|||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (!id || !detail || !graphRef.current || detail.status !== WorkflowStatus.DRAFT) return;
|
if (!id || !detail || !graphRef.current || detail.status !== WorkflowStatus.DRAFT) return;
|
||||||
|
|
||||||
|
// 先进行流程验证
|
||||||
|
const result = validateFlow(graphRef.current);
|
||||||
|
const hasCycleResult = hasCycle(graphRef.current);
|
||||||
|
|
||||||
|
if (hasCycleResult) {
|
||||||
|
result.errors.push('流程图中存在循环依赖');
|
||||||
|
result.valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.valid) {
|
||||||
|
message.error(
|
||||||
|
<div>
|
||||||
|
<div>流程验证失败,无法保存:</div>
|
||||||
|
<ul style={{ marginBottom: 0 }}>
|
||||||
|
{result.errors.map((error, index) => (
|
||||||
|
<li key={index}>{error}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 获取图形数据
|
// 获取图形数据
|
||||||
const graphData = graphRef.current.toJSON();
|
const graphData = graphRef.current.toJSON();
|
||||||
|
|
||||||
// 收集节点配置数据
|
// 收<EFBFBD><EFBFBD><EFBFBD>节点配置数据
|
||||||
const nodes = graphRef.current.getNodes().map(node => {
|
const nodes = graphRef.current.getNodes().map(node => {
|
||||||
const data = node.getData() as NodeData;
|
const data = node.getData() as NodeData;
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user