jsPlumb拖拽绘制流程图效果代码
代码语言:html
所属分类:图表
代码描述:jsPlumb拖拽绘制流程图效果代码,可根据json数据生成流程图,也可将流程图导出为json数据
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title></title> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/jquery-ui-1.11.0.min.css"> <style> *{margin:0;padding:0;box-sizing:border-box;} h1,h2,h3,h4,h5,h6,a,p,label,ul,li,label,span{margin:0;padding:0;font-family:'微软雅黑';} a,a:active,a:focus, a:hover{text-decoration:none;} .clear{clear:both;} body{background:#ededed;} html,body{height:100%;} .device .deviceLeft{width:220px;height:100%;border-right:1px solid #ccc;float:left;overflow: auto;} .device .deviceLeft h3{padding-left:10px;font-size:14px;background:#ddd;line-height:36px;border-top:1px solid #ccc;border-bottom:1px solid #ccc;} .device .deviceLeft .deviceLeft_box{overflow: hidden;padding:10px 0;} .device .deviceLeft .deviceLeft_box .node{user-select:none;width:98px;height:40px;line-height:20px;float: left;margin:5px;} .device .node{width:120px;height:50px;line-height:30px;box-shadow:2px 2px 10px #aaa;border-radius:3px;text-align:center;z-index:20;background-color:#f1f1f2;color:black;padding:10px;font-size:14px;cursor:pointer;} .device .node:hover{box-shadow:2px 2px 19px #444;opacity:.8;filter:alpha(opacity=80);} .device .node1css{border:lightskyblue 1px solid;} .device .node2css{border:orange 1px solid;} .device .node3css{border:indianred 1px solid;} .device .node4css{border:greenyellow 1px solid;} .device .node5css{border:#ccc 1px solid;} .device #deviceRight{position:absolute;right:0;width:calc(100% - 220px);height:100%;box-sizing:border-box;background:url(//repo.bfw.wiki/bfwrepo/image/611b10eb67750.png);} .device #myDropDown{width:80px;margin-left:-14px;border:1px solid #ccc;text-align:center;} .device #main{width:100%;height:100%;} </style> </head> <body> <div class="container device"> <button class="btn1"> console.log(JSON) </button> <div class="deviceLeft"> <h3>配置1</h3> <div class="deviceLeft_box"> <div class="node node1css" data-type="server">服务器</div> <div class="node node2css" data-type="host">主机</div> <div class="node node3css" data-type="aisle">通道</div> </div> <h3>配置2</h3> <div class="deviceLeft_box"> <div class="node node4css" data-type="route">路由</div> </div> <h3>配置3</h3> <div class="deviceLeft_box"> <div class="node node5css" data-type="signal">信号</div> </div> </div> <div id="deviceRight"> <div id="main"></div> </div> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery.1.11.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-ui-1.11.0.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery.jsPlumb-1.6.2-min.js"></script> <script type="text/javascript"> $(document).ready(function(){ //设置左侧为可复制的 $(".deviceLeft .deviceLeft_box").children().draggable({ helper: "clone", scope: "zlg", }); //设置右侧为拖拽存放区 var i=0; $("#main").droppable({ scope:"zlg", drop:function (event , ui) { var left = parseInt(ui.offset.left - $(this).offset().left); var top = parseInt(ui.offset.top - $(this).offset().top); var type=ui.draggable[0].dataset.type; switch (type) { case "server"://服务器 i++; var id = "chart-server" + i; $(this).append('<div class="node node1css server" style="position: absolute" id="' + id + '" data-type="'+type+'" data-id=" " >' + $(ui.helper).html() + '</div>'); $("#" + id).css("left", left).css("top", top); jsPlumb.addEndpoint(id, { anchors: "Top" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Right" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Bottom" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Left" }, hollowCircle); jsPlumb.draggable(id); jsPlumb.makeTarget(id, { anchor: "Continuous" }) $("#" + id).draggable({ containment: "parent",grid: [10, 10] }); doubleclick("#" + id); break; case "host"://主机 i++; id = "chart-host" + i; $(this).append('<div class="node node2css host" style=\'position: absolute\' id="' + id + '" data-type="'+type+'" data-id=" " >' + $(ui.helper).html() + "</div>"); $("#" + id).css("left", left).css("top", top); jsPlumb.addEndpoint(id, { anchors: "Top" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Right" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Bottom" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Left" }, hollowCircle); jsPlumb.addEndpoint(id, hollowCircle); jsPlumb.draggable(id); jsPlumb.makeTarget(id, { anchor: "Continuous" }) $("#" + id).draggable({ containment: "parent",grid: [10, 10] }); doubleclick("#" + id); break; case "aisle"://通道 i++; id = "chart-aisle" + i; $(this).append('<div class="node node3css aisle" style=\'position: absolute\' id="' + id + '" data-type="'+type+'" data-id=" " >' + $(ui.helper).html() + "</div>"); $("#" + id).css("left", left).css("top", top); jsPlumb.addEndpoint(id, { anchors: "Top" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Right" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Bottom" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Left" }, hollowCircle); jsPlumb.addEndpoint(id, hollowCircle); jsPlumb.draggable(id); jsPlumb.makeTarget(id, { anchor: "Continuous" }) $("#" + id).draggable({ containment: "parent",grid: [10, 10] }); doubleclick("#" + id); break; case "route"://路由 i++; id = "chart-route" + i; $(this).append('<div class="node node4css route" style=\'position: absolute\' id="' + id + '" data-type="'+type+'" data-id=" " >' + $(ui.helper).html() + '</div>'); $("#" + id).css("left", left).css("top", top); jsPlumb.addEndpoint(id, { anchors: "Top" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Right" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Bottom" }, hollowCircle); jsPlumb.addEndpoint(id, { anchors: "Left" }, hollowCircle); jsPlumb.draggable(id); jsPlumb.makeTarget(id, { anchor: "Continuous" }) $("#" + id).draggable({ containment: "parent",grid: [10, 10] }); doubleclick("#" + id); .........完整代码请登录后点击上方下载按钮下载查看
网友评论0