@@ -8,6 +8,7 @@ import {findComponent} from "@/views/dashboard/components/component-list.ts";
88
99const dashboardStore = dashboardStoreWithOut ()
1010const canvasLocked = ref (false ) // Is the canvas movement locked, Default false
11+ const emits = defineEmits ([" parentAddItemBox" ]);
1112// @ts-ignore
1213let currentInstance
1314// Props
@@ -400,11 +401,26 @@ function removeItem(index: number) {
400401 canvasComponentData .value .splice (index , 1 )
401402}
402403
404+ function getNextDragId() {
405+ if (! canvasComponentData .value || canvasComponentData .value .length === 0 ) {
406+ return 0 ;
407+ }
408+ // @ts-ignore
409+ const validIds = canvasComponentData .value .map (item => item ._dragId ).filter (id => id != null && id !== ' ' ); // 过滤 null、undefined 和空字符串
410+
411+ if (validIds .length === 0 ) {
412+ return 0 ;
413+ }
414+ // @ts-ignore
415+ const maxDragId = Math .max (... validIds );
416+ return maxDragId + 1 ;
417+ }
418+
403419function addItem(item : CanvasItem , index : any ) {
404420 if (index < 0 ) {
405421 index = canvasComponentData .value .length
406422 }
407- item ._dragId = index
423+ item ._dragId = getNextDragId ()
408424 checkItemPosition (item , {x: item .x , y: item .y })
409425 emptyTargetCell (item )
410426 addItemToPositionBox (item )
@@ -899,15 +915,25 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
899915 if (canvasLocked .value ) {
900916 const moveItem = infoBox .value .moveItem
901917 // Get the SQTab currently being moved in
902- const curActiveSQTab = canvasComponentData ?.value .find (item => item .component === ' SQTab' && item .moveInActive === true );
903- if (curActiveSQTab ) {
904- // @ts-ignore
905- const refTabInstance = currentInstance .refs [' shape_component_' + curActiveSQTab .id ][0 ]
906- refTabInstance .addTabItem (moveItem )
918+ const curActiveMoveInSQTab = canvasComponentData ?.value .find (item => item .component === ' SQTab' && item .collisionActive === true );
919+ if (curActiveMoveInSQTab ) {
920+ if (curActiveMoveInSQTab .moveInActive ) {
921+ // @ts-ignore
922+ const refTabInstance = currentInstance .refs [' shape_component_' + curActiveMoveInSQTab .id ][0 ]
923+ refTabInstance .addTabItem (moveItem )
924+ removeItemById (moveItem .id )
925+ }
926+ curActiveMoveInSQTab .collisionActive = false
927+ curActiveMoveInSQTab .moveInActive = false
928+ }
929+
930+ // move out
931+ if (props .parentConfigItem && props .parentConfigItem .moveOutActive ) {
932+ emits (' parentAddItemBox' , _ .cloneDeep (moveItem ))
907933 removeItemById (moveItem .id )
908- curActiveSQTab .collisionActive = false
909- curActiveSQTab .moveInActive = false
934+ props .parentConfigItem .moveOutActive = false
910935 }
936+
911937 }
912938 canvasLocked .value = false
913939 }
@@ -1045,6 +1071,7 @@ function tabMoveOutCheckSQ() {
10451071 const top = cloneItem .offsetTop
10461072 const {tw} = getItemStylePosition (props .parentConfigItem )
10471073 props .parentConfigItem .moveOutActive = left < - tabMoveOutXOffset || top < - tabMoveOutYOffset || (left + width - tw ) > tabMoveOutXOffset ;
1074+ canvasLocked .value = props .parentConfigItem .moveOutActive
10481075 }
10491076}
10501077
@@ -1135,7 +1162,8 @@ defineExpose({
11351162 <component :ref =" 'shape_component_'+item.id"
11361163 class =" sql-component slot-component dragHandle"
11371164 :is =" findComponent(item.component)"
1138- :config-item =" item" >
1165+ :config-item =" item"
1166+ @parentAddItemBox =" (subItem:any) => addItemBox(subItem)" >
11391167 </component >
11401168 </CanvasShape >
11411169 </template >
0 commit comments