Skip to content

Commit 0d4e680

Browse files
committed
refactor: dashboard
1 parent 76bff9c commit 0d4e680

File tree

3 files changed

+49
-61
lines changed

3 files changed

+49
-61
lines changed

frontend/src/router/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Layout from '@/components/layout/index.vue'
44
import login from '@/views/login/index.vue'
55
import chat from '@/views/chat/index.vue'
66
import ds from '@/views/ds/index.vue'
7-
import dashboard from '@/views/dashboard/index.vue'
87
import DashboardEditor from '@/views/dashboard/DashboardEditor.vue'
98
import setting from '@/views/setting/index.vue'
109
import { watchRouter } from './watch'

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ const props = defineProps({
2020
type: Boolean,
2121
required: true
2222
},
23-
baseWidth: {
24-
type: Number,
25-
default: 100
26-
},
27-
baseHeight: {
28-
type: Number,
29-
default: 50
30-
},
31-
baseMarginLeft: {
32-
type: Number,
33-
default: 20
34-
},
35-
baseMarginTop: {
36-
type: Number,
37-
default: 20
38-
},
3923
startMove: {
4024
type: Function,
4125
default: () => {
@@ -51,11 +35,7 @@ const props = defineProps({
5135
})
5236
5337
const {
54-
baseWidth,
55-
baseHeight,
56-
baseMarginLeft,
57-
baseMarginTop,
58-
draggable,
38+
draggable
5939
} = toRefs(props)
6040
6141
const cursors = {
@@ -116,7 +96,7 @@ const pointList = ['lt', 't', 'rt', 'r', 'rb', 'b', 'lb', 'l']
11696
canNotDrag: !draggable
11797
}" @mousedown="startMove($event, configItem, itemIndex)" ref="shapeRef">
11898
<slot></slot>
119-
<div v-for="point in pointList" :key="point" class="resizeHandle" :style="getPointStyle(point, configItem)"
99+
<div v-for="point in pointList" :key="point" class="resizeHandle" :style="getPointStyle(point)"
120100
@mousedown="startResize($event, point, configItem, itemIndex)"></div>
121101
</div>
122102
</template>

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

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script setup lang="ts">
2-
import { ref, nextTick, toRefs, type PropType } from 'vue'
2+
import {ref, nextTick, toRefs, type PropType} from 'vue'
33
import _ 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'
66
import CanvasShape from './CanvasShape.vue'
7+
78
const dashboardStore = dashboardStoreWithOut()
89
910
@@ -105,6 +106,7 @@ let itemMaxX = 0
105106
let itemMaxY = 0
106107
107108
const moveTime = 80
109+
108110
function 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+
173176
function 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
631637
function 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
645653
function 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() {
840848
function getRenderState() {
841849
return moveAnimate.value
842850
}
851+
843852
// @ts-ignore
844853
function 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

Comments
 (0)