Skip to content

Commit 67d00f4

Browse files
committed
refactor: move gap
1 parent b1f7eeb commit 67d00f4

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

frontend/src/views/dashboard/canvas/CanvasCore.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,19 @@ function getNowPosition(addSizeX: number, addSizeY: number, moveXSize: number, m
801801
return { nowSizeX, nowSizeY, nowX, nowY, nowOriginWidth, nowOriginHeight, nowOriginX, nowOriginY }
802802
}
803803
804+
function checkStartMove() {
805+
const cloneItem = infoBox.value.cloneItem
806+
const nowItemNode = infoBox.value.nowItemNode
807+
const offsetX = cellWidth.value * 2
808+
const offsetY = cellHeight.value * 2
809+
if (cloneItem && nowItemNode) {
810+
const xGap = Math.abs(cloneItem.offsetLeft - nowItemNode.offsetLeft)
811+
const yGap = Math.abs(cloneItem.offsetTop - nowItemNode.offsetTop)
812+
return xGap > offsetX || yGap > offsetY
813+
}
814+
return false
815+
}
816+
804817
function startMove(e: MouseEvent, item: CanvasItem, index: number) {
805818
canvasLocked.value = false // Reset canvas lock status
806819
if (!draggable.value) return
@@ -920,9 +933,13 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
920933
921934
//If the current canvas is locked, no component movement will be performed
922935
if (canvasLocked.value) return
936+
if (!checkStartMove()) {
937+
return
938+
}
939+
923940
// Adjust the accuracy of moving coordinate changes
924-
let newX = Math.floor(nowCloneItemX / cellWidth.value)
925-
let newY = Math.floor(nowCloneItemY / cellHeight.value)
941+
let newX = Math.round(nowCloneItemX / cellWidth.value)
942+
let newY = Math.round(nowCloneItemY / cellHeight.value)
926943
newX = newX > 0 ? newX : 1
927944
newY = newY > 0 ? newY : 1
928945
debounce(() => {

0 commit comments

Comments
 (0)