【教程】LogicFlow流程图界的神器
·
前言
everybody多少人了解过流程设计器🙋♂️,本人起初对流程设计器了解甚少,无奈需求所致不得不开始了解学习。可经过一番深入了解下来发现虽然市面上此类工具不少也很成熟,但是这些工具要不就是文档残缺不全、晦涩难懂(有可能个人原因🤯),要不就是提供的控件图表让使用人员有些学习成本。
那么问题来了,有没有一个让开发人员开发起来舒服,让后台使用人员使用起来也舒服的东西呢?答案呼之欲出就是今天给大家介绍的此框架。
效果展示
基础流程图
审批流程
LogicFlow是什么
LogicFlow 是由滴滴体验平台技术研发的一款基于HTML + CSS+Svg的流程图编辑框架,分为核心包合扩展包通过两者的相互配合,可以帮我们快速搭建出一套流程图编辑器并且支持多种数据格式的渲染,并且对外提供很多api也支持节点、菜单的自定义。以下是LogicFlow的整体机构图
具体架构及其原理可参考:LogicFlow 的设计和架构
PS:截止目前在github上已有
- 👀83
- 🔀 934
- ⭐6.6k
正文
下面以创建一个具有控制栏、拖拽栏的简单画布为例
安装
npm install @logicflow/core -S // 为核心功能
npm install @logicflow/extension -S // 为扩展功能
引入文件
import LogicFlow from '@logicflow/core';
// 引入整体背景的样式
import '@logicflow/core/dist/style/index.css';
设置容器
:::warning
此处需注意一定要设置上容器的宽高,否则默认是container的宽高
:::
<template>
<div class="ViewProcessEditor">
<div ref="logicContainer" class="viewport" />
</div>
</template>
<style scoped lang="less">
.ViewProcessEditor {
height: 100vh;
overflow: hidden;
.viewport {
height: 100%;
overflow: hidden;
}
}
</style>
初始化
data() {
return {
lf: null,
config: {
stopZoomGraph: true, // 禁止缩放
// 背景网格大小
grid: {
size: 10,
type: 'dot',
},
keyboard: {
enabled: true,
},
snapline: true,
},
};
},
mounted() {
// 初始项目注册
this.lf = new LogicFlow({
...this.config,
container: this.$refs.logicContainer,
});
this.lf.render();
},
配置右上角控制栏、左侧拖拽面板
这时候就用到强大的插件功能了
再次引入扩展文件
import { Control,DndPanel } from '@logicflow/extension';
// 引入 extension相关操作的样式
import '@logicflow/extension/lib/style/index.css';
插件配置
this.lf = new LogicFlow({
...this.config,
plugins: [Control, DndPanel],
container: this.$refs.logicContainer,
});
this.lf.extension.dndPanel.setPatternItems([
{
type: 'circle',
text: '开始',
label: '开始节点',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAAH6ji2bAAAABGdBTUEAALGPC/xhBQAAAnBJREFUOBGdVL1rU1EcPfdGBddmaZLiEhdx1MHZQXApraCzQ7GKLgoRBxMfcRELuihWKcXFRcEWF8HBf0DdDCKYRZpnl7p0svLe9Zzbd29eQhTbC8nv+9zf130AT63jvooOGS8Vf9Nt5zxba7sXQwODfkWpkbjTQfCGUd9gIp3uuPP8bZ946g56dYQvnBg+b1HB8VIQmMFrazKcKSvFW2dQTxJnJdQ77urmXWOMBCmXM2Rke4S7UAW+/8ywwFoewmBps2tu7mbTdp8VMOkIRAkKfrVawalJTtIliclFbaOBqa0M2xImHeVIfd/nKAfVq/LGnPss5Kh00VEdSzfwnBXPUpmykNss4lUI9C1ga+8PNrBD5YeqRY2Zz8PhjooIbfJXjowvQJBqkmEkVnktWhwu2SM7SMx7Cj0N9IC0oQXRo8xwAGzQms+xrB/nNSUWVveI48ayrFGyC2+E2C+aWrZHXvOuz+CiV6iycWe1Rd1Q6+QUG07nb5SbPrL4426d+9E1axKjY3AoRrlEeSQo2Eu0T6BWAAr6COhTcWjRaYfKG5csnvytvUr/WY4rrPMB53Uo7jZRjXaG6/CFfNMaXEu75nG47X+oepU7PKJvvzGDY1YLSKHJrK7vFUwXKkaxwhCW3u+sDFMVrIju54RYYbFKpALZAo7sB6wcKyyrd+aBMryMT2gPyD6GsQoRFkGHr14TthZni9ck0z+Pnmee460mHXbRAypKNy3nuMdrWgVKj8YVV8E7PSzp1BZ9SJnJAsXdryw/h5ctboUVi4AFiCd+lQaYMw5z3LGTBKjLQOeUF35k89f58Vv/tGh+l+PE/wG0rgfIUbZK5AAAAABJRU5ErkJggg==',
},
{
type: 'rect',
label: '用户任务',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAEFVwZaAAAABGdBTUEAALGPC/xhBQAAAqlJREFUOBF9VM9rE0EUfrMJNUKLihGbpLGtaCOIR8VjQMGDePCgCCIiCNqzCAp2MyYUCXhUtF5E0D+g1t48qAd7CCLqQUQKEWkStcEfVGlLdp/fm3aW2QQdyLzf33zz5m2IsAZ9XhDpyaaIZkTS4ASzK41TFao88GuJ3hsr2pAbipHxuSYyKRugagICGANkfFnNh3HeE2N0b3nN2cgnpcictw5veJIzxmDamSlxxQZicq/mflxhbaH8BLRbuRwNtZp0JAhoplVRUdzmCe/vO27wFuuA3S5qXruGdboy5/PRGFsbFGKo/haRtQHIrM83bVeTrOgNhZReWaYGnE4aUQgTJNvijJFF4jQ8BxJE5xfKatZWmZcTQ+BVgh7s8SgPlCkcec4mGTmieTP4xd7PcpIEg1TX6gdeLW8rTVMVLVvb7ctXoH0Cydl2QOPJBG21STE5OsnbweVYzAnD3A7PVILuY0yiiyDwSm2g441r6rMSgp6iK42yqroI2QoXeJVeA+YeZSa47gZdXaZWQKTrG93rukk/l2Al6Kzh5AZEl7dDQy+JjgFahQjRopSxPbrbvK7GRe9ePWBo1wcU7sYrFZtavXALwGw/7Dnc50urrHJuTPSoO2IMV3gUQGNg87IbSOIY9BpiT9HV7FCZ94nPXb3MSnwHn/FFFE1vG6DTby+r31KAkUktB3Qf6ikUPWxW1BkXSPQeMHHiW0+HAd2GelJsZz1OJegCxqzl+CLVHa/IibuHeJ1HAKzhuDR+ymNaRFM+4jU6UWKXorRmbyqkq/D76FffevwdCp+jN3UAN/C9JRVTDuOxC/oh+EdMnqIOrlYteKSfadVRGLJFJPSB/ti/6K8f0CNymg/iH2gO/f0DwE0yjAFO6l8JaR5j0VPwPwfaYHqOqrCI319WzwhwzNW/aQAAAABJRU5ErkJggg==',
className: 'important-node',
},
{
type: 'rect',
label: '系统任务',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAEFVwZaAAAABGdBTUEAALGPC/xhBQAAAqlJREFUOBF9VM9rE0EUfrMJNUKLihGbpLGtaCOIR8VjQMGDePCgCCIiCNqzCAp2MyYUCXhUtF5E0D+g1t48qAd7CCLqQUQKEWkStcEfVGlLdp/fm3aW2QQdyLzf33zz5m2IsAZ9XhDpyaaIZkTS4ASzK41TFao88GuJ3hsr2pAbipHxuSYyKRugagICGANkfFnNh3HeE2N0b3nN2cgnpcictw5veJIzxmDamSlxxQZicq/mflxhbaH8BLRbuRwNtZp0JAhoplVRUdzmCe/vO27wFuuA3S5qXruGdboy5/PRGFsbFGKo/haRtQHIrM83bVeTrOgNhZReWaYGnE4aUQgTJNvijJFF4jQ8BxJE5xfKatZWmZcTQ+BVgh7s8SgPlCkcec4mGTmieTP4xd7PcpIEg1TX6gdeLW8rTVMVLVvb7ctXoH0Cydl2QOPJBG21STE5OsnbweVYzAnD3A7PVILuY0yiiyDwSm2g441r6rMSgp6iK42yqroI2QoXeJVeA+YeZSa47gZdXaZWQKTrG93rukk/l2Al6Kzh5AZEl7dDQy+JjgFahQjRopSxPbrbvK7GRe9ePWBo1wcU7sYrFZtavXALwGw/7Dnc50urrHJuTPSoO2IMV3gUQGNg87IbSOIY9BpiT9HV7FCZ94nPXb3MSnwHn/FFFE1vG6DTby+r31KAkUktB3Qf6ikUPWxW1BkXSPQeMHHiW0+HAd2GelJsZz1OJegCxqzl+CLVHa/IibuHeJ1HAKzhuDR+ymNaRFM+4jU6UWKXorRmbyqkq/D76FffevwdCp+jN3UAN/C9JRVTDuOxC/oh+EdMnqIOrlYteKSfadVRGLJFJPSB/ti/6K8f0CNymg/iH2gO/f0DwE0yjAFO6l8JaR5j0VPwPwfaYHqOqrCI319WzwhwzNW/aQAAAABJRU5ErkJggg==',
className: 'import_icon',
},
{
type: 'diamond',
label: '条件判断',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAAHeEJUAAAAABGdBTUEAALGPC/xhB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A+lwURhAON82Kwe2iDAC1Watq4XHaGQ7skLcFOtI5lDxuM2gZe6WFIotPAhbaeYlU4to5cuarF1QrcZ/lwrLaCJl66JBocYZnrNlvm2+MBCTmUymPrYZVbjdlr/BxlMjmNmNI3SAAAAAElFTkSuQmCC',
},
]);
最终效果
常用API
名词解释:文档中说的“边Edge”其实就是节点直接的“连接线”,在使用api的时候可以注意区分
API | 作用 | 用法 |
---|---|---|
getGraphData | 获取流程图数据 | lf.getGraphData(); |
getNodeDataById | 返回节点的信息 | lf.getNodeDataById(‘节点id’) ; |
addNode | 添加新节点 | lf.addNode(Object); |
deleteNode | 创建节点 | lf.deleteNode(“节点id”); |
cloneNode | 复制节点 | lf.cloneNode(“节点id”); |
还有很多很多在这就不一一列举了,具体请自行根据需要查看官方文档
🙏结语
❤️感谢铁汁们的耐心阅读,如果本篇文章能对大家有所帮助,还请多多点赞收藏关注,支持一下❤️
更多推荐
已为社区贡献2条内容
所有评论(0)