当前位置: 首页 > news >正文

vue2 + antvx6 实现流程图功能

导入关键包

 npm install @antv/x6 --save

npm install @antv/x6-vue-shape 

保存插件 (可选)

npm install --save @antv/x6-plugin-clipboard @antv/x6-plugin-history @antv/x6-plugin-keyboard @antv/x6-plugin-selection @antv/x6-plugin-snapline @antv/x6-plugin-stencil @antv/x6-plugin-transform insert-css

写好的组件直接导入即可

<template><div><el-container><el-aside><div id="stencil"><div><div class="dnd-circle dnd-start" @mousedown="startDrag('start',$event)"></div><span>开始</span></div><div><div class="dnd-rect" @mousedown="startDrag('rect',$event)"></div><span>节点1</span></div><div><div class="dnd-polygon" @mousedown="startDrag('polygon',$event)"></div><span>节点2</span></div><div><div class="dnd-circle" @mousedown="startDrag('end',$event)"></div><span>结束</span></div></div></el-aside><el-main><div ref="graphContainer"></div></el-main></el-container><!--  todo drawer 抽屉实现节点内容编辑  --><el-drawertitle="节点属性编辑":visible.sync="drawer":direction="direction":before-close="handleClose"><el-form :data="editNode" :inline="true"><el-form-item label="节点名称" prop="label"><el-input v-model="editNode.label"></el-input></el-form-item><el-form-item label="节点形状" prop="shape"><el-select v-model="editNode.shape"><el-option v-for="(item,index) in shapeList" :key="item.value" :label="item.label":value="item.value"></el-option></el-select></el-form-item><el-button type="primary" @click="saveNode">保存</el-button></el-form></el-drawer></div>
</template><script>
import {Graph} from '@antv/x6'
import '@antv/x6-vue-shape'
// 插件 键盘监听事件
import {Keyboard} from '@antv/x6-plugin-keyboard'
// 拖拽事件
import {Dnd} from '@antv/x6-plugin-dnd'import {Stencil} from '@antv/x6-plugin-stencil'
import {Transform} from '@antv/x6-plugin-transform'
import {Selection} from '@antv/x6-plugin-selection'
import {Snapline} from '@antv/x6-plugin-snapline'
import {Clipboard} from '@antv/x6-plugin-clipboard'
import {History} from '@antv/x6-plugin-history'
import {register} from '@antv/x6-vue-shape'
import insertCss from 'insert-css'export default {name: 'MindMap',data () {return {graphOut: {},drawer: false,direction: 'rtl',currentNode: {},editNode: {},dnd: {},// 节点形状shapeList: [{label: '矩形',value: 'rect'}, {label: '圆形',value: 'circle'}, {label: '椭圆',value: 'ellipse'}, {label: '多边形',value: 'polygon'}, {label: '折线',value: 'polyline'}, {label: '路径',value: 'path'}, {label: '图片',value: 'image'},],// 连接桩ports: {groups: {top: {position: 'top',attrs: {circle: {magnet: true,stroke: 'black',r: 4,},},},bottom: {position: 'bottom',attrs: {circle: {magnet: true,stroke: 'black',r: 4,},},},left: {position: 'left',attrs: {circle: {magnet: true,stroke: 'black',r: 4,},},},right: {position: 'right',attrs: {circle: {magnet: true,stroke: 'black',r: 4,},},},},items: [{id: 'port_1',group: 'bottom',}, {id: 'port_2',group: 'top',}, {id: 'port_3',group: 'left',}, {id: 'port_4',group: 'right',}]}}},mounted () {this.graphOut = this.initGraph()},methods: {initGraph () {const graph = new Graph({container: this.$refs.graphContainer,// autoResize: true, // 大小自适应height: 400,width: '100%',grid: true,magnetThreshold: 'onleave',panning: {enabled: true,modifiers: 'shift',magnetThreshold: 1,// 鼠标画布移动eventTypes: ['leftMouseDown']},// 开启自动吸附connecting: {// 距离节点或者连接桩 50 px 触发自动吸附snap: true,// 是否允许连接到画布空白位置的点allowBlank: false,// 是否允许创建循环连线allowLoop: false,// 拖动边时,是否高亮显示所有可用连接桩或节点highlight: true,},modes: {default: ['drag-node']},background: {color: '#F2F7FA',},mousewheel: {// 是否开启滚轮缩放交互enabled: true,// 滚动缩放因子 默认 1.2factor: 1.2,// 是否将鼠标位置作为中心缩放、默认为truezoomAtMousePosition: true,// 按下什么键 才会缩放modifiers: ['ctrl', 'meta'],// 判断什么情况下 滚轮事件被处理// guard: false,},connector: {name: 'rounded',args: {radius: 8}}})// 支持拖拽this.dnd = new Dnd({target: graph,scaled: false,})Graph.registerNode('custom-node-width-port',{inherit: 'rect',width: 100,height: 40,attrs: {body: {stroke: '#8f8f8f',strokeWidth: 1,fill: '#fff',rx: 6,ry: 6,},},// 上下左右 四条边都有连接桩ports: this.ports},true,)Graph.registerNode('custom-circle-start',{inherit: 'circle',ports: this.ports},true,)Graph.registerNode('custom-polygon',{inherit: 'polygon',points: '0,10 10,0 20,10 10,20',ports: this.ports},true,)Graph.registerNode('custom-rect',{inherit: 'rect',ports: this.ports},true,)graph.addNode({x: 100,y: 40,width: 180,height: 30,label: '中心主题',shape: 'custom-node-width-port', // 节点形状attrs: {body: {fill: '#f5f5f5',stroke: '#333',},type: 'root'},tools: [{name: 'boundary',args: {attrs: {fill: '#16B8AA',stroke: '#2F80EB',strokeWidth: 1,fillOpacity: 0.1,},},}]})// 添加 plugin 插件graph.use(new Keyboard()) // 键盘事件.use(new Selection({enabled: true,multiple: true,rubberband: true,movable: true,showEdgeSelectionBox: true,showNodeSelectionBox: true,pointerEvents: 'none'})) // 绑定框选.use(new Snapline({enabled: true,sharp: true,})) // 对齐线.use(new Clipboard()).use(new History({enabled: true})) // 绑定撤销// 鼠标事件this.mouseEvent(graph)// 键盘时间this.keyboardEvent(graph)// 添加子节点的逻辑...return graph},addChildNode (nodeId, type) {console.log(nodeId, type)},handleClose (done) {this.$confirm('确认关闭?').then(_ => {done()}).catch(_ => {})},saveNode () {this.$confirm('确认保存?').then(_ => {console.log(this.editNode)this.currentNode['label'] = this.editNode['label']// this.currentNode['shape'] = this.editNode['shape']}).catch(_ => {})// 关闭当前 抽屉 el-drawerthis.drawer = false},startDrag (type, e) {this.startDragToGraph(this.graphOut, type, e)},startDragToGraph (graph, type, e) {const startNode = this.graphOut.createNode({shape: 'custom-circle-start',width: 38,height: 38,attrs: {body: {strokeWidth: 1,stroke: '#000000',fill: '#ffffff',rx: 10,ry: 10,},},})const polygonNode = this.graphOut.createNode({shape: 'custom-polygon',width: 80,height: 60,attrs: {body: {strokeWidth: 1,stroke: '#000000',fill: '#ffffff',rx: 10,ry: 10,},label: {fontSize: 13,fontWeight: 'bold',},},})const rectNode = this.graphOut.createNode({shape: 'custom-rect',width: 80,height: 60,attrs: {body: {strokeWidth: 1,stroke: '#000000',fill: '#ffffff',rx: 10,ry: 10,},label: {fontSize: 13,fontWeight: 'bold',},},})const endNode = this.graphOut.createNode({shape: 'custom-circle-start',width: 38,height: 38,key: 'end',attrs: {body: {strokeWidth: 4,stroke: '#000000',fill: '#ffffff',rx: 10,ry: 10,},label: {text: '结束',fontSize: 13,fontWeight: 'bold',},},})let dragNodeif (type === 'start') {dragNode = startNode} else if (type === 'end') {dragNode = endNode} else if (type === 'rect') {dragNode = rectNode} else if (type === 'polygon') {dragNode = polygonNode}console.log('dnd', dragNode, e, type)this.dnd.start(dragNode, e)},// 删除事件 节点removeNode (node) {this.graphOut.removeNode(node)},// 鼠标事件mouseEvent (graph) {// 鼠标事件// 鼠标 Hover 时添加按钮graph.on('node:mouseenter', ({node}) => {node.addTools({name: 'button',args: {x: 0,y: 0,offset: {x: 18, y: 18},// onClick({ view }) { ... },},})})// 鼠标移开时删除按钮graph.on('node:mouseleave', ({node}) => {node.removeTools() // 删除所有的工具})graph.on('node:dblclick', ({node}) => {// 添加连接桩node.addPort({group: 'top',attrs: {circle: {magnet: true,stroke: '#8f8f8f',r: 5,},},})// 编辑nodethis.currentNode = nodethis.drawer = true})graph.on('edge:mouseenter', ({cell}) => {cell.addTools([{name: 'vertices'},{name: 'button-remove',args: {distance: 20},},])})graph.on('node:click', ({node}) => {this.currentNode = node})},// 键盘事件keyboardEvent (graph) {// 键盘事件graph.bindKey('tab', (e) => {e.preventDefault()const selectedNodes = graph.getCells().filter((item) => item.isNode())console.log(selectedNodes)if (selectedNodes.length) {const node = selectedNodes[0]const type = node.attrs['type']this.addChildNode(node.id, type)}})graph.bindKey('delete', (e) => {this.removeNode(this.currentNode)})graph.bindKey('backspace', (e) => {this.removeNode(this.currentNode)})},},watch: {// currentNode: {//   handler (nwVal, old) {//   },//   immediate: true,//   deep: true// }}
}
</script><style>
/* 样式调整 */
#stencil {width: 100px;height: 100%;position: relative;display: flex;flex-direction: column;align-items: center;border-right: 1px solid #dfe3e8;text-align: center;font-size: 12px;
}.dnd-rect {width: 50px;height: 30px;line-height: 40px;text-align: center;border: 2px solid #000000;border-radius: 6px;cursor: move;font-size: 12px;margin-top: 30px;
}.dnd-polygon {width: 35px;height: 35px;border: 2px solid #000000;transform: rotate(45deg);cursor: move;font-size: 12px;margin-top: 30px;margin-bottom: 10px;
}.dnd-circle {width: 35px;height: 35px;line-height: 45px;text-align: center;border: 5px solid #000000;border-radius: 100%;cursor: move;font-size: 12px;margin-top: 30px;
}.dnd-start {border: 2px solid #000000;
}.x6-widget-stencil {background-color: #f8f9fb;
}.x6-widget-stencil-title {background: #eee;font-size: 1rem;
}.x6-widget-stencil-group-title {font-size: 1rem !important;background-color: #fff !important;height: 40px !important;
}.x6-widget-transform {margin: -1px 0 0 -1px;padding: 0px;border: 1px solid #239edd;
}.x6-widget-transform > div {border: 1px solid #239edd;
}.x6-widget-transform > div:hover {background-color: #3dafe4;
}.x6-widget-transform-active-handle {background-color: #3dafe4;
}.x6-widget-transform-resize {border-radius: 0;
}</style>

相关文章:

vue2 + antvx6 实现流程图功能

导入关键包 npm install antv/x6 --save npm install antv/x6-vue-shape 保存插件 (可选) npm install --save antv/x6-plugin-clipboard antv/x6-plugin-history antv/x6-plugin-keyboard antv/x6-plugin-selection antv/x6-plugin-snapline antv/x6-plugin-stencil antv/…...

IDEA 中的奇技淫巧

IDEA 中的奇技淫巧 书签 在使用ctrlalt方向键跳转时&#xff0c;或者追踪代码时&#xff0c;经常遇到的情况是层级太多&#xff0c;找不到代码的初始位置&#xff0c;入口。可以通过书签的形式去打上一个标记&#xff0c;后续可以直接跳转到书签位置。 标记书签&#xff1a;c…...

LSTM-KDE的长短期记忆神经网络结合核密度估计多变量回归区间预测(Matlab)

LSTM-KDE的长短期记忆神经网络结合核密度估计多变量回归区间预测&#xff08;Matlab&#xff09; 目录 LSTM-KDE的长短期记忆神经网络结合核密度估计多变量回归区间预测&#xff08;Matlab&#xff09;效果一览基本介绍程序设计参考资料 效果一览 基本介绍 1.LSTM-KDE的长短期…...

CMakeLists.txt语法规则:部分常用命令说明三

一. 简介 前面几篇文章学习了CMakeLists.txt语法中 add_executable命令&#xff0c;add_library命令&#xff0c;aux_source_directory命令&#xff0c;include_directories命令&#xff0c;add_subdirectory 命令的简单使用。文章如下&#xff1a; CMakeLists.txt语法规则&…...

android init进程启动流程

一,Android系统完整的启动流程 二,android 系统架构图 三,init进程的启动流程 四,init进程启动服务的顺序 五,android系统启动架构图 六,Android系统运行时架构图 bool Service::Start() {// Starting a service removes it from the disabled or reset state and// imme…...

利用爬虫解决数据采集难题

文章目录 安装为什么选择 BeautifulSoup 和 requests&#xff1f;安装 BeautifulSoup 和 requests解决安装问题 示例总结 在现代信息时代&#xff0c;数据是企业决策和发展的关键。然而&#xff0c;许多有用的数据分散在网络上&#xff0c;且以各种格式和结构存在&#xff0c;因…...

智慧粮库/粮仓视频监管系统:AI视频智能监测保障储粮安全

智慧粮库视频监管系统是一种基于物联网、AI技术和视频监控技术的先进管理系统&#xff0c;主要用于对粮食储存环境进行实时监测、数据分析和预警。TSINGSEE青犀智慧粮库/粮仓视频智能管理系统方案通过部署多区域温、湿度、空气成分等多类传感器以及视频监控等设施&#xff0c;对…...

经验浅谈!伦敦银如何交易?

近期&#xff0c;伦敦银价格出现很强的上涨&#xff0c;这促使一些新手投资者进入了市场&#xff0c;但由于缺乏经验&#xff0c;他们不知道该怎么在市场中交易&#xff0c;下面我们就从宏观上介绍一些方法&#xff0c;来讨论一下伦敦银如何交易。 首先我们要知道&#xff0c;要…...

信息系统项目管理师(高项)_习题杂记

1.GB/T16260-2006《软件工程产品质量》系列标准&#xff1a; 1&#xff09;GB/T16260.1-2006《软件工程产品质量第1部分&#xff1a;质量模型》&#xff0c;提出了软件生存周期中的质量模型&#xff1b; 2&#xff09;GB/T16260.2-2006《软件工程产品质量第2部分&#xff1a;…...

CMakeLists.txt 简单的语法介绍

一. 简介 前面通过几个简单地示例向大家演示了 cmake 的使用方法&#xff0c;由此可知&#xff0c;cmake 的使用方法其实还是非常简单的&#xff0c;重点在于编写 CMakeLists.txt&#xff0c;CMakeLists.txt 的语法规则也简单&#xff0c;并没有 Makefile 的语法规则那么复杂难…...

AI时代:人工智能大模型引领科技创造新时代

目录 前言一. AI在国家战略中有着举足轻重的地位1.1 战略1.2 能源1.3 教育 二. AI在日常生活中扮演着重要角色2.1 医疗保健2.2 智能客服2.3 自动驾驶2.4 娱乐和媒体2.5 智能家居 三. AI的未来发展趋势 总结 前言 随着AI技术的进步&#xff0c;新一代的AI技术已经开始尝试摆脱依…...

为什么 IP 地址通常以 192.168 开头?(精简版)

网络通讯的本质就是收发数据包。如果说收发数据包就跟收发快递一样。IP地址就类似于快递上填的收件地址和发件地址一样&#xff0c;路由器就充当快递员的角色&#xff0c;在这个纷繁复杂的网络世界里找到该由谁来接收这个数据包&#xff0c;所以说&#xff1a;IP地址就像快递里…...

【HEC】HECRAS中的降雨边界

目录 说明HEC-RAS网格降雨模型与HEC-HMS的比较HECRAS 降雨边界2D Area降雨边界添加降水边界条件调整2D Flow Area特性添加入渗网格数据创建土地覆盖层创建土壤层创建入渗层指定几何图形关联具有空间变化的网格降水数据Point点数据Gridded网格化数据Constant恒定值蒸散和风数据...

搜索算法系列之三(插值查找)

前言 插值查找仅适用于有序数据、有序数组&#xff0c;和二分查找类似&#xff0c;更讲究数据有序均匀分布。 算法原理 插值查找(interpolation search)是一种查找算法&#xff0c;它与二分查找类似&#xff0c;但在寻找元素时更加智能化。这种算法假设数据集是等距的或者有…...

前端奇怪面试题总结

面试题总结 不修改下面的代码进行正常解构 这道题考的是迭代器和生成器的概念 let [a,b] {a:1,b:2}答案 对象缺少迭代器&#xff0c;需要手动加上 Object.prototype[Symbol.iterator] function* (){// return Object.values(this)[Symbol.iterator]()return yeild* Object.v…...

NPM--最新淘宝镜像源地址

最新淘宝镜像源地址&#xff1a; 原来的 https://registry.npm.taobao.org 已替换为 https://registry.npmmirror.com 查看镜像源 npm config get registry 更换为淘宝最新镜像源 npm config set registry https://registry.npmmirror.com...

vue3中实现地区下拉选择组件封装

1组件文件 新建一个文件夹内&#xff0c;包含inde.vue,index.ts,pac.json这三个文件 index.vue文件 <template><el-cascaderv-model"data":options"pcaData":style"{ width: props.width }":placeholder"props.placeholder&quo…...

责任链模式案例

需求背景&#xff1a; 请你设计一个员工休假审批流程&#xff0c;当员工的休假天数<1时&#xff0c;由直接领导审批&#xff0c;休假天数<2时&#xff0c;分别由直接领导、一级部门领导审批&#xff0c;休假天数>3时&#xff0c;分别由直接领导、一级部门领导、分管领…...

Android NDK开发(二)——JNIEnv、jobject与jclass关系

本文主要讲解Android NDK开发中JNIEnv、jobject与jclass的相关知识&#xff0c;并用c和c两种语言实现了jobject和jclass。 本专栏知识点是通过<零声教育>的音视频流媒体高级开发课程进行系统学习&#xff0c;梳理总结后写下文章&#xff0c;对音视频相关内容感兴趣的读者…...

机器学习入门:sklearn基础教程

Scikit-learn&#xff08;简称sklearn&#xff09;是Python中最受欢迎的机器学习库之一&#xff0c;它提供了丰富的机器学习算法和工具&#xff0c;适用于各种任务和场景。本文将为您介绍sklearn的基础知识和常用功能&#xff0c;带您踏入机器学习的世界。 1. 安装与导入 首先…...

Python从入门到精通(05章):类与对象结构

Python从入门到精通&#xff08;第05章&#xff09;&#xff1a;条件判断与分支结构 开头导语 这是本系列第05章。本文采用“知识点讲解 错误示例 正确写法 自测清单”的结构&#xff0c;目标是让你不仅能看懂&#xff0c;还能独立写出可运行代码。建议你边看边敲&#xff0…...

OpenClaw跨平台测试:Qwen3-VL:30B在Mac/Win/Linux飞书表现

OpenClaw跨平台测试&#xff1a;Qwen3-VL:30B在Mac/Win/Linux飞书表现 1. 测试背景与动机 去年12月接手团队自动化工具选型时&#xff0c;我们遇到了一个典型困境&#xff1a;团队成员分别使用macOS、Windows和Ubuntu系统&#xff0c;但现有AI助手工具要么绑定特定平台&#…...

Win11 24H2新技巧:无需微软账户快速完成OOBE本地账户配置

1. Win11 24H2本地账户配置的现状与痛点 每次拿到新电脑或者重装系统时&#xff0c;最烦人的就是那个漫长的初始化设置过程。特别是Windows 11强制要求登录微软账户的设定&#xff0c;让很多注重隐私或者网络条件不好的用户头疼不已。我最近帮朋友配置了几台预装Win11 24H2的新…...

AnimateDiff文生视频零基础入门:5分钟学会用文字生成动态GIF

AnimateDiff文生视频零基础入门&#xff1a;5分钟学会用文字生成动态GIF 1. 为什么选择AnimateDiff作为文生视频的起点&#xff1f; 如果你曾经尝试过AI视频生成工具&#xff0c;可能会被复杂的操作流程和硬件要求劝退。传统方案往往需要你先准备一张静态图片&#xff0c;再通…...

实战:在无商店的Win10企业版ThinkPad上,通过PowerShell手动部署Lenovo Vantage

1. 为什么需要手动部署Lenovo Vantage 很多ThinkPad用户可能都遇到过这样的困扰&#xff1a;新装的Windows 10企业版系统找不到微软应用商店&#xff0c;而Lenovo Vantage这个必备的管理工具又只能通过商店安装。作为一个长期使用ThinkPad的技术博主&#xff0c;我完全理解这种…...

空调智慧节能控制系统解决方案:一键部署,适配多场景节能需求

一、应用背景 当前&#xff0c;建筑能耗已成为社会总能耗的重要组成部分&#xff0c;其中空调系统能耗占比高达50%左右&#xff0c;尤其在商业综合体、高校、酒店、写字楼等大型建筑中&#xff0c;空调能耗过高、管理粗放的问题尤为突出。传统空调控制系统依赖人工操作&#xf…...

嵌入式软件分层架构设计与RTOS抽象实践

通用嵌入式软件架构分层设计实践指南1. 项目概述1.1 系统架构设计背景在嵌入式系统开发中&#xff0c;随着项目复杂度提升&#xff0c;代码组织混乱、可维护性差成为常见问题。特别是在使用STM32、GD32等主流单片机时&#xff0c;缺乏合理的软件分层设计会导致以下问题&#xf…...

构建坚不可摧的AI应用:Gemini API错误码诊断与容错实战指南

构建坚不可摧的AI应用&#xff1a;Gemini API错误码诊断与容错实战指南 【免费下载链接】cookbook A collection of guides and examples for the Gemini API. 项目地址: https://gitcode.com/GitHub_Trending/coo/cookbook 当你的AI应用在关键时刻突然抛出"503 Se…...

游戏数据可视化与卡车模拟辅助工具:ETS2 Telemetry Server全解析

游戏数据可视化与卡车模拟辅助工具&#xff1a;ETS2 Telemetry Server全解析 【免费下载链接】ets2-telemetry-server ETS2/ATS Telemetry Web Server Mobile Dashboard 项目地址: https://gitcode.com/gh_mirrors/et/ets2-telemetry-server 在数字化驾驶体验日益普及的…...

2026年(新锐)期刊分区表正式发布(附下载)

2026年3月24日&#xff0c;由新锐学术研制的《新锐期刊分区表》&#xff08;简称“新锐分区”&#xff09;正式推出。据中国科学院期刊分区表公众号2025年11月介绍&#xff1a;应广大用户的要求&#xff0c;"期刊分区表"公众号将专注于发布期刊分区表相关的动态信息&…...