工作流可视化库是用于构建流程图、工作流编辑器和节点图等应用的前端组件库。它们提供了强大的图形编辑、节点连接、拖拽布局等功能,广泛应用于流程设计、数据流可视化、低代码平台等场景。
Vue Flow 是基于 Vue 3 的流程图库,它是 React Flow 的 Vue 版本实现,提供了高度可定制的节点图编辑器。
# 使用 pnpm 安装
pnpm add @vue-flow/core
# 可选插件
pnpm add @vue-flow/background @vue-flow/controls @vue-flow/minimap
<script setup lang="ts">
import { ref } from 'vue'
import { VueFlow, useVueFlow } from '@vue-flow/core'
import { Background } from '@vue-flow/background'
import { Controls } from '@vue-flow/controls'
import { MiniMap } from '@vue-flow/minimap'
// 导入样式
import '@vue-flow/core/dist/style.css'
import '@vue-flow/core/dist/theme-default.css'
const elements = ref([
{
id: '1',
type: 'input',
label: '开始节点',
position: { x: 250, y: 5 }
},
{
id: '2',
label: '处理节点',
position: { x: 100, y: 100 }
},
{
id: 'e1-2',
source: '1',
target: '2',
animated: true
}
])
const { onConnect, addEdges } = useVueFlow()
// 连接节点时的回调
onConnect((params) => {
addEdges([params])
})
</script>
<template>
<div style="height: 500px">
<VueFlow v-model="elements">
<Background />
<Controls />
<MiniMap />
</VueFlow>
</div>
</template>
<!-- CustomNode.vue -->
<script setup lang="ts">
import { Handle, Position } from '@vue-flow/core'
defineProps<{
data: {
label: string
}
}>()
</script>
<template>
<div class="custom-node">
<Handle type="target" :position="Position.Top" />
<div class="node-content">
{{ data.label }}
</div>
<Handle type="source" :position="Position.Bottom" />
</div>
</template>
<style scoped>
.custom-node {
padding: 10px 20px;
border-radius: 8px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
</style>
Logic Flow 是滴滴开源的流程图编辑框架,提供了一套完整的流程可视化解决方案,特别适合于业务流程管理。
# 核心库
pnpm add @logicflow/core
# 扩展包
pnpm add @logicflow/extension
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import LogicFlow from '@logicflow/core'
import '@logicflow/core/dist/style/index.css'
const containerRef = ref<HTMLDivElement>()
let lf: LogicFlow
onMounted(() => {
if (!containerRef.value) return
// 初始化 LogicFlow
lf = new LogicFlow({
container: containerRef.value,
grid: true,
background: {
color: '#f7f9ff'
}
})
// 渲染数据
lf.render({
nodes: [
{
id: '1',
type: 'rect',
x: 100,
y: 100,
text: '开始'
},
{
id: '2',
type: 'circle',
x: 300,
y: 100,
text: '审批'
}
],
edges: [
{
id: 'e1',
type: 'polyline',
sourceNodeId: '1',
targetNodeId: '2'
}
]
})
// 监听事件
lf.on('node:click', ({ data }) => {
console.log('节点被点击:', data)
})
})
</script>
<template>
<div ref="containerRef" style="height: 500px; width: 100%" />
</template>
import { RectNode, RectNodeModel } from '@logicflow/core'
class CustomNode extends RectNode {}
class CustomNodeModel extends RectNodeModel {
initNodeData(data: any) {
super.initNodeData(data)
// 自定义节点样式
this.width = 120
this.height = 60
this.radius = 8
}
getNodeStyle() {
const style = super.getNodeStyle()
style.stroke = '#667eea'
style.fill = '#f0f3ff'
style.strokeWidth = 2
return style
}
}
export default {
type: 'custom-node',
view: CustomNode,
model: CustomNodeModel
}
import CustomNode from './CustomNode'
lf.register(CustomNode)
// 使用自定义节点
lf.render({
nodes: [
{
id: '1',
type: 'custom-node',
x: 100,
y: 100,
text: '自定义节点'
}
]
})
| 特性 | Vue Flow | Logic Flow |
|---|---|---|
| 框架支持 | Vue 3 专用 | 框架无关 |
| 学习曲线 | 中等 | 较平缓 |
| 性能 | 优秀 | 良好 |
| 自定义能力 | 强(Vue 组件) | 强(类继承) |
| BPMN 支持 | 需自行实现 | 原生支持 |
| 社区活跃度 | 高 | 中等 |
| TypeScript | 完整支持 | 完整支持 |
| 适用场景 | 通用流程图 | 业务流程为主 |