-
Notifications
You must be signed in to change notification settings - Fork 695
Expand file tree
/
Copy pathindex.vue
More file actions
123 lines (114 loc) · 3.88 KB
/
index.vue
File metadata and controls
123 lines (114 loc) · 3.88 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
<script setup lang="ts">
import { onMounted, ref, computed, reactive } from 'vue'
import Toolbar from '@/views/dashboard/editor/Toolbar.vue'
import DashboardEditor from '@/views/dashboard/editor/DashboardEditor.vue'
import { findNewComponentFromList } from '@/views/dashboard/components/component-list.ts'
import { guid } from '@/utils/canvas.ts'
import cloneDeep from 'lodash/cloneDeep'
import { storeToRefs } from 'pinia'
import { dashboardStoreWithOut } from '@/stores/dashboard/dashboard.ts'
import router from '@/router'
import { initCanvasData } from '@/views/dashboard/utils/canvasUtils.ts'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const dashboardStore = dashboardStoreWithOut()
const { componentData, canvasViewInfo, fullscreenFlag } = storeToRefs(dashboardStore)
const dataInitState = ref(true)
const state = reactive({
routerPid: null,
resourceId: null,
opt: null,
})
const dashboardEditorInnerRef = ref(null)
const addComponent = (componentType: string, viewInfo?: any) => {
const component = cloneDeep(findNewComponentFromList(componentType))
if (component && dashboardEditorInnerRef.value) {
component.id = guid()
// add view
if (component?.component === 'SQView' && !!viewInfo) {
viewInfo['sourceId'] = viewInfo['id']
viewInfo['id'] = component.id
dashboardStore.addCanvasViewInfo(viewInfo)
} else if (component.component === 'SQTab') {
const subTabName = guid('tab')
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
component.propValue[0].name = subTabName
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
component.propValue[0].title = t('dashboard.new_tab')
component.activeTabName = subTabName
}
component.y = maxYComponentCount() + 2
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
dashboardEditorInnerRef.value.addItemToBox(component)
}
}
const maxYComponentCount = () => {
if (componentData.value.length === 0) {
return 1
} else {
return componentData.value
.filter((item) => item['y'])
.map((item) => item['y'] + item['sizeY']) // Calculate the y+sizeY of each element
.reduce((max, current) => Math.max(max, current), 0)
}
}
onMounted(() => {
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
state.opt = router.currentRoute.value.query.opt
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
state.resourceId = router.currentRoute.value.query.resourceId
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
state.routerPid = router.currentRoute.value.query.pid
if (state.opt === 'create') {
dashboardStore.updateDashboardInfo({
dataState: 'prepare',
name: t('dashboard.new_dashboard'),
pid: state.routerPid,
})
} else if (state.resourceId) {
dataInitState.value = false
initCanvasData({ id: state.resourceId }, function () {
dataInitState.value = true
})
}
})
const baseParams = computed(() => {
return {
opt: state.opt,
resourceId: state.resourceId,
pid: state.routerPid,
}
})
</script>
<template>
<div class="editor-content" :class="{ 'editor-content-fullscreen': fullscreenFlag }">
<div class="editor-main">
<Toolbar :base-params="baseParams" @add-component="addComponent"></Toolbar>
<DashboardEditor
v-if="dataInitState"
ref="dashboardEditorInnerRef"
:canvas-component-data="componentData"
:canvas-view-info="canvasViewInfo"
>
</DashboardEditor>
</div>
</div>
</template>
<style scoped lang="less">
.editor-content {
width: 100vw;
height: 100vh;
background: #fff;
overflow: hidden;
}
.editor-content-fullscreen {
padding: 0 !important;
}
.editor-main {
position: relative;
background: #f5f6f7;
overflow: hidden;
width: 100%;
height: 100%;
}
</style>