首页 > 其他分享 >el-table树形数据 + jsPlumb , 批量映射字段

el-table树形数据 + jsPlumb , 批量映射字段

时间:2023-08-30 16:22:05浏览次数:41  
标签:el 连线 -- jsPlumb instance let table pointList row

<template>

<el-dialog
title="映射"
append-to-body
:visible.sync="mappingShow"
:close-on-click-modal="false"
:before-close="closeFileMappingDialog"
width="1000px"
>
<el-card class="box-card" shadow="always">

<el-row style="margin-bottom: 10px;" >
<el-col :span="24" >
{{ routeRow.mappingname }}
</el-col>
</el-row>
<el-row >
<!-- :gutter="20" -->

<div id="jsplumbContainer" @scroll="connect" >

<el-col :span="8">
<el-table id="leftTable"
:data="leftTab"
row-key="code"
default-expand-all
border
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
:row-class-name="({row}) => `leftRow Id-${row.code}`"
>
<el-table-column label="名称" prop="name"></el-table-column>
<!-- <el-table-column label="代码" >-->
<!-- <template slot-scope="scope">-->
<!-- <div :class="`leftRow Id-${scope.row.code}`" :id="scope.row.code" >-->
<!-- {{ scope.row.code }}-->
<!-- </div>-->
<!-- </template>-->
<!-- </el-table-column>-->
</el-table>
</el-col>

<el-col :span="8" :offset="8">
<el-table id="rightTable"
:data="rightTab"
row-key="code"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
default-expand-all
border
:row-class-name="({row}) => `rightRow Id-${row.code}`"
>
<el-table-column label="名称" prop="name"></el-table-column>
<!-- <el-table-column label="代码" >-->
<!-- <template slot-scope="scope">-->
<!-- <div :id="scope.row.code" >-->
<!--&lt;!&ndash; :class="`rightRow Id-${scope.row.code}`" &ndash;&gt;-->
<!-- {{ scope.row.code }}-->
<!-- </div>-->
<!-- </template>-->
<!-- </el-table-column>-->
</el-table>

</el-col>
</div>

</el-row>


</el-card>

</el-dialog>

</template>

<script>

// import { jsPlumb } from 'jsplumb'
import jsPlumb from 'jsplumb'
//jsplumb使用
let $jsPlumb = jsPlumb.jsPlumb;

let instance = null;
const relationship = []

export default {
name: "fieldMapping",
props:{
currentTreeData:{},
leftTab: [],
rightTab: [],
},
data() {
return {
mappingShow: false,
routeRow:{},
contrastId: this.currentTreeData.id, // 点击树id

pointList: [ ],
count: 0,

}
},
watch(){

},
created() {

this.init3();

},
mounted(){


},
methods:{

openFileMappingDialog(row){
// console.log('选择数据 row :', row )
this.routeRow = row ;

this.mappingShow = true ;

this.initJsPlumb() ;

},
closeFileMappingDialog(){
this.mappingShow = false ;
},

initJsPlumb(){
let that = this ;
that.$nextTick(()=> {
instance.ready(function () {

setTimeout(()=>{
// console.log(' /////// initJsPlumb ///////////////' )

instance.setContainer('jsplumbContainer');
// 初始化jsPlumb 创建jsPlumb实例
// that.init3();
// 设置可以为连线起点和连线终点的元素
that.setContainer();
// 设置默认连线
// that.setConnect(relationship);
// 绑定事件监听
that.setEvent();
// 连线前的判断
// that.beforeDrop3();

},1000)

});
})
},
init3() {

instance = $jsPlumb.getInstance({
//父级元素id;假如页面元素所在上层不同,最外层父级一定要设置
Container: "jsplumbContainer",
// DragOptions : { cursor: "pointer", zIndex:2000 },//拖动的时候
PaintStyle: { //连接线样式
stroke: '#BCBCBC',
strokeWidth: 5,
},
HoverPaintStyle: {
stroke: '#1E90FF'
},
EndpointStyle: {
fill: '#BCBCBC',
radius: 6
},
EndpointHoverStyle: {
fill: '#1E90FF',
radius: 8
}, // 端点悬停样式
Rectangle: {

},
ConnectionsDetachable: true, //连线是否可用鼠标分离
ReattachConnections: true, //是否重新连接使用鼠标分离的线
});

},
// 截取元素类名中的id
interceptId(className){
return className.slice(className.indexOf('-') + 1);
},
// 设置可以连线的元素
setContainer(){
// console.log(' /////// 设置可以连线的元素 ///////////////' )
const leftElList = document.querySelectorAll('.leftRow'); // 左侧行元素集合
const rightElList = document.querySelectorAll('.rightRow'); // 右侧行元素集合
// 将dom元素设置为连线的起点或者终点 设置了起点的元素才能开始连线 设置为终点的元素才能为连线终点
// console.log('leftElList ==>', leftElList )
instance.batch(function () {
[leftElList, rightElList].forEach((trList, index) => {
trList.forEach((tr) => {
// const id = that.interceptId(tr.classList[2]);
instance.setDraggable(tr, false); // 是否支持拖拽
if (index === 0) {
// const item = that.leftTab.find(i => i.id == id);
// 判断是否有子项,若没有则设置为起点
// !item?.hasChild && instance.makeSource(tr, {
instance.makeSource(tr, {
// anchor: ["Right"], // 设置端点位置
anchor: [1, 0.5, 0, 0], // 左 上 右 下
allowLoopback: true, //允许回连
maxConnections: -1, //最大连接数(-1表示不限制)
endpoint: "Dot"
})
}
else {
// const item = that.rightTab.find(i => i.id == id);
// 判断是否有子项,若没有则设置为终点
// !item?.hasChild && instance.makeTarget(tr, {
instance.makeTarget(tr, {
// anchor: ["Left"], // 设置端点位置
anchor: [0, 0.5, 0, 0], // 左 上 右 下
allowLoopback: true, //允许回连
maxConnections: -1, //最大连接数(-1表示不限制)
});
}
});
});
});

},
// 设置默认连线
setConnect(relationship) {
setTimeout(() => {
relationship.forEach(function (data) {
// source是连线起点元素id target是连线终点元素id
instance.connect({
source: document.querySelector(`.Id-${data.sourceId}`),
target: document.querySelector(`.Id-${data.targetId}`)
});
});
})
},
// 绑定事件监听
setEvent() {
let that = this ;
// 连线事件
instance.bind("connection", function (connInfo, originalEvent) {
// connInfo是jsPlumb对象 可以打印出来康康有哪些东西 source
// console.log('连线事件 connInfo :', connInfo, )
let sourceid = that.interceptId(connInfo.source.classList[2]);
let targetid = that.interceptId(connInfo.target.classList[2]);
console.log('连线事件 :', sourceid, targetid, connInfo.source.classList, )
that.pointList.push({
sourceId: sourceid,
targetId: targetid ,
pointIds: sourceid + "-" + targetid
})
that.pointList = that.unique(that.pointList)
// console.log('连线事件 pointList :', that.pointList, )
});
// 点击连接线删除该条线
instance.bind('click', function (connection, originalEvent) {
let sourceid = that.interceptId(connection.source.classList[2]);
let targetid = that.interceptId(connection.target.classList[2]);
console.log('删除事件 :', sourceid, targetid , connection, )

that.$confirm("确认删除映射么?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
closeOnClickModal: false,
type: "warning",
})
.then(() => {
instance.deleteConnection(connection);
for(let i = 0; i < that.pointList.length; i++) {
let item = that.pointList[i];
if ( item.sourceId == sourceid && item.targetId == targetid ) {
that.pointList.splice(i, 1);
}
}

})
.catch(() => {});

// console.log('删除事件 pointList :', that.pointList, )

})

},
unique(arr) {
const res = new Map();
return arr.filter((arr) => !res.has(arr.pointIds) && res.set(arr.pointIds, 1));
},
// 页面滚动,连线跟随变化
connect() {
this.count++;
if (this.count >= 3) {
let connections = instance.getAllConnections();
let linePoints = [];
for (let i = connections.length - 1; i >= 0; i--) {
linePoints.push([connections[i].sourceId, connections[i].targetId]);
instance.deleteConnection(connections[i]);
}
for (let i = 0; i < linePoints.length; i++) {
instance.connect({
source: linePoints[i][0],
target: linePoints[i][1]
});
}
this.count = 0;
}
},


}
}
</script>

<style lang="scss" scoped>

#jsplumbContainer{
height: 65vh;
overflow-y: auto;
position: relative; /*一定加上这句,否则连线位置发生错乱*/
}
.el-table /deep/.el-table__cell {
padding: 5px 0;
}

</style>

标签:el,连线,--,jsPlumb,instance,let,table,pointList,row
From: https://www.cnblogs.com/llying/p/17667562.html

相关文章

  • excel导出功能
    packagecom.infosec.ztpdp.policycenter.module.audit.controller;importjava.io.IOException;importjava.io.OutputStream;importjava.net.URLDecoder;importjava.text.SimpleDateFormat;importjava.util.HashMap;importjava.util.List;importjava.util.Map;......
  • node18 vue2启动报错 error:0308010C:digital envelope routines::unsupported
    出现原因貌似是因为是因为node17版本开始发布的OpenSSL3.0,而OpenSSL3.0对允许算法和密钥大小增加了严格的限制,可能会对生态系统造成一些影响。解决方法第一种方法降低node版本降低到17以下即可,如项目不能降低版本看后面的解决方式第二种方法设置NODE_OPTIONS环境变量......
  • python selenium报错ValueError: Timeout value connect was <...>, but it must be an
    最近学习爬虫,安装selenium,很简单地执行代码,但是一直报错。importtimeimportopenpyxlfromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeysfromselenium.webdriver.common.byimportByfromselenium.webdriver.chrome.serviceimportService......
  • Shell脚本入门
    一、Shell简介Shell脚本,就是利用Shell的命令解释的功能,对一个纯文本的文件进行解析,然后执行这些功能,也可以说Shell脚本就是一系列命令的集合。  Shell可以直接使用在win/Unix/Linux上面,并且可以调用大量系统内部的功能来解释执行程序,如果熟练掌握Shell脚本,可以让我们操作计算机......
  • js 遍历json格式数据到table中
    前端aspx文件,js把数据显示在表格中1.首先我们在前端页面写一个table代码。1<tableborder="1"id="gystable"cellpadding="0"cellspacing="0"class="frame5">2......
  • 存储过程导出EXCEL
    请参考下面代码:--创建存储过程CREATEPROCEDUREExportToExcel@TableNameNVARCHAR(128)ASBEGIN--创建临时表来存储查询结果CREATETABLE#TempTable(IDINT,Column1NVARCHAR(50),Column2NVARCHAR(50),Column3NVARCHAR(50))--执行查询并将结果插入临时表INS......
  • A RenderFlex overflowed by 483 pixels on the right.
    ARenderFlexoverflowedby483pixelsontheright.Flutter出现List<dynamic>isnotasubtypeoftypeList<String>解决方法_flutterlist<dynamic>_codekxx的博客-CSDN博客https://blog.csdn.net/codekxx/article/details/104557944 翻译搜索复制......
  • pandas操作excel表格
    点击查看代码importpandasaspdfromtqdmimporttqdmfile1=r"files/1.xls"file2=r"files/2.xls"df_File1=pd.read_excel(file1,sheet_name='keyWord',keep_default_na=False)key_column=df_File1['key'].fillna('......
  • Proj CDeepFuzz Paper Reading: Aries: Efficient Testing of Deep Neural Networks v
    Abstract背景:thedefactostandardtoassessthequalityofDNNsintheindustryistochecktheirperformance(accuracy)onacollectedsetoflabeledtestdatatestselectioncansavelaborandthenbeusedtoassessthemodel前提:themodelshouldhav......
  • Learning Auxiliary Monocular Contexts Helps Monocular 3D Object Detection (2)
    Featurebackbone采用DLA,输入维度为3×H×W的RGB图,得到维度D×h×w的特征图F,然后将特征图送入几个轻量级regressionheads,2Dboudingboxes的中心特征图用下面的模块得到:其中AN是AttentiveNormalization.用公式表示:类似的,2D和3Dboudingboxes的中心之间的offset用公......