vue中使用Drawflow连线插件,并对端口进行命名

news2024/9/20 10:55:46

效果如图

场景:项目中需要拖拽模块并连线,有输入端和输出端之分,不同模块不同端口才能相连

文档相关

点击前往------->原项目git地址

点击前往------->提供端口既可输出又可输出方案

点击前往----->查阅发现原项目无法对端口命名

public文件夹下创建drawflow文件夹,将原项目的对应文件放在drawflow文件夹中,并且在public文件下的html中对对应的文件进行引用,这样对应的js就挂载在window上

<link rel="stylesheet" href="./Drawflow/dist/drawflow.min.css">

<link rel="stylesheet" href="./Drawflow/docs/beautiful.css">

<script src="./Drawflow/dist/drawflow.min.js"></script>

 

<template>
  <div>
    <div class="wrapper drawflow-box">
      <div class="col">
        <el-collapse accordion>
          <div v-for="(item,index) in listData" :key="index">
            <el-collapse-item :title="item.name">
              <el-row :gutter="12">
                <el-col :span="12" v-for="(data,key) in item.children" :key="key">
                  <div class="drawflow-drag" draggable="true" @dragstart="drag($event)" :data-node="data.type">
                    <i class="el-icon-platform-eleme"></i>
                    <span>{{data.name}}</span>
                  </div>
                </el-col>
              </el-row>
            </el-collapse-item>
          </div>
        </el-collapse>

      </div>
      <div class="col-right">
        <div class="menu">
          <ul>
            <li @click="changeModule($event);" class="selected">模块单元</li>
            <!-- <li @click="editor.changeModule('Home'); changeModule($event);" class="selected">模块单元</li> -->
            <!-- <li @click="editor.changeModule('Other'); changeModule($event);">Other Module</li> -->
          </ul>
        </div>
        <div id="drawflow" @drop="drop($event)" @dragover="allowDrop($event)">

          <div class="btn-export" @click="handleExport(editor.export())">导出</div>
          <div class="btn-clear" @click="editor.clearModuleSelected()">清除</div>
          <!-- <div class="btn-lock">
            <i id="lock" class="fas fa-lock" onclick="editor.editor_mode='fixed'; changeMode('lock');"></i>
            <i id="unlock" class="fas fa-lock-open" onclick="editor.editor_mode='edit'; changeMode('unlock');" style="display:none;"></i>
          </div> -->
          <div class="bar-zoom">
            <i class="icon-suoxiao" title="缩小" @click="editor.zoom_out()"></i>
            <i class="icon-fuwei" title="复位" @click="editor.zoom_reset()"></i>
            <i class="icon-fangda" title="放大" @click="editor.zoom_in()"></i>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// Drawflow 连线插件

export default {
  data() {
    return {
      active: "",
      editor: null,
      mobile_item_selec: "",
      mobile_last_move: null,
      transform: "",
      listData: [
        {
          type: "in",
          name: "输入模块",
          children: [
            {
              name: "输入模块一",
              type: "test",
            },
            {
              name: "输入模块二",
              type: "test",
            },
            {
              name: "输入模块三",
              type: "test",
            },
          ],
        },
        {
          type: "out",
          name: "输出单元",
          children: [
            {
              name: "输出单元一",
              type: "dbclick",
            },
            {
              name: "输出单元二",
              type: "dbclick",
            },
            {
              name: "输出单元三",
              type: "dbclick",
            },
          ],
        },
      ],
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.init();
      //挂载方法事件
      window.showpopup = this.showpopup;
      window.closemodal = this.closemodal;
    });
  },
  methods: {
    init() {
      var id = document.getElementById("drawflow");
      this.editor = new window.Drawflow(id);
      this.editor.reroute = true;
      this.editor.reroute_fix_curvature = true;
      this.editor.force_first_input = false;

      const dataToImport = {
        drawflow: {
          Home: {
            data: {},
          },
        },
      };

      this.editor.start();
      this.editor.import(dataToImport);
      this.editor.addNode(
        "test",
        3,
        3,
        180,
        200,
        "test",
        {
          name: "",
          inputs: {
            input_1: { connections: [], name: "t1" },
            input_2: { connections: [], name: "t2" },
            input_3: { connections: [], name: "t3" },
          },
          outputs: {
            output_1: { connections: [], name: "t4" },
            output_2: { connections: [], name: "t5" },
            output_3: { connections: [], name: "t6" },
          },
        },
        '<div><div class="content-box">Multiple!</div></div>'
      );
    },
    //下面的所有方法都是从原项目html中直接搬过来,有问题去原项目看
    showpopup(e) {
      e.target.closest(".drawflow-node").style.zIndex = "9999";
      e.target.children[0].style.display = "block";
      //document.getElementById("modalfix").style.display = "block";

      //e.target.children[0].style.transform = 'translate('+translate.x+'px, '+translate.y+'px)';
      this.transform = this.editor.precanvas.style.transform;
      this.editor.precanvas.style.transform = "";
      this.editor.precanvas.style.left = this.editor.canvas_x + "px";
      this.editor.precanvas.style.top = this.editor.canvas_y + "px";

      //e.target.children[0].style.top  =  -editor.canvas_y - editor.container.offsetTop +'px';
      //e.target.children[0].style.left  =  -editor.canvas_x  - editor.container.offsetLeft +'px';
      this.editor.editor_mode = "fixed";
    },
    closemodal(e) {
      e.target.closest(".drawflow-node").style.zIndex = "2";
      e.target.parentElement.parentElement.style.display = "none";
      //document.getElementById("modalfix").style.display = "none";
      this.editor.precanvas.style.transform = this.transform;
      this.editor.precanvas.style.left = "0px";
      this.editor.precanvas.style.top = "0px";
      this.editor.editor_mode = "edit";
    },
    allowDrop(ev) {
      ev.preventDefault();
    },
    drag(ev) {
      if (ev.type === "touchstart") {
        this.mobile_item_selec = ev.target
          .closest(".drag-drawflow")
          .getAttribute("data-node");
      } else {
        ev.dataTransfer.setData("node", ev.target.getAttribute("data-node"));
      }
    },
    drop(ev) {
      if (ev.type === "touchend") {
        var parentdrawflow = document
          .elementFromPoint(
            mobile_last_move.touches[0].clientX,
            mobile_last_move.touches[0].clientY
          )
          .closest("#drawflow");
        if (parentdrawflow != null) {
          this.addNodeToDrawFlow(
            mobile_item_selec,
            mobile_last_move.touches[0].clientX,
            mobile_last_move.touches[0].clientY
          );
        }
        mobile_item_selec = "";
      } else {
        ev.preventDefault();
        var data = ev.dataTransfer.getData("node");
        this.addNodeToDrawFlow(data, ev.clientX, ev.clientY);
      }
    },
    addNodeToDrawFlow(name, pos_x, pos_y) {
      let editor = this.editor;
      if (editor.editor_mode === "fixed") {
        return false;
      }
      pos_x =
        pos_x *
          (editor.precanvas.clientWidth /
            (editor.precanvas.clientWidth * editor.zoom)) -
        editor.precanvas.getBoundingClientRect().x *
          (editor.precanvas.clientWidth /
            (editor.precanvas.clientWidth * editor.zoom));
      pos_y =
        pos_y *
          (editor.precanvas.clientHeight /
            (editor.precanvas.clientHeight * editor.zoom)) -
        editor.precanvas.getBoundingClientRect().y *
          (editor.precanvas.clientHeight /
            (editor.precanvas.clientHeight * editor.zoom));

      switch (name) {
        case "test":
          var test = `
            <div>
              <div class="box" ondblclick="showpopup(event)">
                双击可以打开!
                <div class="modal" style="display:none">
                  <div class="modal-content">
                    <span class="close" onclick="closemodal(event)">&times;</span>
                    插入文本
                    <input type="text">
                  </div>
                </div>
              </div>
            </div>
            `;
          editor.addNode(
            "test",
            3,
            3,
            pos_x,
            pos_y,
            "test",
            {
              name: "test",
              inputs: {
                input_1: { connections: [], name: "t1" },
                input_2: { connections: [], name: "t2" },
                input_3: { connections: [], name: "t3" },
              },
              outputs: {
                output_1: { connections: [], name: "t4" },
                output_2: { connections: [], name: "t5" },
                output_3: { connections: [], name: "t6" },
              },
            },
            test
          );
          break;
        case "multiple":
          var multiple = `
            <div>
              <div class="box">
                Multiple!
              </div>
            </div>
            `;
          editor.addNode(
            "multiple",
            3,
            4,
            pos_x,
            pos_y,
            "multiple",
            {},
            multiple
          );
          break;
        case "dbclick":
          var dbclick = `
            <div>
            <div class="title-box"><i class="fas fa-mouse"></i> Db Click</div>
              <div class="box dbclickbox" ondblclick="showpopup(event)">
                Db Click here
                <div class="modal" style="display:none">
                  <div class="modal-content">
                    <span class="close" onclick="closemodal(event)">&times;</span>
                    插入文本
                    <input type="text" df-name>
                  </div>
                </div>
              </div>
            </div>
            `;
          editor.addNode("dbclick", 3, 3, pos_x, pos_y, "dbclick", {}, dbclick);
          break;

        default:
      }
    },
    changeModule(event) {
      var all = document.querySelectorAll(".menu ul li");
      for (var i = 0; i < all.length; i++) {
        all[i].classList.remove("selected");
      }
      event.target.classList.add("selected");
    },
    handleExport(val) {
      console.log(val);
    },
  },
};
</script>
<style>
.drawflow .drawflow-node .input::before {
      //通过操作标签上的属性,动态获取对应的文字
      content: attr(data-before);
      position: absolute;
      width: 64px;
      text-align: right;
      top: 0;
      left: -72px;
      font-size: 12px;
      color: #67C23A;
    }
    .drawflow .drawflow-node .output::before {
      content: attr(data-before);
      position: absolute;
      text-align: left;
      width: 64px;
      top: 0;
      left: 20px;
      font-size: 12px;
      color: #F56C6C;
    }
</style>
<style lang="scss">

.drawflow-box {
  /** 样式调整 */
  .col {
    background: #fff;
    padding: 0 20px;
    box-sizing: border-box;
    .el-row {
      margin-top: 10px;
      .el-col {
        .drawflow-drag {
          width: 120px;
          height: 64px;
          border: 1px solid #ccc;
          margin: 0 auto;
          cursor: move;
          user-select: none;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
  }
  .test .drawflow_content_node {
    height: 100%;
  }

  .content-box {
    padding: 20px;
  }
}
</style>

 

修改 Drawflow/dist 文件夹下的drawflow.min.js文件对应的addNode方法(拖拽组件时执行)

添加1,2两处代码后,

 如果自定义节点类型中带了name属性,对应的端口就会出现对应的名称,如果没有name就按原项目逻辑执行

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/714753.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

myCobot 280 2023机械臂全新功能,手柄控制、自干涉检测

引言 机械臂是一种可编程的、自动化的机械系统&#xff0c;它可以模拟人类的动作&#xff0c;完成各种任务&#xff0c;例如装配、喷涂、包装、搬运、焊接、研磨等。由于其高度灵活性和多功能性&#xff0c;机械臂在现代社会中已经得到了广泛的应用。 myCobot 280 M5Stack 20…

在服务器部署前后端分离的项目(前后都有), 并使用nginx配置跨域

怎样部署自己的项目呢 先准备一个服务器(小系统最便宜的轻量级服务器就行, 如果不需要给人访问的话)安装宝塔面板 (宝塔面板, 可视化界面, 操作简单, 使用非常方便, 上手也很容易, 如果只是学习, 虚拟机也行没必要花钱, 我使用的CentOS7系统,安装宝塔面板)软件: MySQL, Tomcat…

【问题记录】多线程环境下,使用 std::cout 输出内容会显示混乱

环境 Windows 11 家庭中文版Microsoft Visual Studio Community 2022 (64 位) - Current 版本 17.5.3 测试代码 #include <iostream> #include <Windows.h>//创建的线程数量 #define THREAD_COUNT 4DWORD WINAPI ThreadProc(LPVOID lpParam) {UNREFERENCED_P…

JS事件监听

目录 事件监听 事件监听案例 事件监听 事件&#xff1a;HTML事件是发生在HTML元素上的“事情” 按钮点击鼠标移动到元素上按下键盘按键事件监听&#xff1a;JS可以在事件被检测到时执行代码事件绑定 方法一&#xff1a;通过HTML标签中的事件属性进行绑定 <input type"…

在windows环境下安装支持CUDA的opencv-python

文章目录 附件&#xff1a;GPU和CUDA的关系 —— 开发人员通过CUDA可以使用GPU的计算能力来加速各种计算任务&#xff0c;并提高计算性能和效率。一、环境配置&#xff08;0&#xff09;我的电脑配置环境&#xff08;1&#xff09;CUDA cuDNN下载与安装&#xff08;2&#xff…

【云原生、Kubernetes】Kubernetes核心概念理解

首先我们要掌握 Kubernete 的一些核心概念。 这些核心可以帮助我们更好的理解 Kubernetes 的特性和工作机制。 集群组件 首先&#xff0c;Kubernetes 集群中包含2类节点&#xff0c;分别是&#xff1a;master控制节点和node工作节点。 master 控制节点 负责管理整个集群系统…

【手撕算法|动态规划系列No.4】leetcode91. 解码方法

个人主页&#xff1a;平行线也会相交 欢迎 点赞&#x1f44d; 收藏✨ 留言✉ 加关注&#x1f493;本文由 平行线也会相交 原创 收录于专栏【手撕算法系列专栏】【LeetCode】 &#x1f354;本专栏旨在提高自己算法能力的同时&#xff0c;记录一下自己的学习过程&#xff0c;希望…

软件测试:系统测试

1 系统测试的概念 系统测试&#xff08;System Testing&#xff09;的定义&#xff1a;将已经集成好的软件系统&#xff0c;作为整个基于计算机系统的一个元素&#xff0c;与计算机硬件、外设、某些支持软件、数据和人员等其他系统元素结合在一起&#xff0c;在实际运行&#…

HDLBits刷题笔记8:Circuits.Sequential Logic.Latches and Flip-Flops

D flip-flop module top_module (input clk,input d,output reg q );always (posedge clk)q < d; endmoduleD flip-flops 建立一个8bit的D触发器 module top_module (input clk,input [7:0] d,output reg [7:0] q );always (posedge clk)q < d; endmoduleDFF with res…

GDAL 图像直方图统计

文章目录 一、简介二、实现代码三、实现效果参考资料 一、简介 这里使用一种简单的方式来计算图像中的像素值直方图分布。计算过程如下所述&#xff1a; 第一种方式&#xff1a; 1、首先将图像变为一维数组&#xff08;reshape&#xff09;&#xff0c;并将数组中的数值进行排序…

vue点击盒子一步一步滚动

vue点击盒子一步一步滚动 HTML <div class"course_detail"><div class"arrow" v-if"index 0" click"step"></div><div class"lightArrow" v-else click"step"></div><div clas…

自定义的车牌号键盘组件

<template><view class"keyboard-wrap" v-if"kbShow"><view class"head"><view class"done" tap"done"><text class"iconfont iconxiala-"></text>关闭</view></vi…

2. 注册platform

这里先分析platform 对应的dts内容如下 i2s0_8ch: i2sff800000 {compatible "rockchip,rv1126-i2s-tdm";reg <0xff800000 0x1000>;interrupts <GIC_SPI 46 IRQ_TYPE_LEVEL_HIGH>;clocks <&cru MCLK_I2S0_TX>, <&cru MCLK_I2S0_RX&g…

JAVA开发( 腾讯云消息队列 RocketMQ使用总结 )

一、问题背景 之所以需要不停的总结是因为在java开发过程中使用到中间件实在太多了&#xff0c;久久不用就会慢慢变得生疏&#xff0c;有时候一个中间很久没使用&#xff0c;可能经过了很多版本的迭代&#xff0c;使用起来又有区别。所以还是得不断总结更新。最近博主就是在使用…

睿铂相机同步性控制技术解析

极客睿铂 前几期睿铂给大家分享了一些倾斜相机背后的技术&#xff0c;主要都是的关于镜头光学方面的。但实际上倾斜摄影相机还有很多其他关键性技术有待突破&#xff0c;任何技术的发展都不能一蹴而就&#xff0c;需要根据客户的问题反馈&#xff0c;发现新的问题并解决问题&a…

自定义MVC架构【下】

目录 一、前言 二、导出自定义MVC架包 三、使用自定义MVC架包 四、优化增删改查Dao层及Servlet 1.优化增删改查Dao层 2.优化增删改查Servlet代码 五、案例实操 1.将PageTag自定义标签进行配置 2.jsp页面环境搭建 3.案例演示 一、前言 在上篇中&#xff0c;我们已经优化…

ARM架构(寄存器点灯)

文章目录 前言一、LED原理图二、使用寄存器点灯的步骤三、如何操作寄存器四、实际操作1.使能GPIO端口2.将引脚设置为输出模式3.设置输出状态 五、全部代码总结 前言 本篇文章我们来讲解一下如何使用寄存器点亮一个LED灯&#xff0c;一般对于新人来说都是使用HAL库或者标准库来…

SpringBoot3【④ 基础特性】

1. SpringApplication 1.1. 自定义 banner 类路径添加banner.txt或设置spring.banner.location就可以定制 banner推荐网站&#xff1a;Spring Boot banner 在线生成工具&#xff0c;制作下载英文 banner.txt&#xff0c;修改替换 banner.txt 文字实现自定义&#xff0c;个性化…

操作系统面试知识点

1、进程、线程和协程的区别和联系 1、进程是资源调度的基本单位&#xff0c;运行一个可执行程序会创建一个或多个进程&#xff0c;进程就是运行起来的可执行程序 2、线程是程序执行的基本单位&#xff0c;是轻量级的进程。每个进程中都有唯一的主线程&#xff0c;且只能有一个…

机器学习第三课(sklearn接口)

一、sklearn基本知识 中文官网 英文官网 注意&#xff1a;sklearn第三方模块的安装 要用pip install scikit-learn from sklearn.neighbors import KNeighborsClassifier # 1 准备数据 # 训练集的特征数据 2维 x [[-2],[-1],[2],[3],[4]] # 训练集的目标数据 1维 y [0,0,1,…