前言
本文基础上一篇文章基础上,进行编写,如果看不懂,可以先看上一篇文章JsPlumb + D3js实现自定义节点,可拖拽节点,自动树状布局
新增节点
监听右键行为,在画布上点击右键,弹出添加节点
// 添加右键菜单事件处理函数 document.addEventListener("contextmenu", function(event) { console.info(event); that.selectedId = 0; $(".flow-popover").css('left',event.x + 'px'); $(".flow-popover").css('top',event.y + 'px'); that.visible = true; event.preventDefault(); // 取消默认右键菜单显示行为 }, false);
复制
添加节点代码
<!-- 添加节点 --> <el-popover placement="left" class="flow-popover" trigger="manual" v-model="visible"> <div><el-button type="text" icon="el-icon-user-solid" @click="newNode">添加节点</el-button></div> </el-popover>
复制
添加节点按钮的点击事件
newNode(e) { let that = this; let maxId = that.nodeList[this.nodeList.length - 1].id; let id = Number(maxId) + 1; var rect = document.getElementById("relation-box").getBoundingClientRect(); that.nodeList.push({ id: Number(maxId) + 1, left: e.x - rect.left + "px", name: 'new node', top: e.y - rect.top + "px" }) },
复制
此时点击右键-添加节点按钮,就在画布上创建出一个叫new node的新节点。但节点无法拖动
拖拽事件
要让节点可以拖动,需要执行以下事件
that.$nextTick().then(() => { that.jsPlumbInstance.draggable("node-" + id); // 给每个节点添加锚点 that.jsPlumbInstance.addEndpoint("node-" + id, { anchor: ['Bottom', 'Top', 'Left', 'Right'], Overlays: [ ['Arrow', {width: 10, length: 8, location: 1, direction: 1, foldback: 0.623}]] }, that.commonLink) })
复制
删除连线
// 给连线添加右键点击事件 let that = this; this.jsPlumbInstance.bind("dblclick",function(event) { that.$confirm('此操作将永久删除该文件, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { that.jsPlumbInstance.deleteConnection(event); that.$message({ type: 'success', message: '删除成功!' }); }).catch(() => { that.$message({ type: 'info', message: '已取消删除' }); }); })
复制
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
2025年3月中国数据库排行榜:PolarDB夺魁傲群雄,GoldenDB晋位入三强
墨天轮编辑部
1882次阅读
2025-03-11 17:13:58
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1296次阅读
2025-03-13 11:40:53
【专家观点】罗敏:从理论到真实SQL,感受DeepSeek如何做性能优化
墨天轮编辑部
1281次阅读
2025-03-06 16:45:38
01. HarmonyOS Next应用开发实践与技术解析
若城
1192次阅读
2025-03-04 21:06:20
DeepSeek R1助力,腾讯AI代码助手解锁音乐创作新
若城
1179次阅读
2025-03-05 09:05:00
03 HarmonyOS Next仪表盘案例详解(二):进阶篇
若城
1169次阅读
2025-03-04 21:08:36
05 HarmonyOS NEXT高效编程秘籍:Arkts函数调用与声明优化深度解析
若城
1157次阅读
2025-03-04 22:46:06
04 高效HarmonyOS NEXT编程:ArkTS数据结构优化与属性访问最佳实践
若城
1152次阅读
2025-03-04 21:09:35
02 HarmonyOS Next仪表盘案例详解(一):基础篇
若城
1148次阅读
2025-03-04 21:07:43
06 HarmonyOS Next性能优化之LazyForEach 列表渲染基础与实现详解 (一)
若城
1143次阅读
2025-03-05 21:09:40