Skip to content

Commit 1f74224

Browse files
authored
refactor(Dashboard): When optimizing the addition of components, they can be arranged in order from left to right in the dashboard (dataease#114)
1 parent 0e7369b commit 1f74224

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

frontend/src/stores/dashboard/dashboard.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const dashboardStore = defineStore('dashboard', {
1313
canvasViewInfo: {},
1414
fullscreenFlag: false,
1515
dataPrepareState: false,
16+
baseMatrixCount: {
17+
x: 72,
18+
y: 36,
19+
},
1620
dashboardInfo: {
1721
id: null,
1822
name: null,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,6 @@ const forceComputed = () => {
10691069
}
10701070
10711071
function addItemBox(item: CanvasItem) {
1072-
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
1073-
item.x = findPositionX(item)
10741072
canvasComponentData.value.push(item)
10751073
forceComputed()
10761074
nextTick(() => {
@@ -1177,8 +1175,7 @@ function tabMoveInCheckSQ() {
11771175
/**
11781176
* Find position box
11791177
*/
1180-
function findPositionX(item: CanvasItem) {
1181-
const width = item.sizeX
1178+
function findPositionX(width: number) {
11821179
let resultX = 1
11831180
let checkPointYIndex = -1 // -1 means not occupying any Y-direction canvas
11841181
// Component width
@@ -1245,6 +1242,7 @@ defineExpose({
12451242
removeItem,
12461243
findClosetCoords,
12471244
makeCoordinate,
1245+
findPositionX,
12481246
})
12491247
</script>
12501248

frontend/src/views/dashboard/editor/DashboardEditor.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ const addItemToBox = (item: CanvasItem) => {
8585
canvasCoreRef.value.addItemBox(item)
8686
}
8787
88+
const findPositionX = (width: number) => {
89+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
90+
return canvasCoreRef.value.findPositionX(width)
91+
}
92+
8893
useEmitt({
8994
name: 'custom-canvas-resize',
9095
callback: canvasSizeInit,
@@ -93,6 +98,7 @@ useEmitt({
9398
defineExpose({
9499
canvasSizeInit,
95100
addItemToBox,
101+
findPositionX,
96102
})
97103
98104
onMounted(() => {

frontend/src/views/dashboard/editor/Toolbar.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const { dashboardInfo, fullscreenFlag } = storeToRefs(dashboardStore)
2222
2323
const snapshotStore = snapshotStoreWithOut()
2424
const { snapshotIndex } = storeToRefs(snapshotStore)
25-
const emits = defineEmits(['addComponent'])
25+
const emits = defineEmits(['addComponents'])
2626
const resourceGroupOptRef = ref(null)
2727
const chatChartSelectionRef = ref(null)
2828
const openViewDialog = () => {
@@ -139,10 +139,11 @@ const backToMain = () => {
139139
}
140140
141141
const addChatChart = (views: any) => {
142+
emits('addComponents', 'SQView', views)
142143
views.forEach((view: any) => {
143144
const target = cloneDeep(view)
144145
delete target.chart.sourceType
145-
emits('addComponent', 'SQView', target)
146+
emits('addComponents', 'SQView', target)
146147
})
147148
ElMessage({
148149
type: 'success',
@@ -212,14 +213,14 @@ const previewInner = () => {
212213
:title="t('dashboard.text')"
213214
themes="light"
214215
is-label
215-
@custom-click="() => emits('addComponent', 'SQText')"
216+
@custom-click="() => emits('addComponents', 'SQText')"
216217
></component-button-label>
217218
<component-button-label
218219
:icon-name="dvTab"
219220
title="Tab"
220221
themes="light"
221222
is-label
222-
@custom-click="() => emits('addComponent', 'SQTab')"
223+
@custom-click="() => emits('addComponents', 'SQTab')"
223224
>
224225
</component-button-label>
225226
</div>

frontend/src/views/dashboard/editor/index.vue

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { useI18n } from 'vue-i18n'
1313
1414
const { t } = useI18n()
1515
const dashboardStore = dashboardStoreWithOut()
16-
const { componentData, canvasViewInfo, fullscreenFlag } = storeToRefs(dashboardStore)
16+
const { componentData, canvasViewInfo, fullscreenFlag, baseMatrixCount } =
17+
storeToRefs(dashboardStore)
1718
1819
const dataInitState = ref(true)
1920
const state = reactive({
@@ -23,8 +24,26 @@ const state = reactive({
2324
})
2425
2526
const dashboardEditorInnerRef = ref(null)
26-
const addComponent = (componentType: string, viewInfo?: any) => {
27+
const addComponents = (componentType: string, views?: any) => {
2728
const component = cloneDeep(findNewComponentFromList(componentType))
29+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
30+
component.x = findPositionX(component.sizeX)
31+
if (views) {
32+
views.forEach((view: any, index: number) => {
33+
const target = cloneDeep(view)
34+
delete target.chart.sourceType
35+
if (index > 0) {
36+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
37+
component.x = ((component.x + component?.sizeX - 1) % baseMatrixCount.value.x) + 1
38+
}
39+
addComponent(component, target)
40+
})
41+
} else {
42+
addComponent(component)
43+
}
44+
}
45+
const addComponent = (componentSource: any, viewInfo?: any) => {
46+
const component = cloneDeep(componentSource)
2847
if (component && dashboardEditorInnerRef.value) {
2948
component.id = guid()
3049
// add view
@@ -34,9 +53,7 @@ const addComponent = (componentType: string, viewInfo?: any) => {
3453
dashboardStore.addCanvasViewInfo(viewInfo)
3554
} else if (component.component === 'SQTab') {
3655
const subTabName = guid('tab')
37-
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
3856
component.propValue[0].name = subTabName
39-
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
4057
component.propValue[0].title = t('dashboard.new_tab')
4158
component.activeTabName = subTabName
4259
}
@@ -85,12 +102,20 @@ const baseParams = computed(() => {
85102
pid: state.routerPid,
86103
}
87104
})
105+
const findPositionX = (width: number) => {
106+
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
107+
return dashboardEditorInnerRef.value.findPositionX(width)
108+
}
88109
</script>
89110

90111
<template>
91112
<div class="editor-content" :class="{ 'editor-content-fullscreen': fullscreenFlag }">
92113
<div class="editor-main">
93-
<Toolbar :base-params="baseParams" @add-component="addComponent"></Toolbar>
114+
<Toolbar
115+
:base-params="baseParams"
116+
:find-position-x="findPositionX"
117+
@add-components="addComponents"
118+
></Toolbar>
94119
<DashboardEditor
95120
v-if="dataInitState"
96121
ref="dashboardEditorInnerRef"

0 commit comments

Comments
 (0)