Skip to content

Commit c16c4f4

Browse files
committed
refactor: dashboard resize position
1 parent 99671b8 commit c16c4f4

File tree

1 file changed

+77
-12
lines changed

1 file changed

+77
-12
lines changed

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

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ function resizePlayer(item: CanvasItem, newSize: any) {
270270
fillPositionBox(item.y + item.sizeY)
271271
}
272272
273+
// Move the current item
274+
item.x = newSize.x
275+
item.y = newSize.y
276+
273277
emptyTargetCell(item)
274278
addItemToPositionBox(item)
275279
changeItemCoord(item)
@@ -659,6 +663,68 @@ function containerMouseDown(e: MouseEvent) {
659663
infoBox.value.startY = e.pageY
660664
}
661665
666+
function getNowPosition(addSizeX: number, addSizeY: number) {
667+
const point = infoBox.value.point
668+
const hasT = /t/.test(point)
669+
const hasB = /b/.test(point)
670+
const hasL = /l/.test(point)
671+
const hasR = /r/.test(point)
672+
// 根据坐标点 判断resize方向
673+
let nowSizeX = infoBox.value.oldSizeX
674+
let nowSizeY = infoBox.value.oldSizeY
675+
let nowX = infoBox.value.oldX
676+
let nowY = infoBox.value.oldY
677+
if (hasR) {
678+
nowSizeX = Math.max(nowSizeX + addSizeX, 1)
679+
}
680+
if (hasB) {
681+
nowSizeY = Math.max(nowSizeY + addSizeY, 1)
682+
}
683+
684+
if (hasL) {
685+
nowSizeX = Math.max(nowSizeX - addSizeX, 1)
686+
nowX = Math.max(nowX + addSizeX, 1)
687+
}
688+
689+
if (hasT) {
690+
nowSizeY = Math.max(nowSizeY - addSizeY, 1)
691+
nowY = Math.max(nowY + addSizeY, 1)
692+
}
693+
return {nowSizeX, nowSizeY, nowX, nowY}
694+
}
695+
696+
697+
function getNowClonePosition(moveXSize: number, moveYSize: number) {
698+
const point = infoBox.value.point
699+
const hasT = /t/.test(point)
700+
const hasB = /b/.test(point)
701+
const hasL = /l/.test(point)
702+
const hasR = /r/.test(point)
703+
// 根据坐标点 判断resize方向
704+
let nowOriginWidth = infoBox.value.originWidth
705+
let nowOriginHeight = infoBox.value.originHeight
706+
let nowOriginX = infoBox.value.originX
707+
let nowOriginY = infoBox.value.originY
708+
if (hasR) {
709+
nowOriginWidth = Math.max(nowOriginWidth + moveXSize, baseWidth.value)
710+
}
711+
if (hasB) {
712+
nowOriginHeight = Math.max(nowOriginHeight + moveYSize, baseHeight.value)
713+
}
714+
715+
if (hasL) {
716+
nowOriginWidth = Math.max(nowOriginWidth - moveXSize, baseWidth.value)
717+
nowOriginX = Math.max(nowOriginX + moveXSize, 1)
718+
}
719+
720+
if (hasT) {
721+
nowOriginHeight = Math.max(nowOriginHeight - moveYSize, baseHeight.value)
722+
nowOriginY = Math.max(nowOriginY + moveYSize, 1)
723+
}
724+
return {nowOriginWidth, nowOriginHeight, nowOriginX, nowOriginY}
725+
}
726+
727+
662728
function startMove(e: MouseEvent, item: CanvasItem, index: number) {
663729
if (!draggable.value) return
664730
dashboardStore.setCurComponent(item)
@@ -729,22 +795,21 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
729795
: parseInt(String(moveXSize / cellWidth.value))
730796
731797
const addSizeY =
732-
moveYSize % cellHeight.value > cellHeight.value / 4
733-
? parseInt(String(moveYSize / cellHeight.value + 1))
734-
: parseInt(String(moveYSize / cellHeight.value))
735-
736-
const nowX = Math.max(infoBox.value.oldSizeX + addSizeX, 1)
737-
const nowY = Math.max(infoBox.value.oldSizeY + addSizeY, 1)
798+
moveYSize % cellHeight.value > cellHeight.value / 4
799+
? parseInt(String(moveYSize / cellHeight.value + 1))
800+
: parseInt(String(moveYSize / cellHeight.value))
801+
// 根据坐标点 判断resize方向
802+
const {nowSizeX, nowSizeY, nowX, nowY} = getNowPosition(addSizeX, addSizeY)
738803
739804
debounce(() => {
740-
resizePlayer(resizeItem, {sizeX: nowX, sizeY: nowY})
805+
resizePlayer(resizeItem, {sizeX: nowSizeX, sizeY: nowSizeY, x: nowX, y: nowY})
741806
}, 10)
742807
743-
const nowWidth = Math.max(infoBox.value.originWidth + moveXSize, baseWidth.value)
744-
const nowHeight = Math.max(infoBox.value.originHeight + moveYSize, baseHeight.value)
745-
746-
infoBox.value.cloneItem.style.width = `${nowWidth}px`
747-
infoBox.value.cloneItem.style.height = `${nowHeight}px`
808+
const {nowOriginWidth, nowOriginHeight, nowOriginX, nowOriginY} = getNowClonePosition(moveXSize, moveYSize)
809+
infoBox.value.cloneItem.style.width = `${nowOriginWidth}px`
810+
infoBox.value.cloneItem.style.height = `${nowOriginHeight}px`
811+
infoBox.value.cloneItem.style.left = `${nowOriginX}px`
812+
infoBox.value.cloneItem.style.top = `${nowOriginY}px`
748813
} else if (moveItem) {
749814
scrollScreen(e)
750815
if (!draggable.value) return

0 commit comments

Comments
 (0)