-
Notifications
You must be signed in to change notification settings - Fork 691
Expand file tree
/
Copy pathDashboardEditor.vue
More file actions
162 lines (150 loc) · 3.89 KB
/
DashboardEditor.vue
File metadata and controls
162 lines (150 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<script setup lang="ts">
import CanvasCore from '@/views/dashboard/canvas/CanvasCore.vue'
import { nextTick, onMounted, type PropType, ref } from 'vue'
import type { CanvasItem } from '@/utils/canvas.ts'
import { useEmitt, useEmittLazy } from '@/utils/useEmitt.ts'
const canvasCoreRef = ref(null)
const dashboardEditorRef = ref(null)
const baseWidth = ref(0)
const baseHeight = ref(0)
const baseMarginLeft = ref(0)
const baseMarginTop = ref(0)
// Props
const props = defineProps({
canvasId: {
type: String,
default: 'canvas-main',
},
parentConfigItem: {
type: Object as PropType<CanvasItem>,
required: false,
default: null,
},
dashboardInfo: {
type: Object,
required: false,
default: null,
},
canvasViewInfo: {
type: Object,
required: false,
default: () => {},
},
canvasStyleData: {
type: Object,
required: false,
default: null,
},
canvasComponentData: {
type: Array as PropType<CanvasItem[]>,
required: true,
},
baseMatrixCount: {
type: Object,
default: () => {
return {
x: 72,
y: 36,
}
},
},
moveInActive: {
type: Boolean,
default: false,
},
})
const canvasSizeInit = () => {
sizeInit()
if (canvasCoreRef.value) {
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
canvasCoreRef.value.sizeInit()
}
}
const sizeInit = () => {
if (dashboardEditorRef.value) {
baseMarginLeft.value = 16
baseMarginTop.value = 16
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
const screenWidth = dashboardEditorRef.value.offsetWidth
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
const screenHeight = dashboardEditorRef.value.offsetHeight
baseWidth.value =
(screenWidth - baseMarginLeft.value) / props.baseMatrixCount.x - baseMarginLeft.value
baseHeight.value =
(screenHeight - baseMarginTop.value) / props.baseMatrixCount.y - baseMarginTop.value
useEmittLazy('view-render-all')
}
}
const addItemToBox = (item: CanvasItem) => {
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
canvasCoreRef.value.addItemBox(item)
}
const findPositionX = (width: number) => {
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
return canvasCoreRef.value.findPositionX(width)
}
useEmitt({
name: 'custom-canvas-resize',
callback: canvasSizeInit,
})
defineExpose({
canvasSizeInit,
addItemToBox,
findPositionX,
})
onMounted(() => {
window.addEventListener('resize', canvasSizeInit)
nextTick(() => {
if (dashboardEditorRef.value) {
sizeInit()
nextTick(() => {
if (canvasCoreRef.value) {
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
canvasCoreRef.value.init()
}
})
}
})
})
const emits = defineEmits(['parentAddItemBox'])
</script>
<template>
<div
ref="dashboardEditorRef"
class="dashboard-editor-main"
:class="{ 'move-in-active': moveInActive }"
>
<CanvasCore
ref="canvasCoreRef"
:base-width="baseWidth"
:base-height="baseHeight"
:base-margin-left="baseMarginLeft"
:base-margin-top="baseMarginTop"
:canvas-component-data="canvasComponentData"
:canvas-style-data="canvasStyleData"
:canvas-view-info="canvasViewInfo"
:dashboard-info="dashboardInfo"
:parent-config-item="parentConfigItem"
:canvas-id="canvasId"
@parent-add-item-box="(item) => emits('parentAddItemBox', item)"
></CanvasCore>
</div>
</template>
<style scoped lang="less">
.dashboard-editor-main {
width: 100%;
height: 100%;
overflow-y: auto;
&::-webkit-scrollbar {
width: 0 !important;
height: 0 !important;
}
:deep(.ed-empty__description) {
width: 240px !important;
}
}
.move-in-active {
border: 2px dotted blueviolet;
margin: -2px;
}
</style>