一个自定义的流程图组件
效果图:
组件引入
import Vue from 'vue'
import {FlowChart} from 'special-ui'
Vue.use(FlowChart)
组件使用
<template>
<div class="container">
<flow-chart :nodes="nodes" :edges="edges" :nodeStle="nodeStle" :eageStle="eageStle" :arrowheadStyle="arrowheadStyle" :direction="'TB'" @onSelect="selectNode"/>
</div>
</template>
<script>
export default {
data () {
return {
nodeStle: 'stroke: #333; fill: #fff;',
eageStle: 'stroke: #f66; stroke-width: 1px;',
arrowheadStyle: 'stroke: #f66;',
labelStyle: 'fill: #333; font-size: 14px',
nodes: [],
edges: []
}
},
created() {
this.init()
},
methods: {
selectNode (d) {
console.log(d)
},
init () {
this.nodes = [
{
id: 'e0',
value: {
label: '开始'
}
},
{
id: 'e1',
class: 'diamond',
labelStyle: 'fill: #aaa; font-size: 18px',
value: {
label: '条件',
shape: 'diamond'
}
},
{
id: 'e2',
style: 'stroke: #fff; fill: #61b2e4',
value: {
label: '分支一',
shape: 'ellipse'
}
},
{
id: 'e3',
value: {
label: '分支二',
shape: 'ellipse'
}
},
{
id: 'e4',
value: {
label: '节点3'
}
},
{
id: 'e5',
value: {
label: '节点4'
}
},
{
id: 'e6',
value: {
label: '结束',
shape: 'circle'
}
}
]
this.edges = [
{
from: 'e0',
to: 'e1'
},
{
from: 'e1',
to: 'e2',
label: '条件1'
},
{
from: 'e1',
to: 'e3',
label: '条件2'
},
{
from: 'e2',
to: 'e4',
},
{
from: 'e3',
to: 'e5',
},
{
from: 'e4',
to: 'e6'
},
{
from: 'e5',
to: 'e6'
}
]
}
}
}
</script>
<style lang="scss" scoped>
.container {
height: 100%;
}
</style>
组件参数
属性 | 说明 | 默认值 |
---|---|---|
direction | 流程图方向 | LR (LR: 从左至右; RL: 从右至左; TB: 从上至下; BT: 从下至上) |
nodes | 流程图节点 | [] |
edges | 流程图连线 | [] |
nodeStyle | 节点样式 | ‘ ‘, 遵循svg样式 |
eageStyle | 连线样式 | ‘ ‘, 遵循svg样式 |
arrowheadStyle | 连线箭头样式 | ‘ ‘, 遵循svg样式 |
labelStyle | 文字样式 | ‘ ‘, 遵循svg样式 |
说明
可以在节点数组项中配置nodeStyle、labelStyle; 连线数组中配置eageStyle、arrowheadStyle、labelStyle;
配置了单项的样式后,优先级高于全局样式配置
事件
属性|说明 onSelect|节点点击事件