增加工具栏提示。

This commit is contained in:
dengqichen 2024-12-11 13:14:23 +08:00
parent 5ea3c5396b
commit aba4f837ed

View File

@ -15,7 +15,7 @@ export const validateFlow = (graph: Graph): ValidationResult => {
const edges = graph.getEdges(); const edges = graph.getEdges();
// 验证开始节点 // 验证开始节点
const startNodes = nodes.filter(node => node.getData()?.type === 'START'); const startNodes = nodes.filter(node => node.getData()?.type === 'startEvent');
if (startNodes.length === 0) { if (startNodes.length === 0) {
result.errors.push('流程必须包含一个开始节点'); result.errors.push('流程必须包含一个开始节点');
result.valid = false; result.valid = false;
@ -25,7 +25,7 @@ export const validateFlow = (graph: Graph): ValidationResult => {
} }
// 验证结束节点 // 验证结束节点
const endNodes = nodes.filter(node => node.getData()?.type === 'END'); const endNodes = nodes.filter(node => node.getData()?.type === 'endEvent');
if (endNodes.length === 0) { if (endNodes.length === 0) {
result.errors.push('流程必须包含至少一个结束节点'); result.errors.push('流程必须包含至少一个结束节点');
result.valid = false; result.valid = false;
@ -39,17 +39,17 @@ export const validateFlow = (graph: Graph): ValidationResult => {
const nodeType = nodeData?.type; const nodeType = nodeData?.type;
const nodeName = nodeData?.name || '未命名'; const nodeName = nodeData?.name || '未命名';
if (nodeType === 'START' && incomingEdges.length > 0) { if (nodeType === 'startEvent' && incomingEdges.length > 0) {
result.errors.push('开始节点不能有入边'); result.errors.push('开始节点不能有入边');
result.valid = false; result.valid = false;
} }
if (nodeType === 'END' && outgoingEdges.length > 0) { if (nodeType === 'endEvent' && outgoingEdges.length > 0) {
result.errors.push('结束节点不能有出边'); result.errors.push('结束节点不能有出边');
result.valid = false; result.valid = false;
} }
if (nodeType !== 'START' && nodeType !== 'END' && if (nodeType !== 'startEvent' && nodeType !== 'endEvent' &&
(incomingEdges.length === 0 || outgoingEdges.length === 0)) { (incomingEdges.length === 0 || outgoingEdges.length === 0)) {
result.errors.push(`节点 "${nodeName}" 未完全连接`); result.errors.push(`节点 "${nodeName}" 未完全连接`);
result.valid = false; result.valid = false;
@ -58,19 +58,23 @@ export const validateFlow = (graph: Graph): ValidationResult => {
// 验证网关配对 // 验证网关配对
const validateGatewayPairs = () => { const validateGatewayPairs = () => {
const gatewayNodes = nodes.filter(node => node.getData()?.type === 'GATEWAY'); const gatewayNodes = nodes.filter(node => node.getData()?.type === 'exclusiveGateway');
gatewayNodes.forEach(gateway => { gatewayNodes.forEach(gateway => {
const outgoingEdges = graph.getOutgoingEdges(gateway) || []; const outgoingEdges = graph.getOutgoingEdges(gateway) || [];
const incomingEdges = graph.getIncomingEdges(gateway) || []; const incomingEdges = graph.getIncomingEdges(gateway) || [];
const gatewayData = gateway.getData(); const gatewayData = gateway.getData();
const gatewayName = gatewayData?.name || '未命名'; const gatewayName = gatewayData?.name || '未命名';
if (gatewayData?.config?.type === 'PARALLEL' || // 排他网关必须至少有一个出口
gatewayData?.config?.type === 'INCLUSIVE') { if (outgoingEdges.length < 1) {
if (outgoingEdges.length < 2) { result.errors.push(`排他网关 "${gatewayName}" 必须至少有一个出口`);
result.errors.push(`并行/包容网关 "${gatewayName}" 必须有至少两个出口`); result.valid = false;
result.valid = false; }
}
// 排他网关必须有入口
if (incomingEdges.length < 1) {
result.errors.push(`排他网关 "${gatewayName}" 必须至少有一个入口`);
result.valid = false;
} }
}); });
}; };