Skip to content

Commit 76bff9c

Browse files
committed
refactor: dashboard
1 parent 273479a commit 76bff9c

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<script setup lang="ts">
2+
import { type CanvasItem } from '../utils/CanvasUtils'
3+
import { ref, toRefs, type PropType } from 'vue'
4+
const shapeRef = ref(null)
5+
// Props
6+
const props = defineProps({
7+
configItem: {
8+
type: Object as PropType<CanvasItem>,
9+
required: true
10+
},
11+
itemIndex: {
12+
type: Number,
13+
required: true
14+
},
15+
moveAnimate: {
16+
type: Boolean,
17+
required: true
18+
},
19+
draggable: {
20+
type: Boolean,
21+
required: true
22+
},
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+
},
39+
startMove: {
40+
type: Function,
41+
default: () => {
42+
return {}
43+
}
44+
},
45+
startResize: {
46+
type: Function,
47+
default: () => {
48+
return {}
49+
}
50+
}
51+
})
52+
53+
const {
54+
baseWidth,
55+
baseHeight,
56+
baseMarginLeft,
57+
baseMarginTop,
58+
draggable,
59+
} = toRefs(props)
60+
61+
const cursors = {
62+
lt: 'nw',
63+
t: 'n',
64+
rt: 'ne',
65+
r: 'e',
66+
rb: 'se',
67+
b: 's',
68+
lb: 'sw',
69+
l: 'w'
70+
}
71+
72+
function getPointStyle(point: string) {
73+
const hasT = /t/.test(point)
74+
const hasB = /b/.test(point)
75+
const hasL = /l/.test(point)
76+
const hasR = /r/.test(point)
77+
let newLeft = '0px'
78+
let newTop = '0px'
79+
80+
// Points at the four corners
81+
if (point.length === 2) {
82+
newLeft = hasL ? '0px' : '100%'
83+
newTop = hasT ? '0px' : '100%'
84+
} else {
85+
// The point between the upper and lower points, with a width centered
86+
if (hasT || hasB) {
87+
newLeft = '50%'
88+
newTop = hasT ? '0px' : '100%'
89+
}
90+
91+
// The points on both sides are centered in height
92+
if (hasL || hasR) {
93+
newLeft = hasL ? '0px' : '100%'
94+
newTop ='50%'
95+
}
96+
}
97+
98+
return {
99+
marginLeft: '-4px',
100+
marginTop: '-4px',
101+
left: `${newLeft}`,
102+
top: `${newTop}`,
103+
// @ts-expect-error
104+
cursor: `${cursors[point]}-resize`
105+
}
106+
}
107+
108+
const pointList = ['lt', 't', 'rt', 'r', 'rb', 'b', 'lb', 'l']
109+
</script>
110+
111+
<template>
112+
<div :class="{
113+
item: true,
114+
moveAnimation: moveAnimate,
115+
movingItem: configItem.isPlayer,
116+
canNotDrag: !draggable
117+
}" @mousedown="startMove($event, configItem, itemIndex)" ref="shapeRef">
118+
<slot></slot>
119+
<div v-for="point in pointList" :key="point" class="resizeHandle" :style="getPointStyle(point, configItem)"
120+
@mousedown="startResize($event, point, configItem, itemIndex)"></div>
121+
</div>
122+
</template>
123+
124+
<style scoped lang="less">
125+
@import '../css/CanvasStyle.less';
126+
</style>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
.dragAndResize
2+
{
3+
position: relative;
4+
user-select: none;
5+
*
6+
{
7+
box-sizing: border-box;
8+
margin: 0;
9+
padding: 0;
10+
}
11+
.item
12+
{
13+
position: absolute;
14+
width: 100px;
15+
height: 100px;
16+
cursor: move;
17+
border: 1px solid #59c7f9;
18+
background-color: #fff;
19+
.resizeHandle
20+
{
21+
position: absolute;
22+
background: #fff;
23+
border: 1px solid #59c7f9;
24+
width: 8px;
25+
height: 8px;
26+
border-radius: 50%;
27+
z-index: 0;
28+
}
29+
}
30+
.moveAnimation
31+
{
32+
transition: top 80ms ease;
33+
}
34+
.canNotDrag
35+
{
36+
cursor: default!important;
37+
}
38+
39+
.cloneNode
40+
{
41+
z-index: 3;
42+
43+
transition: none;
44+
45+
opacity: .5;
46+
}
47+
48+
.movingItem
49+
{
50+
position: absolute;
51+
52+
border: none;
53+
&:before
54+
{
55+
position: absolute;
56+
z-index: 2;
57+
top: 0;
58+
left: 0;
59+
width: 100%;
60+
height: 100%;
61+
content: '';
62+
background-color: #b8d3f9;
63+
}
64+
.resizeHandle
65+
{
66+
display: none;
67+
}
68+
}
69+
70+
.positionBox
71+
{
72+
position: fixed;
73+
top: 0;
74+
right: 100px;
75+
76+
overflow: auto;
77+
78+
width: 500px;
79+
height: 500px;
80+
81+
border: 1px solid;
82+
}
83+
84+
.coords
85+
{
86+
position: fixed;
87+
right: 100px;
88+
bottom: 200px;
89+
90+
overflow: auto;
91+
92+
width: 200px;
93+
height: 200px;
94+
95+
border: 1px solid;
96+
}
97+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export interface CanvasItem {
2+
_dragId: string | number
3+
x: number
4+
y: number
5+
sizeX: number
6+
sizeY: number
7+
[key: string]: any
8+
}
9+
10+
11+
export type CanvasCoord = {
12+
x1: number
13+
y1: number
14+
x2: number
15+
y2: number
16+
c1: number
17+
c2: number
18+
el: {
19+
x: number
20+
y: number
21+
sizeX: number
22+
sizeY: number
23+
_dragId: string | number
24+
[key: string]: any
25+
}
26+
}

0 commit comments

Comments
 (0)