Skip to content

Commit 2dc1ead

Browse files
committed
feat: dashboard
1 parent fdc6874 commit 2dc1ead

File tree

5 files changed

+123
-48
lines changed

5 files changed

+123
-48
lines changed

frontend/components.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ declare module 'vue' {
1111
ElAvatar: typeof import('element-plus/es')['ElAvatar']
1212
ElButton: typeof import('element-plus/es')['ElButton']
1313
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
14-
ElCol: typeof import('element-plus/es')['ElCol']
1514
ElDialog: typeof import('element-plus/es')['ElDialog']
1615
ElDrawer: typeof import('element-plus/es')['ElDrawer']
1716
ElDropdown: typeof import('element-plus/es')['ElDropdown']
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineStore } from 'pinia'
2+
3+
export const useDashboardStore = defineStore('dashboardStore', {
4+
state: () => {
5+
return {
6+
curComponent: null
7+
}
8+
},
9+
getters: {
10+
getCurComponent(): any {
11+
return this.curComponent
12+
}
13+
},
14+
actions: {
15+
setCurComponent(value: any) {
16+
this.curComponent = value
17+
}
18+
}
19+
})

frontend/src/views/dashboard/PreviewDashboard.vue

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,46 @@ const baseWidth = ref(0)
66
const baseHeight = ref(0)
77
const baseMarginLeft = ref(0)
88
const baseMarginTop = ref(0)
9+
const baseMatrixCount = {
10+
x: 72,
11+
y: 36
12+
}
913
const componentData = ref([
1014
{
1115
id: 4,
1216
x: 1,
1317
y: 1,
14-
sizeX: 2,
15-
sizeY: 2,
18+
sizeX: 20,
19+
sizeY: 10,
1620
_dragId: 0
1721
},
1822
{
1923
id: 10,
2024
x: 2,
2125
y: 1,
22-
sizeX: 2,
23-
sizeY: 2,
26+
sizeX: 20,
27+
sizeY: 10,
2428
_dragId: 1
2529
},
2630
{
2731
id: 7,
2832
x: 1,
2933
y: 2,
30-
sizeX: 2,
31-
sizeY: 3,
34+
sizeX: 20,
35+
sizeY: 10,
3236
_dragId: 2
3337
}
3438
])
3539
3640
onMounted(() => {
3741
const screenWidth = window.innerWidth
3842
const screenHeight = window.innerHeight
39-
baseWidth.value = 90.8333 * (screenWidth / 1366)
40-
baseHeight.value = 100 * (screenHeight / 638)
41-
baseMarginLeft.value = 20 * (screenWidth / 1366)
42-
baseMarginTop.value = 20 * (screenHeight / 638)
43+
baseMarginLeft.value = 10
44+
baseMarginTop.value = 10
45+
46+
baseWidth.value = (screenWidth - baseMarginLeft.value) / baseMatrixCount.x - baseMarginLeft.value
47+
baseHeight.value = (screenHeight - baseMarginTop.value) / baseMatrixCount.y - baseMarginTop.value
48+
4349
nextTick(() => {
4450
if (cyGridster.value) {
4551
// @ts-ignore
@@ -50,7 +56,14 @@ onMounted(() => {
5056
</script>
5157

5258
<template>
53-
<DsCanvasCore ref="cyGridster" :canvas-component-data="componentData"></DsCanvasCore>
59+
<DsCanvasCore
60+
ref="cyGridster"
61+
:base-width="baseWidth"
62+
:base-height="baseHeight"
63+
:base-margin-left="baseMarginLeft"
64+
:base-margin-top="baseMarginTop"
65+
:canvas-component-data="componentData"
66+
></DsCanvasCore>
5467
</template>
5568

5669
<style scoped lang="less"></style>

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

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ const props = defineProps({
6969
}
7070
})
7171
72+
const {
73+
canvasComponentData,
74+
baseWidth,
75+
baseHeight,
76+
baseMarginLeft,
77+
baseMarginTop,
78+
draggable,
79+
resizable
80+
} = toRefs(props)
81+
7282
type Coord = {
7383
x1: number
7484
y1: number
@@ -94,17 +104,6 @@ type Item = {
94104
sizeY: number
95105
[key: string]: any
96106
}
97-
98-
const {
99-
canvasComponentData,
100-
baseWidth,
101-
baseHeight,
102-
baseMarginLeft,
103-
baseMarginTop,
104-
draggable,
105-
resizable
106-
} = toRefs(props)
107-
108107
// DOM ref
109108
const containerRef = ref<HTMLElement | null>(null)
110109
const renderOk = ref(false)
@@ -115,6 +114,17 @@ const maxCell = ref(0)
115114
const positionBox = ref<Array<Array<{ el: boolean }>>>([])
116115
const coordinates = ref<Coord[]>([])
117116
const infoBox = ref()
117+
const pointList = ['lt', 't', 'rt', 'r', 'rb', 'b', 'lb', 'l']
118+
const cursors = {
119+
lt: 'nw',
120+
t: 'n',
121+
rt: 'ne',
122+
r: 'e',
123+
rb: 'se',
124+
b: 's',
125+
lb: 'sw',
126+
l: 'w'
127+
}
118128
119129
// Position data (non-reactive)
120130
@@ -452,9 +462,9 @@ function findClosetCoords(item: { _dragId: string | number }, tCoord: Coord) {
452462
}
453463
/**
454464
* Generate coordinates
455-
* @param {Item} item: The item object to generate coordinates for
465+
* @param {any} item: The item object to generate coordinates for
456466
*/
457-
function makeCoordinate(item: Item) {
467+
function makeCoordinate(item: any) {
458468
let width = cellWidth.value * item.sizeX - baseMarginLeft.value
459469
let height = cellHeight.value * item.sizeY - baseMarginTop.value
460470
let left = cellWidth.value * (item.x - 1) + baseMarginLeft.value
@@ -645,8 +655,8 @@ function findBelowItems(item: Item) {
645655
646656
return _.sortBy(Object.values(belowItems), 'y')
647657
}
648-
649-
function startResize(e: MouseEvent, item: Item, index: number) {
658+
// @ts-ignore
659+
function startResize(e: MouseEvent, point: string, item: Item, index: number) {
650660
if (!resizable.value) return
651661
props.resizeStart(e, item, index)
652662
@@ -707,7 +717,6 @@ function startMove(e: MouseEvent, item: Item, index: number) {
707717
infoBox.value.nowItemNode = target.closest('.item')
708718
infoBox.value.cloneItem = infoBox.value.nowItemNode.cloneNode(true)
709719
}
710-
711720
infoBox.value.cloneItem.classList.add('cloneNode')
712721
if( containerRef.value ){
713722
containerRef.value.append(infoBox.value.cloneItem)
@@ -882,6 +891,46 @@ function moving() {
882891
// do moving
883892
}
884893
894+
function getPointStyle(point: string, item: Item) {
895+
const { sizeX, sizeY } = item
896+
const width = sizeX * (baseWidth.value + baseMarginLeft.value) - baseMarginLeft.value
897+
const height = sizeY * (baseHeight.value + baseMarginTop.value) - baseMarginTop.value
898+
899+
const hasT = /t/.test(point)
900+
const hasB = /b/.test(point)
901+
const hasL = /l/.test(point)
902+
const hasR = /r/.test(point)
903+
let newLeft = 0
904+
let newTop = 0
905+
906+
// 四个角的点
907+
if (point.length === 2) {
908+
newLeft = hasL ? 0 : width
909+
newTop = hasT ? 0 : height
910+
} else {
911+
// 上下两点的点,宽度居中
912+
if (hasT || hasB) {
913+
newLeft = width / 2
914+
newTop = hasT ? 0 : height
915+
}
916+
917+
// 左右两边的点,高度居中
918+
if (hasL || hasR) {
919+
newLeft = hasL ? 0 : width
920+
newTop = Math.floor(height / 2)
921+
}
922+
}
923+
924+
return {
925+
marginLeft: '-4px',
926+
marginTop: '-4px',
927+
left: `${newLeft}px`,
928+
top: `${newTop}px`,
929+
// @ts-ignore
930+
cursor: `${cursors[point]}-resize`
931+
}
932+
}
933+
885934
defineExpose({
886935
getRenderState,
887936
init,
@@ -922,12 +971,15 @@ defineExpose({
922971
:key="'item' + index"
923972
:style="nowItemStyle(item)"
924973
>
925-
<slot :name="'slot' + index">{{ item }}</slot>
926-
<span
974+
<slot :name="'slot' + index">{{ item }} -- {{ baseWidth }}</slot>
975+
976+
<div
977+
v-for="point in pointList"
978+
:key="point"
927979
class="resizeHandle"
928-
v-show="resizable"
929-
@mousedown="startResize($event, item, index)"
930-
></span>
980+
:style="getPointStyle(point, item)"
981+
@mousedown="startResize($event, point, item, index)"
982+
></div>
931983
</div>
932984
</div>
933985
</div>

frontend/src/views/dashboard/css/DeDrag.less

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
.dragAndResize
22
{
33
position: relative;
4-
54
user-select: none;
6-
75
*
86
{
97
box-sizing: border-box;
108
margin: 0;
119
padding: 0;
1210
}
13-
1411
.item
1512
{
1613
position: absolute;
@@ -25,18 +22,13 @@
2522

2623
.resizeHandle
2724
{
28-
position: absolute;
29-
right: 2px;
30-
bottom: 2px;
31-
32-
width: 0;
33-
height: 0;
34-
35-
cursor: nw-resize;
36-
37-
opacity: .5;
38-
border-bottom: 10px solid black;
39-
border-left: 10px solid transparent;
25+
position: absolute;
26+
background: #fff;
27+
border: 1px solid #59c7f9;
28+
width: 8px;
29+
height: 8px;
30+
border-radius: 50%;
31+
z-index: 0;
4032
}
4133
}
4234

0 commit comments

Comments
 (0)