增加了动态生成跟节点验证。

This commit is contained in:
戚辰先生 2024-12-06 21:45:55 +08:00
parent 80de1149d3
commit a45d25634f
4 changed files with 20 additions and 9 deletions

View File

@ -7,7 +7,8 @@ export const NODE_CONFIG: Record<string, NodeConfig> = {
theme: { theme: {
fill: '#f6ffed', fill: '#f6ffed',
stroke: '#52c41a' stroke: '#52c41a'
} },
label: '开始'
}, },
END: { END: {
size: { width: 80, height: 80 }, size: { width: 80, height: 80 },
@ -15,7 +16,8 @@ export const NODE_CONFIG: Record<string, NodeConfig> = {
theme: { theme: {
fill: '#fff1f0', fill: '#fff1f0',
stroke: '#ff4d4f' stroke: '#ff4d4f'
} },
label: '结束'
}, },
SHELL: { SHELL: {
size: { width: 200, height: 80 }, size: { width: 200, height: 80 },
@ -24,6 +26,7 @@ export const NODE_CONFIG: Record<string, NodeConfig> = {
fill: '#e6f7ff', fill: '#e6f7ff',
stroke: '#1890ff' stroke: '#1890ff'
}, },
label: '脚本',
extras: { extras: {
rx: 4, rx: 4,
ry: 4, ry: 4,
@ -43,6 +46,7 @@ export const NODE_CONFIG: Record<string, NodeConfig> = {
fill: '#fff7e6', fill: '#fff7e6',
stroke: '#fa8c16' stroke: '#fa8c16'
}, },
label: '定时器',
extras: { extras: {
rx: 4, rx: 4,
ry: 4, ry: 4,
@ -62,6 +66,7 @@ export const NODE_CONFIG: Record<string, NodeConfig> = {
fill: '#f9f0ff', fill: '#f9f0ff',
stroke: '#722ed1' stroke: '#722ed1'
}, },
label: '网关',
extras: { extras: {
refPoints: '0,10 10,0 20,10 10,20' refPoints: '0,10 10,0 20,10 10,20'
} }

View File

@ -532,10 +532,15 @@ const FlowDesigner: React.FC = () => {
} }
); );
// 创建节点配置 // 获取节点配置
const position = calculateNodePosition(nodeType.code, dropPosition); const position = calculateNodePosition(nodeType.code, dropPosition);
const nodeStyle = generateNodeStyle(nodeType.code); const nodeStyle = generateNodeStyle(nodeType.code);
const ports = generatePorts(nodeType.code); const ports = generatePorts(nodeType.code);
const config = NODE_CONFIG[nodeType.code];
if (!config) {
throw new Error(`未找到节点类型 ${nodeType.code} 的配置`);
}
// 创建节点 // 创建节点
const node = graphRef.current.addNode({ const node = graphRef.current.addNode({
@ -544,7 +549,7 @@ const FlowDesigner: React.FC = () => {
ports, ports,
data: { data: {
type: nodeType.code, type: nodeType.code,
name: nodeType.name, name: config.label, // 使用配置中的中文名称
config: {} as any, config: {} as any,
}, },
}); });
@ -554,7 +559,7 @@ const FlowDesigner: React.FC = () => {
graphRef.current.select(node); graphRef.current.select(node);
setCurrentNode(node); setCurrentNode(node);
setCurrentNodeType(nodeType); setCurrentNodeType(nodeType);
form.setFieldsValue({ name: nodeType.name }); form.setFieldsValue({ name: config.label }); // 使用配置中的中文名称
setConfigVisible(true); setConfigVisible(true);
message.success('节点创建成功'); message.success('节点创建成功');

View File

@ -13,9 +13,11 @@ export interface NodeConfig {
fill: string; fill: string;
stroke: string; stroke: string;
}; };
label: string;
extras?: { extras?: {
rx?: number; rx?: number;
ry?: number; ry?: number;
refPoints?: string;
icon?: { icon?: {
'xlink:href': string; 'xlink:href': string;
width: number; width: number;
@ -23,6 +25,5 @@ export interface NodeConfig {
x: number; x: number;
y: number; y: number;
}; };
refPoints?: string;
}; };
} }

View File

@ -81,18 +81,18 @@ export const generateNodeStyle = (nodeType: string): NodeStyle => {
...(config.extras || {}) ...(config.extras || {})
}, },
label: { label: {
text: nodeType, text: config.label,
fill: '#000000', fill: '#000000',
fontSize: 14, fontSize: 14,
fontWeight: 500, fontWeight: 500,
...(nodeType === 'SHELL' ? { ...(config.shape === 'rect' ? {
refX: 0.5, refX: 0.5,
refY: 0.5, refY: 0.5,
textAnchor: 'middle', textAnchor: 'middle',
textVerticalAnchor: 'middle' textVerticalAnchor: 'middle'
} : {}) } : {})
}, },
...(nodeType === 'SHELL' && config.extras?.icon ? { ...(config.extras?.icon ? {
image: config.extras.icon image: config.extras.icon
} : {}) } : {})
} }