Custom FLow Chart Plugin
npm install jkstack-flow-chartnpm i jkstack-flow-chart
vue
`
##### 2.全局引入,在main.js中全局引入
`vue
import FlowChart from 'jkstack-flow-chart' // 引入组件
import 'jkstack-flow-chart/dist/flow-chart.css' // 引入组件样式
Vue.use(FlowChart)
`
$3
`vue
ref="flowChart"
:data="data"
:height="height"
:width="width"
:closeSideBarClickMask="false"
:maskColor="maskColor"
:statusColor ="statusColor"
addFlowNodeText="流程节点"
addSwitchNodeText="条件节点"
:showDelBtn="true"
:showAddBtn="true"
:showBackBtn="false"
:shoViewBtn="false"
:addShowSwitchNode="false"
@node-selected="nodeSelecSted"
@node-add="nodeAdd"
@node-delete="nodeDel"
>
流程节点
条件节点
控制节点
`
$3
##### FlowChart Attributes
| 参数 | 说明 | 类型 | 默认值 |
| -------------------- | ---------------------------------------------------------------- | ------ | ---------------------- |
| width | 指定画布宽度,单位为 'px' | number | 1200 |
| height | 指定画布高度,单位为 'px' | number | 600 |
| sliderWidth | 指定抽屉宽度,单位为 'px' | number | 400 |
| data | 显示的图表数据 配置项 | object | {nodes: [], edges: []} |
| closeSideBarClickMask| 是否可以通过点击 mask 关闭抽屉 | boolean | true |
| maskColor | mask遮罩层的颜色 | string | rgba(0,0,0,0.3) |
| statusColor | 节点状态颜色 (success/error/normal/start/end) | object | 默认值|
| showBackBtn | 是否展示反选按钮 | boolean | true |
| showAddBtn | 是否展示新增按钮 | boolean | true |
| showDelBtn | 是否展示删除按钮 | boolean | true |
| showViewBtn | 是否展示查看按钮 | boolean | true |
| addFlowNodeText | 新增菜单中新增流程节点得文案 | string | 新建流程节点 |
| addShowSwitchNode | 新增菜单中是否展示‘新增条件节点’ | boolean | true |
| addSwitchNodeText | 新增菜单中新增条件节点得文案 | string | 新建条件节点 |
###### 节点状态颜色默认值
`js
statusColor: {
success: { color: '#67C23A' },
error: { color: '#F56C6C' },
normal: { color: '#409EFF' },
start: { color: '#909399' },
end: { color: '#909399' }
}
`
##### FlowChart Events
| 事件名 | 说明 | 参数 |
| --------------- | ---------------------------------------------------------------- | ---- |
| node-selected | 当用户手动点击当前节点查看按钮触发的事件 | node |
| node-add | 当用户手动点击新增节点和合并控制节点时触发的事件 | node |
| node-delete | 当用户手动删除节点时触发的事件 | - |
##### FlowChart Methods
| 方法名 | 说明 | 参数 |
| --------------- | --------------------------------------------- | ------ |
| deleteItem | 用于删除关联的节点 | nodeId |
| updateItem | 用于更新节点数据 | node |
| getAllPreNodeList| 用于返回所有前置节点 | nodeId |
| fitView | canvas适应视口 | padding: [top, right, bottom, left] |
| toggleSidebar | 用于切换抽屉的状态 | - |
| getData | 用于用户获取当前数据 | - |
##### FlowChart Slot
| slot name | 说明 |
| --------------- | -------------------------------------------------------------------------------------------- |
| sideBar | 抽屉的内容,如果需要编辑当前节点,需要自定义 dom ,并且提交数据的时候调用 updateItem 方法更新节点信息|
##### data
- 数据格式如下,分为nodes(节点)和edges(关系),
`js
data: {
nodes: [
{
id: 'start',
type: 'flowNode',
label: '开始',
state: 'start',
x: 100,
y: 100,
propertyOne: '节点属性',
propertyTwo: '节点属性',
propertyThree: '节点属性',
task: {}
},
{
id: 'xxx1',
type: 'switchNode',
label: '第一个节点',
state: 'normal',
x: 480,
y: 100,
propertyOne: '节点属性',
propertyTwo: '节点属性',
propertyThree: '节点属性',
task: {}
},
{
id: 'xxx2',
type: 'controlNode',
label: '第二个节点',
state: 'normal',
x: 480,
y: 140,
propertyOne: '节点属性',
propertyTwo: '节点属性',
propertyThree: '节点属性',
task: {}
}
],
edges: [
{
source: "start",
target: "xxx1",
type: "customEdge"
},
{
source: "xxx1",
target: "xxx2",
type: "customBackEdge"
}
]
}
``