Skip to content

Commit 76b7578

Browse files
committed
refactor: dashboard view
1 parent 26fc930 commit 76b7578

File tree

17 files changed

+167
-48
lines changed

17 files changed

+167
-48
lines changed

backend/alembic/versions/941e2355a94d_011_update_dashboard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919

2020
def upgrade():
21-
op.add_column('core_dashboard', sa.Column('canvas_views', sa.Text(), nullable=True))
21+
op.add_column('core_dashboard', sa.Column('canvas_view_info', sa.Text(), nullable=True))
2222
# ### end Alembic commands ###
2323

2424

2525
def downgrade():
2626
# ### commands auto generated by Alembic - please adjust! ###
27-
op.drop_column('core_dashboard', 'canvas_views')
27+
op.drop_column('core_dashboard', 'canvas_view_info')
2828
# ### end Alembic commands ###

backend/apps/dashboard/crud/dashboard_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def create_canvas(session: SessionDep, user: CurrentUser, dashboard: CreateDashb
7171
record.node_type = dashboard.node_type
7272
record.component_data = dashboard.component_data
7373
record.canvas_style_data = dashboard.canvas_style_data
74-
record.canvas_views = dashboard.canvas_views
74+
record.canvas_view_info = dashboard.canvas_view_info
7575
session.add(record)
7676
session.flush()
7777
session.refresh(record)
@@ -86,7 +86,7 @@ def update_canvas(session: SessionDep, user: CurrentUser, dashboard: CreateDashb
8686
record.update_time = int(time.time())
8787
record.component_data = dashboard.component_data
8888
record.canvas_style_data = dashboard.canvas_style_data
89-
record.canvas_views = dashboard.canvas_views
89+
record.canvas_view_info = dashboard.canvas_view_info
9090
session.add(record)
9191
session.commit()
9292
return record

backend/apps/dashboard/models/dashboard_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CoreDashboard(SQLModel, table=True):
5050
default=None,
5151
sa_column=Column(Text, nullable=True)
5252
)
53-
canvas_views: str = Field(
53+
canvas_view_info: str = Field(
5454
default=None,
5555
sa_column=Column(Text, nullable=True)
5656
)
@@ -160,5 +160,5 @@ class QueryDashboard(BaseDashboard):
160160
class CreateDashboard(QueryDashboard):
161161
canvas_style_data: str =''
162162
component_data: str = ''
163-
canvas_views: str = ''
163+
canvas_view_info: str = ''
164164
description: str = ''

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@antv/g2": "^5.3.3",
2020
"@antv/s2": "^2.4.3",
21+
"@eslint/js": "^9.28.0",
2122
"@npkg/tinymce-plugins": "^0.0.7",
2223
"@tinymce/tinymce-vue": "^5.1.0",
2324
"dayjs": "^1.11.13",
@@ -27,7 +28,8 @@
2728
"lodash": "^4.17.21",
2829
"lodash-es": "^4.17.21",
2930
"snowflake-id": "^1.1.0",
30-
"tinymce": "^5.8.2",
31+
"tinymce": "^5.10.9",
32+
"html2canvas": "^1.4.1",
3133
"vue": "^3.5.13",
3234
"vue-dompurify-html": "^5.3.0",
3335
"vue-i18n": "^9.14.4",

frontend/src/style.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,11 @@ body {
137137
min-width: 780px !important;
138138
flex-wrap: wrap !important;
139139
}
140+
.clone_img {
141+
width: 100%;
142+
height: 100%;
143+
position: absolute;
144+
left: 0;
145+
top: 0;
146+
z-index: 100;
147+
}

frontend/src/utils/useEmitt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export const useEmitt = (option?: Option) => {
4141
* Debounced event emitter
4242
* @param eventName - Name of the event to emit
4343
* @param params - Parameters to pass with the event
44-
* @param delay - Debounce delay in milliseconds (default: 300ms)
44+
* @param delay - Debounce delay in milliseconds (default: 200ms)
4545
*/
46-
export const useEmittLazy = (eventName: string, params: any = null, delay = 500) => {
46+
export const useEmittLazy = (eventName: string, params: any = null, delay = 150) => {
4747
// If there's already a pending execution, skip this call
4848
if (lazyDebounceMap.has(eventName)) {
4949
const entry = lazyDebounceMap.get(eventName)!

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { type CanvasCoord, type CanvasItem } from '@/utils/canvas.ts'
66
import CanvasShape from './CanvasShape.vue'
77
import { findComponent } from '@/views/dashboard/components/component-list.ts'
88
import { storeToRefs } from 'pinia'
9-
import { useEmittLazy } from '@/utils/useEmitt.ts'
9+
import { useEmitt, useEmittLazy } from '@/utils/useEmitt.ts'
10+
import html2canvas from 'html2canvas'
1011
1112
const dashboardStore = dashboardStoreWithOut()
1213
const canvasLocked = ref(false) // Is the canvas movement locked, Default false
@@ -815,7 +816,6 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
815816
infoBox.value.moveItem = item
816817
infoBox.value.moveItemIndex = index
817818
}
818-
819819
infoBox.value.cloneItem = null
820820
infoBox.value.nowItemNode = null
821821
// @ts-expect-error eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -829,6 +829,15 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
829829
infoBox.value.cloneItem = infoBox.value.nowItemNode.cloneNode(true)
830830
}
831831
infoBox.value.cloneItem.classList.add('cloneNode')
832+
const img = new Image()
833+
img.classList.add('clone_img')
834+
const clonedSlot = infoBox.value.nowItemNode.querySelector('.slot-component')
835+
836+
html2canvas(clonedSlot).then((canvas) => {
837+
img.src = canvas.toDataURL()
838+
infoBox.value.cloneItem.appendChild(img)
839+
})
840+
832841
if (containerRef.value) {
833842
containerRef.value.append(infoBox.value.cloneItem)
834843
}
@@ -1130,6 +1139,11 @@ function tabMoveInCheckSQ() {
11301139
}
11311140
}
11321141
1142+
useEmitt({
1143+
name: `editor-delete-${props.canvasId}`,
1144+
callback: removeItemById,
1145+
})
1146+
11331147
onMounted(() => {
11341148
currentInstance = getCurrentInstance()
11351149
})
@@ -1171,12 +1185,13 @@ defineExpose({
11711185
:move-animate="moveAnimate"
11721186
:start-move="startMove"
11731187
:start-resize="startResize"
1188+
:canvas-id="canvasId"
11741189
:style="nowItemStyle(item)"
11751190
>
11761191
<component
11771192
:is="findComponent(item.component)"
11781193
:ref="'shape_component_' + item.id"
1179-
class="sql-component dragHandle"
1194+
class="sql-component slot-component dragHandle"
11801195
:config-item="item"
11811196
:view-info="canvasViewInfo[item.id]"
11821197
@parent-add-item-box="(subItem: any) => addItemBox(subItem)"

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { type CanvasItem } from '@/utils/canvas.ts'
33
import { ref, toRefs, type PropType } from 'vue'
44
import ResizeHandle from '@/views/dashboard/canvas/ResizeHandle.vue'
5+
import DragHandle from '@/views/dashboard/canvas/DragHandle.vue'
6+
import ComponentBar from '@/views/dashboard/canvas/ComponentBar.vue'
57
68
const shapeRef = ref(null)
79
// Props
@@ -38,6 +40,10 @@ const props = defineProps({
3840
return {}
3941
},
4042
},
43+
canvasId: {
44+
type: String,
45+
default: 'canvas-main',
46+
},
4147
})
4248
4349
const { draggable } = toRefs(props)
@@ -61,6 +67,13 @@ const shapeClick = (e: MouseEvent) => {
6167
@click="shapeClick"
6268
@mousedown="startMove($event, configItem, itemIndex)"
6369
>
70+
<component-bar
71+
:config-item="configItem"
72+
:active="active"
73+
:show-position="'canvas'"
74+
:canvas-id="canvasId"
75+
></component-bar>
76+
<drag-handle></drag-handle>
6477
<slot></slot>
6578
<resize-handle
6679
v-if="active"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<script setup lang="ts">
2+
import { toRefs } from 'vue'
3+
import icon_delete from '@/assets/svg/icon_delete.svg'
4+
import { Icon } from '@/components/icon-custom'
5+
import { useEmitt } from '@/utils/useEmitt.ts'
6+
7+
const props = defineProps({
8+
active: {
9+
type: Boolean,
10+
default: false,
11+
},
12+
configItem: {
13+
type: Object,
14+
required: true,
15+
},
16+
showPosition: {
17+
required: false,
18+
type: String,
19+
default: 'preview',
20+
},
21+
canvasId: {
22+
type: String,
23+
default: 'canvas-main',
24+
},
25+
})
26+
27+
const { configItem } = toRefs(props)
28+
29+
const doDeleteComponent = (e: MouseEvent) => {
30+
e.stopPropagation()
31+
e.preventDefault()
32+
useEmitt().emitter.emit(`editor-delete-${props.canvasId}`, configItem.value.id)
33+
}
34+
</script>
35+
36+
<template>
37+
<div class="component-bar-main" :class="{ 'bar-hidden': !active }">
38+
<div>
39+
<el-icon class="handle-icon" @click="doDeleteComponent">
40+
<Icon>
41+
<icon_delete class="svg-icon"></icon_delete>
42+
</Icon>
43+
</el-icon>
44+
</div>
45+
</div>
46+
</template>
47+
48+
<style scoped lang="less">
49+
.component-bar-main {
50+
height: 20px;
51+
position: absolute;
52+
right: 5px;
53+
top: 5px;
54+
display: flex;
55+
z-index: 5;
56+
cursor: pointer !important;
57+
.handle-icon {
58+
color: #646a73;
59+
}
60+
&:hover {
61+
background-color: #e8f0fe;
62+
color: var(--el-color-primary);
63+
}
64+
}
65+
66+
.bar-hidden {
67+
display: none;
68+
}
69+
</style>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const shadowStyle = (size: number, index: number) => {
6060
.dragHandle {
6161
background: #c1e2e8;
6262
position: absolute;
63-
cursor: move;
63+
cursor: move !important;
6464
z-index: 3;
6565
}
6666
</style>

0 commit comments

Comments
 (0)