time: 2022-01-29 14:59:54
author: heyunjiang
最近又有需求要做流程图设计,之前使用 antv/x6 搞了自动布局,效果不是太满意。
后来又了解到 mxgraph,没有找到相关实现的 demo,不过 draw.io 倒是其较好的一款实现。
之前团队有人分享过,可以直接使用 draw.io 的 iframe 内嵌方式,感觉不太优雅。
现在又有相关需求,业务团队指定要使用 jsplumb 实现,先了解一下 jsplumb 项目特点
<template>
<div class="container">
<div ref="item_left" class="item"></div>
<div ref="item_right" class="item item2"></div>
</div>
</template>
<script>
import * as jsPlumbBrowserUI from '@jsplumb/browser-ui'
import { BezierConnector } from '@jsplumb/connector-bezier'
export default {
name: 'process',
components: {},
mixins: [],
props: {},
data() {
return {
instance: null,
}
},
computed: {},
watch: {},
created() {},
mounted() {
this.init()
},
methods: {
init() {
const instance = jsPlumbBrowserUI.newInstance({
container: this.$el,
dragOptions: {
containment: 'parent',
},
connector: {
type: BezierConnector.type,
options: {
curviness: 50,
},
},
})
this.instance = instance
jsPlumbBrowserUI.ready(() => {
this.render()
this.bindEvent()
})
},
render() {
this.instance.addEndpoint(this.$refs.item_left, {
source: true,
endpoint: 'Dot',
})
this.instance.addEndpoint(this.$refs.item_right, {
target: true,
endpoint: 'Dot',
})
this.instance.connect({
source: this.$refs.item_left,
target: this.$refs.item_right,
})
}
},
}
</script>
<style lang="scss" scoped>
.container {
position: relative;
height: 100%;
}
.item {
position: absolute;
display: inline-block;
height: 50px;
width: 50px;
border: 1px solid #ccc;
}
.item2 {
left: 100px;
}
</style>