@@ -685,14 +685,11 @@ export default {
685685 // 向jsonData中更新数据
686686 } else if (addCell .edge ) {
687687 console .log (addCell)
688+ let lineObj = _ .pick (addCell, [' id' , ' edge' , ' source' , ' parent' , ' geometry' , ' value' ]);
689+ this .jsonData [' edges' ].push (lineObj);
688690 this .$message .info (' 添加了一条线' );
689691 }
690692 })
691- // console.log('mxEvent', mxEvent);
692- // this.$nextTick(() => {
693- // let addCell = evt.properties.cells[0];
694- // addCell.parent.id === '1' ? this.$message.success(`新增${addCell.title ? addCell.title : '箭头'}节点成功`) : (addCell.parent.id.includes('group') && this.$message.success(`${addCell.title}节点进入${addCell.parent.title}成功`));
695- // });
696693 });
697694
698695 // 拖动节点的事件
@@ -710,11 +707,24 @@ export default {
710707 this .graph .addListener (mxEvent .CELLS_REMOVED , (sender , evt ) => {
711708 this .$nextTick (() => {
712709 let removeCells = evt .properties .cells ;
713- let cellsName = [];
710+ console . log (removeCells, ' removeCells ' )
714711 removeCells .forEach (item => {
715- cellsName .push (item .title );
712+ // 拿每一个cellId在jsonData中进行遍历,并进行移除
713+ if (item .vertex ) {
714+ // 判断是否为组节点
715+ if (item .isGroup ) {
716+ this .$message .info (` 移除了${ item .id } 组` );
717+ this .jsonData [' cells' ][' groups' ].splice (this .jsonData [' cells' ][' groups' ].findIndex (jsonItem => { return jsonItem .id === item .id }), 1 )
718+ } else {
719+ this .$message .info (` 移除${ item .id } 节点` );
720+ this .jsonData [' cells' ][' nodes' ].splice (this .jsonData [' cells' ][' nodes' ].findIndex (jsonItem => { return jsonItem .id === item .id }), 1 )
721+ }
722+ } else if (item .edge ) {
723+ this .$message .info (' 移除了线' );
724+ this .jsonData [' edges' ].splice (this .jsonData [' edges' ].findIndex (jsonItem => { return jsonItem .id === item .id }), 1 )
725+ }
726+ // this.jsonData.forEach(item)
716727 });
717- this .$message .success (` 移除${ [... cellsName]} 节点成功` );
718728 });
719729 });
720730
@@ -792,8 +802,7 @@ export default {
792802 this .keyHandler = new mxKeyHandler (this .graph );
793803 // 键盘按下删除键绑定事件
794804 this .keyHandler .bindKey (46 , () => {
795- const cells = this .graph .getSelectionCells () || [];
796- this .graph .removeCells (cells, true );
805+ this .deleteNode ()
797806 });
798807 this .keyHandler .bindControlKey (65 , () => {
799808 this .graph .selectAll ();
@@ -813,7 +822,6 @@ export default {
813822 this .keyHandler .bindControlKey (90 , () => {
814823 this .goBack ();
815824 });
816-
817825 },
818826 // 配置右键菜单栏
819827 configMenu () {
@@ -1107,7 +1115,8 @@ export default {
11071115
11081116 // 删除节点
11091117 deleteNode () {
1110- this .graph .removeCells ();
1118+ var cells = this .graph .getSelectionCells ();
1119+ this .graph .removeCells ([... cells]);
11111120 },
11121121
11131122 // 修改连线样式
@@ -1439,14 +1448,14 @@ export default {
14391448 this .createGraph ();
14401449 this .eventCenter ();
14411450 this .configMouseEvent ();
1442- this .configKeyEvent ();
14431451 this .configMenu ();
14441452 this .addStencilPalette (' 箭头组' , ' arrows' , path .join (' ./stencil/arrows.xml' ));
14451453 this .$nextTick (() => {
14461454 this .initCustomToolbar ();
14471455 this .initGeneralTool ();
14481456 this .initStencilToolBar ();
14491457 this .makeToolbarDraggable ();
1458+ this .configKeyEvent ();
14501459 });
14511460 }
14521461 },
@@ -1601,9 +1610,9 @@ export default {
16011610 .json-viewer {
16021611 overflow : auto ;
16031612 position : absolute ;
1604- top : 60 % ;
1613+ top : 30 % ;
16051614 width : 260px ;
1606- height : 800 px ;
1615+ height : 70 % ;
16071616 bottom : 0 ;
16081617 right : 0 ;
16091618 }
0 commit comments