11<script setup lang="ts">
2- import { ref , nextTick , toRefs , type PropType } from ' vue'
2+ import {ref , nextTick , toRefs , type PropType } from ' vue'
33import _ from ' lodash'
4- import { dashboardStoreWithOut } from ' @/stores/dashboard/dashboard'
5- import { type CanvasCoord , type CanvasItem } from ' ../utils/CanvasUtils'
4+ import {dashboardStoreWithOut } from ' @/stores/dashboard/dashboard'
5+ import {type CanvasCoord , type CanvasItem } from ' ../utils/CanvasUtils'
66import CanvasShape from ' ./CanvasShape.vue'
7+
78const dashboardStore = dashboardStoreWithOut ()
89
910
@@ -105,6 +106,7 @@ let itemMaxX = 0
105106let itemMaxY = 0
106107
107108const moveTime = 80
109+
108110function debounce(func : () => void , time : number ) {
109111 if (! isOverlay ) {
110112 isOverlay = true
@@ -145,7 +147,7 @@ function resetPositionBox() {
145147 for (let i = 0 ; i < rows ; i ++ ) {
146148 const row = []
147149 for (let j = 0 ; j < maxCell .value ; j ++ ) {
148- row .push ({ el: false })
150+ row .push ({el: false })
149151 }
150152 positionBox .value .push (row )
151153 }
@@ -170,14 +172,15 @@ function addItemToPositionBox(item: CanvasItem) {
170172 }
171173 }
172174}
175+
173176function fillPositionBox(maxY : number ) {
174177 const pb = positionBox .value
175178 maxY += 2
176179 for (let j = 0 ; j < maxY ; j ++ ) {
177180 if (pb [j ] === undefined ) {
178181 const row = []
179182 for (let i = 0 ; i < itemMaxX ; i ++ ) {
180- row .push ({ el: false })
183+ row .push ({el: false })
181184 }
182185 pb .push (row )
183186 }
@@ -366,7 +369,7 @@ function addItem(item: CanvasItem, index: any) {
366369 index = canvasComponentData .value .length
367370 }
368371 item ._dragId = index
369- checkItemPosition (item , { x: item .x , y: item .y })
372+ checkItemPosition (item , {x: item .x , y: item .y })
370373 emptyTargetCell (item )
371374 addItemToPositionBox (item )
372375 const canGoUpRows = canItemGoUp (item )
@@ -403,16 +406,16 @@ function findClosetCoords(item: CanvasItem, tCoord: CanvasCoord) {
403406 }
404407 // Determine whether a collision has occurred
405408 if (
406- tCoord .x2 < nowCoord .x1 ||
407- tCoord .x1 > nowCoord .x2 ||
408- tCoord .y2 < nowCoord .y1 ||
409- tCoord .y1 > nowCoord .y2
409+ tCoord .x2 < nowCoord .x1 ||
410+ tCoord .x1 > nowCoord .x2 ||
411+ tCoord .y2 < nowCoord .y1 ||
412+ tCoord .y1 > nowCoord .y2
410413 ) {
411414 return
412415 } else {
413416 collisionsItem .push ({
414417 centerDistance: Math .sqrt (
415- Math .pow (tCoord .c1 - nowCoord .c1 , 2 ) + Math .pow (tCoord .c2 - nowCoord .c2 , 2 )
418+ Math .pow (tCoord .c1 - nowCoord .c1 , 2 ) + Math .pow (tCoord .c2 - nowCoord .c2 , 2 )
416419 ),
417420 coord: nowCoord
418421 })
@@ -432,6 +435,7 @@ function findClosetCoords(item: CanvasItem, tCoord: CanvasCoord) {
432435 isOverlay = false
433436 }, 200 )
434437}
438+
435439/**
436440 * Generate coordinates
437441 * @param {CanvasItem} item : The item object to generate coordinates for
@@ -481,6 +485,7 @@ function changeItemCoord(item: CanvasItem) {
481485 coordinates .value .splice (index , 1 , coord )
482486 }
483487}
488+
484489/**
485490 * Clear the elements at the target location
486491 * @param {any} item Target item
@@ -506,9 +511,9 @@ function canItemGoUp(item: CanvasItem) {
506511 for (let row = item .y - 2 ; row >= 0 ; row -- ) {
507512 for (let cell = item .x - 1 ; cell < item .x - 1 + item .sizeX ; cell ++ ) {
508513 if (
509- positionBox .value [row ] &&
510- positionBox .value [row ][cell ] &&
511- positionBox .value [row ][cell ].el
514+ positionBox .value [row ] &&
515+ positionBox .value [row ][cell ] &&
516+ positionBox .value [row ][cell ].el
512517 ) {
513518 return upperRows
514519 }
@@ -627,6 +632,7 @@ function findBelowItems(item: CanvasItem) {
627632
628633 return _ .sortBy (Object .values (belowItems ), ' y' )
629634}
635+
630636// @ts-ignore
631637function startResize(e : MouseEvent , point : string , item : CanvasItem , index : number ) {
632638 if (! resizable .value ) return
@@ -640,6 +646,8 @@ function startResize(e: MouseEvent, point: string, item: CanvasItem, index: numb
640646 // Get the parent element of. tem
641647 infoBox .value .resizeItem = item
642648 infoBox .value .resizeItemIndex = index
649+ // Drag and drop coordinate points
650+ infoBox .value .point = point
643651}
644652
645653function containerMouseDown(e : MouseEvent ) {
@@ -663,9 +671,9 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
663671 let className = target .className || ' '
664672
665673 if (
666- ! className .includes (' dragHandle' ) &&
667- ! className .includes (' item' ) &&
668- ! className .includes (' resizeHandle' )
674+ ! className .includes (' dragHandle' ) &&
675+ ! className .includes (' item' ) &&
676+ ! className .includes (' resizeHandle' )
669677 ) {
670678 return
671679 }
@@ -716,9 +724,9 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
716724 const moveYSize = e .pageY - infoBox .value .startY
717725
718726 const addSizeX =
719- moveXSize % cellWidth .value > cellWidth .value / 4
720- ? parseInt (String (moveXSize / cellWidth .value + 1 ))
721- : parseInt (String (moveXSize / cellWidth .value ))
727+ moveXSize % cellWidth .value > cellWidth .value / 4
728+ ? parseInt (String (moveXSize / cellWidth .value + 1 ))
729+ : parseInt (String (moveXSize / cellWidth .value ))
722730
723731 const addSizeY =
724732 moveYSize % cellHeight .value > cellHeight .value / 4
@@ -729,7 +737,7 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
729737 const nowY = Math .max (infoBox .value .oldSizeY + addSizeY , 1 )
730738
731739 debounce (() => {
732- resizePlayer (resizeItem , { sizeX: nowX , sizeY: nowY })
740+ resizePlayer (resizeItem , {sizeX: nowX , sizeY: nowY })
733741 }, 10 )
734742
735743 const nowWidth = Math .max (infoBox .value .originWidth + moveXSize , baseWidth .value )
@@ -751,26 +759,26 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
751759
752760 // Adjust the accuracy of moving coordinate changes
753761 const newX = Math .max (
754- Math .floor (
755- (nowCloneItemX + infoBox .value .cloneItem .offsetWidth / 24 - baseMarginLeft .value ) /
756- cellWidth .value +
762+ Math .floor (
763+ (nowCloneItemX + infoBox .value .cloneItem .offsetWidth / 24 - baseMarginLeft .value ) /
764+ cellWidth .value +
765+ 1
766+ ),
757767 1
758- ),
759- 1
760768 )
761769 // Adjust the accuracy of moving coordinate changes
762770 const newY = Math .max (
763- Math .floor (
764- (nowCloneItemY + infoBox .value .cloneItem .offsetHeight / 24 - baseMarginTop .value ) /
765- cellHeight .value +
771+ Math .floor (
772+ (nowCloneItemY + infoBox .value .cloneItem .offsetHeight / 24 - baseMarginTop .value ) /
773+ cellHeight .value +
774+ 1
775+ ),
766776 1
767- ),
768- 1
769777 )
770778
771779 debounce (() => {
772780 if (newX !== infoBox .value .oldX || newY !== infoBox .value .oldY ) {
773- movePlayer (moveItem , { x: newX , y: newY })
781+ movePlayer (moveItem , {x: newX , y: newY })
774782 infoBox .value .oldX = newX
775783 infoBox .value .oldY = newY
776784 }
@@ -840,6 +848,7 @@ function getMaxCell() {
840848function getRenderState() {
841849 return moveAnimate .value
842850}
851+
843852// @ts-ignore
844853function afterInitOk(func ) {
845854 let timeId = setInterval (() => {
@@ -884,13 +893,13 @@ defineExpose({
884893
885894<template >
886895 <div class =" dragAndResize" ref =" containerRef" @mousedown =" containerMouseDown($event)" @mouseup =" endMove()"
887- @mousemove =" moving()" >
896+ @mousemove =" moving()" >
888897 <div v-if =" renderOk" >
889- <CanvasShape v-for =" (item, index) in canvasComponentData" :config-item =" item" :draggable =" draggable" :item-index = " index "
890- :move-animate = " moveAnimate " :start-move = " startMove " :start-resize = " startResize " :key = " 'item' + index"
891- :base-height = " baseHeight " :base-width = " baseWidth " :base-margin-left = " baseMarginLeft " :base-margin-top = " baseMarginTop "
892- :style =" nowItemStyle(item)" >
893- <!-- {{ item }}-->
898+ <CanvasShape v-for =" (item, index) in canvasComponentData" :config-item =" item" :draggable =" draggable"
899+ :item-index = " index"
900+ :move-animate = " moveAnimate " :start-move = " startMove " :start-resize = " startResize " :key = " 'item' + index "
901+ :style =" nowItemStyle(item)" >
902+ <!-- {{ item }}-->
894903 </CanvasShape >
895904 </div >
896905 </div >
0 commit comments