当前位置:   article > 正文

jsPlumb+vue创建字段映射关系_jsplumb 字段映射

jsplumb 字段映射

项目中需要将ES数据库表字段和其他库表字段做映射,研究了下jsPlumb,做一下记录;

1: 安装 yarn add jsPlumb

2: 引入 import {jsPlumb} from ‘jsplumb’

created(){
    this.plumbIns = jsPlumb.getInstance({
      Container:"plumbContainer",   //选择器id
      ConnectionsDetachable: false, // 再次拖动时不取消选择
      maxConnections: 1, 
      uniqueEndpoint:true,
      Endpoint: "Dot",
      EndpointStyle: { radius: 7, fill: "#fff", outlineRadius: 5, outlineStroke: '#47a3f8', outlineWidth: 3},  //端点样式
      EndpointHoverStyle: { fill: '#47a3f8', radius:7 }, // 端点悬停样式
      PaintStyle: { // 绘画样式,默认8px线宽  #456
        fill: 'white',
        outlineStroke: '#47a3f8',
        strokeWidth: 2,
        outlineStrokeWidth: 3,
        radius: 7,
        outlineRadius: 10
      },
      HoverPaintStyle: { // 默认悬停样式  默认为null
        outlineStroke: 'lightblue'
      },
      ConnectorStyle: {
        outlineStroke: '#47a3f8',
        strokeWidth: 1
      },
      ConnectorHoverStyle: {
        strokeWidth: 2
      },
      ConnectionOverlays:[ //连线上的默认样式  这里是箭头
        ["Arrow",{ width: 12, length: 12, location: 1 , paintStyle: {
						stroke: '#00688B',
						fill: '#00688B',
          }
        }]
      ],
      Connector:["Straight",{gap:1}]   //要使用的默认连接器的类型:折线,流程等
       })},
    mounted(){
	 	let ins = this.plumbIns;
			ins.batch(() => {
				this.initAll();
				this.connectionAll();
	    });
  },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

methods:{

initAll () {
		let rl = this.leftDataListCopy;
		for (let i = 0; i < rl.length; i++) {
			this.init(rl[i].id, 0)
		}
		let rl2 = this.rightDataListCopy;
		for (let i = 0; i < rl2.length; i++) {
			this.init(rl2[i].id, 1)
		}
	},
	// 初始化规则使其可以连线、拖拽
	init (id, type) {
		let ins = this.plumbIns,
      elem = document.getElementById(id);
  const defaultParam = {
    anchor: ["Perimeter", {anchorCount:200, shape:"Rectangle"}],
    allowLoopback: false,
    maxConnections: 1,
  }
  
  const common = {
    // connector: 'Straight',
  }
  if (type === 1) {
    ins.addEndpoint(elem, {
      anchors: ['Left'],
      uuid: id
    }, {...common, isSource: false,isTarget: true})
  } else {
    ins.addEndpoint(elem, {
      anchors: ['Right'],
      uuid: id
    }, {...common, isSource: true,isTarget: false})
  }
		
		ins.draggable(elem,{
			containment: true
  });
},
connectionAll () {
		let ins = this.plumbIns;
		ins.ready(() => {
			for (let i = 0; i < this.connlist.length; i++) {
      let conn = this.connlist[i],
      	connection = ins.connect({
          uuids: [`${conn.sourceNodeId}`, `${conn.targetNodeId}`],
					});
    }
    ins.bind('click', (conn, originalEvent)=> {
      this.$confirm('确认删除映射么?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        ins.deleteConnection(conn)
      }).catch(()=>{})
    })
		})
	},
	}`
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

参考链接: 中文介绍
官网

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/117152
推荐阅读
相关标签
  

闽ICP备14008679号