@@ -328,34 +328,13 @@ export default {
328
328
this .zIndex = 1 ;
329
329
},
330
330
onDragenter (e ) {},
331
- getStateIndex (state ) {
332
- let indexAry = [];
333
- let parent = state .$parent ;
334
- while (parent && parent .$options .name !== " StatePage" ) {
335
- if (parent .$options .name === " ThreadSvg" ) {
336
- indexAry .push (parent .threadIndex );
337
- } else {
338
- indexAry .push (parent .index );
339
- }
340
- parent = parent .$parent ;
341
- }
342
- indexAry .push (state .index );
343
- return indexAry;
344
- },
345
331
onDrop (e ) {
346
332
// 获取从工具栏中直接拖拽下来的状态块的index,需要在stateAry添加了被拖拽的状态块的信息后获取
347
- let dropStateIndex;
348
- let stateAry = store .stateData .threadAry [this .threadIndex ].stateAry
349
- let theDragStateData = this .dragInType (e, stateAry)
350
- let traverseData = Tools .stateTraverse (
351
- stateAry,
352
- theDragStateData .stateId ,
353
- true
354
- );
355
- // 直接将state添加进被嵌套的状态中会使程序不可控,还是需要先将state添加进stateAry的最外层,再删除外层元素
356
- dropStateIndex = traverseData[1 ];
357
- theDragStateData = traverseData[0 ];
358
-
333
+ let stateAry = store .stateData .threadAry [this .threadIndex ].stateAry ;
334
+ let theDragStateData = this .dragInType (e, stateAry);
335
+ // 直接将state添加进被嵌套的状态中会使程序不可控,还是需要先将state添加进stateAry的最外层,再删除外层元素
336
+ let dropStateIndex = stateAry .length - 1 ;
337
+
359
338
if (this .stateData .stateId === theDragStateData .stateId ) {
360
339
return false ;
361
340
}
@@ -399,8 +378,9 @@ export default {
399
378
// 走到这里说明是将状态由里面移出到外面,需要冒泡到外层容器
400
379
e .stopPropagation ();
401
380
}
381
+ // 若没有嵌套在嵌套状态内的子状态,将嵌套状态变回为普通状态
402
382
if (! TargetInFlag && this .stateData .children .length <= 1 ) {
403
- this .nestToNormal (this .stateData )
383
+ this .nestToNormal (this .stateData );
404
384
}
405
385
return false ;
406
386
}
@@ -418,74 +398,63 @@ export default {
418
398
theDragStateData .y = y;
419
399
// theDragStateData.x = 0 /* - statePageVue._dragData.mousedownPoint.x */;
420
400
// theDragStateData.y = 0 /* - statePageVue._dragData.mousedownPoint.y */;
421
- this . calculateStateParent ( this .index , theDragStateData)
401
+ theDragStateData . parent = this .stateData . stateId ;
422
402
423
403
// 若状态从非嵌套变为嵌套状态,改变状态的模式与大小
424
404
if (
425
405
this .stateData .stateType === " stateDiv" &&
426
406
this .stateData .mode !== " nest"
427
407
) {
428
- this .normalToNest (this .stateData )
408
+ this .normalToNest (this .stateData );
429
409
}
430
410
431
411
this .stateData .children .push (theDragStateData);
432
412
433
- let dragTargetParentStates = stateAry;
434
- // 因为在从工具栏直接拖拽下来形成嵌套时,无法在线程框内获取拖拽下来的状态块,只能通过与拖拽下来的状态块嵌套的状态来判断被拖拽下来的状态块的index
435
- let directDropIndexAry = this .getDirectDropIndexAry (this , dropStateIndex );
413
+ let dragStateParentStates = stateAry;
414
+ // 获取在直接拖拽形成嵌套时,正在拖拽的状态父状态的索引
415
+ let directDropIndexAry = this .getdropParentIndexAry (this );
436
416
437
417
if (e .dataTransfer .getData (" operate" ) === " addState" ) {
438
- dragTargetParentStates = this .dropTraverseChildren (
418
+ dragStateParentStates = this .getDropStateParent (
439
419
directDropIndexAry,
440
- dragTargetParentStates
420
+ dragStateParentStates
441
421
);
442
422
} else {
443
- dragTargetParentStates = this .dropTraverseChildren (
444
- statePageVue ._dragData .indexAry ,
445
- dragTargetParentStates
423
+ dragStateParentStates = this .getDropStateParent (
424
+ // 去除线程索引
425
+ statePageVue ._dragData .indexAry .pop (),
426
+ dragStateParentStates
446
427
);
447
428
}
448
429
449
430
if (e .dataTransfer .getData (" operate" ) === " addState" ) {
450
431
setTimeout (() => {
451
432
// 因为从工具栏直接拖拽下来的状态块时默认添加到线程框的最外面一层的,所以需要在最外面一层进行删除
452
- stateAry .splice (directDropIndexAry . pop () , 1 );
433
+ stateAry .splice (dropStateIndex , 1 );
453
434
}, 10 );
454
435
} else {
455
436
setTimeout (() => {
456
437
// 这里必须等drog逻辑执行完以后再去删除外层元素,否则会影响到theDragStateData数据 TODO 后面开始编码后再解决这个问题,使用setTimeout会让程序不可控!!!
457
- dragTargetParentStates .splice (
438
+ dragStateParentStates .splice (
458
439
statePageVue ._dragData .indexAry .pop (),
459
440
1
460
441
);
461
442
}, 10 );
462
443
}
463
444
e .stopPropagation ();
464
445
},
465
- // 更新状态的parent属性
466
- calculateStateParent (parentIndex , theDragStateData ){
467
- theDragStateData .parent = parentIndex
468
- // 当拖动的组件为循环组件时,动态更新循环组件内children的parent
469
- if (theDragStateData .children ) {
470
- let i = 0 ;
471
- while (i < theDragStateData .children .length ) {
472
- theDragStateData .children [i].parent = this .stateData .children .length ;
473
- i++ ;
474
- }
475
- }
476
- },
477
- normalToNest (stateData ){
446
+ normalToNest (stateData ) {
478
447
stateData .mode = " nest" ;
479
448
stateData .width = " 222px" ;
480
449
stateData .height = " 120px" ;
481
450
},
482
- nestToNormal (stateData ){
451
+ nestToNormal (stateData ) {
483
452
stateData .mode = " normal" ;
484
453
stateData .width = " 76px" ;
485
454
stateData .height = " 40px" ;
486
455
},
487
- // 判断状态是从工具栏拖拽下来的还是在线程框内的移动
488
- dragInType (e , stateAry ){
456
+ // 判断状态是从工具栏拖拽下来的还是在线程框内的移动,并返回当前状态
457
+ dragInType (e , stateAry ) {
489
458
let theDragStateData;
490
459
if (e .dataTransfer .getData (" operate" ) === " addState" ) {
491
460
let threadPosInfo = e .target .getBoundingClientRect ();
@@ -496,43 +465,35 @@ export default {
496
465
stateType: e .dataTransfer .getData (" stateType" ),
497
466
};
498
467
499
- theDragStateData = store .getDefaultStateCfg (data);
500
- stateAry .push (theDragStateData);
468
+ let stateDataToAdd = store .getDefaultStateCfg (data);
469
+ stateAry .push (stateDataToAdd);
470
+ theDragStateData = stateAry[stateAry .length - 1 ];
501
471
e .stopPropagation ();
502
472
} else {
503
473
theDragStateData = JSON .parse (
504
474
e .dataTransfer .getData (" theDragStateData" )
505
475
);
506
476
}
507
- return theDragStateData
477
+ return theDragStateData;
508
478
},
509
- // 用于判断在drop时将被drop的状态块添加为哪个状态块的children
510
- dropTraverseChildren (indexAry , parentStateAry ) {
511
- indexAry .pop (); // 除去线程索引
512
- while (indexAry && indexAry .length > 1 ) {
513
- let i = indexAry .pop ();
514
- parentStateAry = parentStateAry[i].children ;
479
+ // 获取当前拖拽状态的父状态在当前线程框内的索引
480
+ getdropParentIndexAry (state ) {
481
+ let indexAry = [];
482
+ let parent = state .$parent ;
483
+ while (parent && parent .$options .name !== " StatePage" ) {
484
+ if (parent .$options .name !== " ThreadSvg" ) {
485
+ indexAry .push (parent .index );
486
+ }
487
+ parent = parent .$parent ;
515
488
}
516
- return parentStateAry ;
489
+ return indexAry . reverse () ;
517
490
},
518
491
519
- // 用于获取从工具栏中直接拖拽下来的状态块的indexAry
520
- getDirectDropIndexAry (dropTarget , dropStateIndex ) {
521
- let directDropIndexAry = this .getStateIndex (dropTarget);
522
- // 除去与被拖拽下来的状态块的状态块本身的index,并将添加下来的状态块的index推进directDropIndexAry
523
- directDropIndexAry .pop ();
524
- directDropIndexAry .push (dropStateIndex);
525
- // 为寻找对应的形成嵌套的状态块以及删除多余的被拖拽下来的状态块的快照,需要将形成的directDropIndexAry进行reverse
526
- directDropIndexAry .reverse ();
527
- return directDropIndexAry;
528
- },
529
- // 用于判断在drop时将被drop的状态块添加为哪个状态块的children
530
- dropTraverseChildren (indexAry , parentStateAry ) {
531
- indexAry .pop (); // 除去线程索引
492
+ // 用于判断在drop时将drop的状态块添加为哪个状态块的children
493
+ getDropStateParent (indexAry , parentStateAry ) {
532
494
while (indexAry && indexAry .length > 1 ) {
533
495
let i = indexAry .pop ();
534
496
parentStateAry = parentStateAry[i].children ;
535
- console .log (parentStateAry);
536
497
}
537
498
return parentStateAry;
538
499
},
@@ -786,9 +747,9 @@ export default {
786
747
top : 0 ;
787
748
left : 0 ;
788
749
display : inline-block ;
789
- & .is-auto-layouting {
750
+ & .is-auto-layouting {
790
751
transition : all 1s ;
791
- }
752
+ }
792
753
/* background-color: rgba(50, 50, 50, 0.62); */
793
754
}
794
755
0 commit comments