vue jsplumb实现工作流程图的方法-mile米乐体育

vue jsplumb实现工作流程图的方法

这篇文章主要介绍“vue jsplumb实现工作流程图的方法”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“vue jsplumb实现工作流程图的方法”文章能帮助大家解决问题。

先写了一个demo,大概样子如下:

米乐app官网登录官网文档home | jsplumb toolkit documentation

先安装插件

npminstalljsplumb--save

安装panzoom,主要用于鼠标滚轮缩放流程图

npminstallpanzoom--save

在需要的页面引入插件

importpanzoomfrom'panzoom'import{jsplumb}from'jsplumb'

接下来先写布局

父组件

flownode是子组件

样式主要是子组件的,父组件样式随意就行

@labelcolor:#409eff;@nodesize:20px;@viewsize:10px;.node-item{position:absolute;display:flex;height:40px;width:120px;justify-content:center;align-items:center;border:1pxsolid#b7b6b6;border-radius:4px;cursor:move;box-sizing:content-box;font-size:12px;z-index:9995;&:hover{z-index:9998;.delete-btn{display:block;}}.log-wrap{width:40px;height:40px;border-right:1pxsolid#b7b6b6;}.nodename{flex-grow:1;width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:center;}.node-anchor{display:flex;position:absolute;width:@nodesize;height:@nodesize;align-items:center;justify-content:center;border-radius:10px;cursor:crosshair;z-index:9999;background:-webkit-radial-gradient(sandybrown10%,white30%,#9a54ff60%);}.anchor-top{top:calc((@nodesize/2)*-1);left:50%;margin-left:calc((@nodesize/2)*-1);}.anchor-right{top:50%;right:calc((@nodesize/2)*-1);margin-top:calc((@nodesize/2)*-1);}.anchor-bottom{bottom:calc((@nodesize/2)*-1);left:50%;margin-left:calc((@nodesize/2)*-1);}.anchor-left{top:50%;left:calc((@nodesize/2)*-1);margin-top:calc((@nodesize/2)*-1);}}.active{border:1pxdashed@labelcolor;box-shadow:0px5px9px0pxrgba(0,0,0,0.5);}.common-circle-node{border-radius:50%;height:60px;width:60px;}

页面样式写完,接下来写插件配置

jsplumb.ready() 是一个钩子函数,它会在 jsplumb 准备完毕时执行。

连接线的建立是通过 jsplumb.connect() 方法实现的。该方法接受一个对象作为配置项。其中包含了与上述概念一一对应的配置项,以及一些额外的样式。

source: 源对象,可以是对象的 id 属性、element 对象或者 endpoint 对象。

target: 目标对象,可以是对象的 id 属性、element 对象或者 endpoint 对象。

anchor: 是一个数组,数组中每一项定义一个锚点。

初始化方法

init(){this.jsplumb.ready(()=>{//导入默认配置this.jsplumb.importdefaults(this.jsplumbsetting)//完成连线前的校验this.jsplumb.bind('beforedrop',evt=>{constres=()=>{}//此处可以添加是否创建连接的校验,返回false则不添加;returnres})this.loadeasyflow()//会使整个jsplumb立即重绘。this.jsplumb.setsuspenddrawing(false,true)})this.initpanzoom()},//加载流程图loadeasyflow(){//初始化节点for(leti=0;i

this.data 是需要渲染的数据,放在文章末尾,具体数据按照接口实际返回的来写

this.jsplumbsourceoptions 是jsplumb配置信息,新建一个文件编写,具体如下:

exportconstjsplumbsetting={grid:[10,10],//动态锚点、位置自适应anchor:['topcenter','rightmiddle','bottomcenter','leftmiddle'],container:'flow',//连线的样式statemachine、flowchart,有四种默认类型:bezier(贝塞尔曲线),straight(直线),flowchart(流程图),statemachine(状态机)connector:['flowchart',{cornerradius:5,alwaysrespectstubs:true,stub:5}],//鼠标不能拖动删除线connectionsdetachable:false,//删除线的时候节点不删除deleteendpointsondetach:false,//连线的端点//endpoint:["dot",{radius:5}],endpoint:['rectangle',{height:10,width:10}],//线端点的样式endpointstyle:{fill:'rgba(255,255,255,0)',outlinewidth:1},logenabled:false,//是否打开jsplumb的内部日志记录//绘制线paintstyle:{stroke:'#409eff',strokewidth:2},hoverpaintstyle:{stroke:'#409eff'},//绘制箭头overlays:[['arrow',{width:8,length:8,location:1}]],rendermode:'svg'}//jsplumb连接参数exportconstjsplumbconnectoptions={issource:true,istarget:true,//动态锚点、提供了4个方向continuous、autodefaultanchor:['topcenter','rightmiddle','bottomcenter','leftmiddle']}exportconstjsplumbsourceoptions={filter:'.node-anchor',//触发连线的区域/*"span"表示标签,".classname"表示类,"#id"表示元素id*/filterexclude:false,anchor:['topcenter','rightmiddle','bottomcenter','leftmiddle'],allowloopback:false}exportconstjsplumbtargetoptions={filter:'.node-anchor',/*"span"表示标签,".classname"表示类,"#id"表示元素id*/filterexclude:false,anchor:['topcenter','rightmiddle','bottomcenter','leftmiddle'],allowloopback:false}

在父组件引入配置文件和方法

import{jsplumbsetting,jsplumbconnectoptions,jsplumbsourceoptions,jsplumbtargetoptions}from'./config/commonconfig'

接下来在上面说的初始化方法文件里面配置鼠标滚轮缩放插件的方法 this.initpanzoom():

//鼠标滚动放大缩小initpanzoom(){constmaincontainer=this.jsplumb.getcontainer()constmaincontainerwrap=maincontainer.parentnodeconstpan=panzoom(maincontainer,{smoothscroll:false,bounds:true,//autocenter:true,zoomdoubleclickspeed:1,minzoom:0.5,maxzoom:2,//设置滚动缩放的组合键,默认不需要组合键beforewheel:(e)=>{//console.log(e)//letshouldignore=!e.ctrlkey//returnshouldignore},beforemousedown:function(e){//allowmouse-downpanningonlyifaltkeyisdown.otherwise-ignorevarshouldignore=e.ctrlkeyreturnshouldignore}})this.jsplumb.maincontainerwrap=maincontainerwrapthis.jsplumb.pan=pan//缩放时设置jsplumb的缩放比率pan.on('zoom',e=>{const{scale}=e.gettransform()this.jsplumb.setzoom(scale)})pan.on('panend',(e)=>{})//平移时设置鼠标样式maincontainerwrap.style.cursor='grab'maincontainerwrap.addeventlistener('mousedown',functionwrapmousedown(){this.style.cursor='grabbing'maincontainerwrap.addeventlistener('mouseout',functionwrapmouseout(){this.style.cursor='grab'})})maincontainerwrap.addeventlistener('mouseup',functionwrapmouseup(){this.style.cursor='grab'})},

大功告成,data的数据放在这里,测试使用:

{"flowjson":{"nodelist":[{"type":"start","nodename":"已新建","id":"start-hixwf8wsacrwxjaaxvwc6aqk00000001","node_code":"已新建","trigger_event":"","branch_flow":"","icon":"play-circle","x":175,"y":60,"width":50,"height":50},{"type":"freedom","nodename":"待审批","id":"freedom-yakfjzz5vsp3gec6zuld2jdk00000004","node_code":"待审批","trigger_event":"","branch_flow":"","icon":"sync","x":330,"y":160,"width":50,"height":120},{"type":"end","nodename":"已通过","id":"end-jjrvtd5j2gijkcn8mf7iywxh00000999","node_code":"已通过","trigger_event":"","branch_flow":"","icon":"stop","x":330,"y":360,"width":50,"height":50},{"type":"end","nodename":"审批拒绝","id":"end-j1dmsch5yjskyk0henkbt62f00010001","node_code":"审批拒绝","trigger_event":"","branch_flow":"","icon":"stop","x":500,"y":350,"width":50,"height":50}],"linklist":[{"type":"link","id":"link-bpi6zux1bjywz5sei3r5qawoi7g3qisr","sourceid":"start-hixwf8wsacrwxjaaxvwc6aqk00000001","targetid":"freedom-yakfjzz5vsp3gec6zuld2jdk00000004","label":"line000000","role":[],"organize":[],"audit_role":[],"audit_organize":[],"audit_organize_same":"0","audit_dealer_same":"0","audit_dealers":[],"notice":"0","plug":"","pass_option":"pass","row_par_json":"","judge_fields":"","auth_at":"","auth_user":"","auth_stat":"","auth_mark":"","cls":{"linktype":"flowchart","linkcolor":"#008000","linkthickness":4}},{"type":"link","id":"link-5xjwzglkipucsjmpfgesjxaomhwkplno","sourceid":"freedom-yakfjzz5vsp3gec6zuld2jdk00000004","targetid":"end-j1dmsch5yjskyk0henkbt62f00010001","label":"line000001","role":[],"organize":[],"audit_role":["project_support_plan_code"],"audit_organize":[],"audit_organize_same":"0","audit_dealer_same":"0","audit_dealers":[],"notice":"0","plug":"","pass_option":"reject","row_par_json":"","judge_fields":"","auth_at":"","auth_user":"","auth_stat":"","auth_mark":"","cls":{"linktype":"flowchart","linkcolor":"#808080","linkthickness":1}},{"type":"link","id":"link-g05v3usxa86watpcmkvgzybdblpasmju","sourceid":"freedom-yakfjzz5vsp3gec6zuld2jdk00000004","targetid":"end-jjrvtd5j2gijkcn8mf7iywxh00000999","label":"line000002","role":[],"organize":[],"audit_role":["project_support_plan_code"],"audit_organize":[],"audit_organize_same":"0","audit_dealer_same":"0","audit_dealers":[],"notice":"0","plug":"","pass_option":"approve","row_par_json":"","judge_fields":"","auth_at":"","auth_user":"","auth_stat":"","auth_mark":"","cls":{"linktype":"flowchart","linkcolor":"#808080","linkthickness":1}}]}}

关于“vue jsplumb实现工作流程图的方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注恰卡编程网行业资讯频道,小编每天都会为大家更新不同的知识点。

展开全文

vue

内容来源于互联网和用户投稿,文章中一旦含有米乐app官网登录的联系方式务必识别真假,本站仅做信息展示不承担任何相关责任,如有侵权或涉及法律问题请联系米乐app官网登录删除

最新文章

网站地图