G6流程引擎技术文档
目录
简介
G6流程引擎是一个基于AntV G6构建的工艺流程图设计系统,专为MES(制造执行系统)工艺建模而设计。该引擎提供了 完整的图形化流程设计能力,支持复杂的节点类型、自定义行为、交互菜单和工具栏功能。
系统采用Vue 3 Composition API架构,结合TypeScript提供强类型支持,实现了高度模块化的组件设计。通过事件驱动的状态管理模式,确保了系统的可扩展性和维护性。
项目结构
G6流程引擎采用清晰的分层架构,主要组织结构如下:
图表来源
章节来源
核心架构
系统架构概览
G6流程引擎采用了现代化的前端架构模式,结合Vue 3的新特性实现了高效的数据流管理和组件通信。
图表来源
模块依赖关系
系统各模块之间存在清晰的依赖关系,通过依赖注入和事件总线实现松耦合设计:
图表来源
章节来源
图实例管理
Core类的核心功能
Core类是整个G6流程引擎的核心,负责图实例的创建、配置和初始化。它提供了统一的接口来管理不同类型的节点和边线。
// 核心节点创建方法
createNode({ label, type }: NodeItem, { x, y, properties }: PointType) {
const id = uuidv4()
return new Create({
id,
type,
label,
x,
y,
properties,
Name: label,
name: label,
})
}
// 默认图配置
setDefaultProps() {
return {
fitCenter: true,
animate: true,
minZoom: 0.2,
maxZoom: 1.4,
defaultNode: {
type: NODES.ACTIVITIES,
labelCfg: {
style: {
fill: '#333',
fontSize: nodeFontSize,
textAlign: 'center',
textBaseline: 'middle',
fontWeight: 'bold',
},
},
},
defaultEdge: {
type: 'polyline',
labelCfg: {
style: {
fill: '#333',
stroke: '#aaa',
fontSize: fontSize - 2,
},
},
style: {
radius: 20,
offset: 45,
endArrow: true,
lineWidth: 3,
stroke: '#aaa',
},
},
}
}
图实例生命周期管理
图表来源
章节来源
节点与边线系统
基础节点组件化封装
G6流程引擎实现了完整的节点组件化体系,包括开始节点、结束节点和普通节点三种基础类型。
开始节点(StartNode)
const StartNode: {
type: string
options: Record<string, any>
} = {
type: NODES.ACTIVITY,
options: {
drawShape(cfg: Record<string, any>, group: any) {
const rect = group.addShape('rect', {
attrs: {
x: -75 - x,
y: -25 - y,
width,
height,
radius: 10,
stroke: '#5B8FF9',
fill: '#C6E5FF',
lineWidth: 3,
},
name: 'rect-shape',
})
return rect
},
},
}
普通节点(OrdinaryNode)
普通节点支持动态图标加载和状态样式配置:
const OrdinaryNode: {
type: string
options: Record<string, any>
} = {
type: NODES.ACTIVITIES,
options: {
drawShape(cfg: Record<string, any>, group: any) {
const type = cfg?.properties?.type
const isRoot = cfg?.isRoot
const rect = group.addShape('rect', {
zIndex: 1,
attrs: {
x: -width / 2,
y: -height / 2,
width,
height,
radius: 1,
stroke: '#5B8FF9',
fill: '#C6E5FF',
lineWidth: 2,
},
name: 'rect-shape',
})
group.addShape('image', {
zIndex: 100,
draggable: false,
attrs: {
x: -width / 2 + 1,
y: -height / 2 + 1,
radius: 1,
width: 20,
height: 20,
img: `/resources/assets/images/${isRoot ? NODES.ACTIVITY : type}.png`,
},
name: 'node-icon',
})
return rect
},
},
}
节点状态样式系统
图表来源
边线配置与样式
系统支持多种类型的边线配置,包括默认边线样式和状态样式:
defaultEdge: {
type: 'polyline',
labelCfg: {
style: {
fill: '#333',
stroke: '#aaa',
fontSize: fontSize - 2,
},
},
style: {
radius: 20,
offset: 45,
endArrow: true,
lineWidth: 3,
stroke: '#aaa',
},
},
edgeStateStyles: {
active: {
stroke: '#5a84ff',
lineWidth: 6,
'text-shape': {
fontSize: fontSize,
},
},
hover: {
stroke: '#5a84ff',
lineWidth: 6,
'text-shape': {
fontSize: fontSize,
},
},
},