Skip to content

Commit b498355

Browse files
committed
refactor: dashboard canvas edit update
1 parent 2eef411 commit b498355

File tree

10 files changed

+115
-8
lines changed

10 files changed

+115
-8
lines changed

frontend/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"password_reset_successful": "Password reset successful"
3333
},
3434
"dashboard": {
35+
"add_component_tips": "Select components from the top toolbar and add them here to create a dashboard",
3536
"add_view": "Add Chart",
3637
"delete_dashboard_warn": "Delete This Dashboard: {0}",
3738
"rename_dashboard": "Rename Dashboard",

frontend/src/i18n/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"password_reset_successful": "重置密码成功"
3535
},
3636
"dashboard": {
37+
"add_component_tips": "从顶部工具栏中选择组件,添加到这里创建仪表板",
3738
"add_view": "添加图表",
3839
"delete_dashboard_warn": "是否删除仪表板:{0}",
3940
"rename_dashboard": "重命名仪表板",

frontend/src/stores/dashboard/dashboard.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export const dashboardStore = defineStore('dashboard', {
3535
},
3636
},
3737
actions: {
38+
setFullscreenFlag(val: boolean) {
39+
this.fullscreenFlag = val
40+
},
3841
setCurComponent(value: any) {
3942
this.curComponent = value
4043
this.curComponentId = value && value.id ? value.id : null

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { findComponent } from '@/views/dashboard/components/component-list.ts'
88
import { storeToRefs } from 'pinia'
99
import { useEmitt, useEmittLazy } from '@/utils/useEmitt.ts'
1010
import html2canvas from 'html2canvas'
11+
import EmptyBackground from '@/views/dashboard/common/EmptyBackground.vue'
12+
import { useI18n } from 'vue-i18n'
1113
14+
const { t } = useI18n()
1215
const dashboardStore = dashboardStoreWithOut()
1316
const canvasLocked = ref(false) // Is the canvas movement locked, Default false
1417
const emits = defineEmits(['parentAddItemBox'])
@@ -1174,6 +1177,11 @@ defineExpose({
11741177
@mouseup="endMove()"
11751178
@mousemove="moving()"
11761179
>
1180+
<EmptyBackground
1181+
v-if="!canvasComponentData.length"
1182+
:description="t('dashboard.add_component_tips')"
1183+
img-type="selectDashboard"
1184+
/>
11771185
<template v-if="renderOk">
11781186
<CanvasShape
11791187
v-for="(item, index) in canvasComponentData"

frontend/src/views/dashboard/common/EmptyBackground.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { type PropType } from 'vue'
33
import nothingInput from '@/assets/img/nothing-input.png'
44
import nothingSelect from '@/assets/img/nothing-select.png'
55
import nothingTable from '@/assets/img/nothing-table.png'
6-
import nothingSelectDashoard from '@/assets/img/none-dashboard.png'
6+
import nothingSelectDashboard from '@/assets/img/none-dashboard.png'
77
import none from '@/assets/img/none.png'
88
import error from '@/assets/img/error.png'
99
import nothingTree from '@/assets/img/nothing-tree.png'
@@ -30,7 +30,7 @@ const getAssetsFile = {
3030
table: nothingTable,
3131
noneWhite: nothingNone,
3232
tree: nothingTree,
33-
selectDashboard: nothingSelectDashoard,
33+
selectDashboard: nothingSelectDashboard,
3434
error,
3535
none,
3636
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<script lang="ts" setup>
2+
import { dashboardStoreWithOut } from '@/stores/dashboard/dashboard.ts'
3+
4+
const dashboardStore = dashboardStoreWithOut()
5+
import { nextTick, onBeforeUnmount, onMounted } from 'vue'
6+
import { useEmitt } from '@/utils/useEmitt.ts'
7+
defineProps({
8+
themes: {
9+
type: String,
10+
default: 'light',
11+
},
12+
componentType: {
13+
type: String,
14+
default: 'button',
15+
},
16+
showPosition: {
17+
required: false,
18+
type: String,
19+
default: 'preview',
20+
},
21+
})
22+
23+
const fullscreenChange = () => {
24+
const isFullscreen = !!document.fullscreenElement
25+
dashboardStore.setFullscreenFlag(isFullscreen)
26+
setTimeout(() => {
27+
useEmitt().emitter.emit('custom-canvas-resize')
28+
}, 100)
29+
}
30+
31+
const toggleFullscreen = () => {
32+
const bodyNode = document.querySelector('body')
33+
if (!document.fullscreenElement) {
34+
bodyNode?.requestFullscreen()
35+
} else {
36+
document.exitFullscreen()
37+
}
38+
}
39+
40+
// 针对钉钉windows版无法退出全屏问题 这里主动退出
41+
const handleKeydown = (event) => {
42+
if (event.key === 'Escape' && document.fullscreenElement) {
43+
document.exitFullscreen()
44+
}
45+
}
46+
47+
onMounted(() => {
48+
document.addEventListener('fullscreenchange', fullscreenChange)
49+
document.addEventListener('keydown', handleKeydown)
50+
})
51+
52+
onBeforeUnmount(() => {
53+
document.removeEventListener('fullscreenchange', fullscreenChange)
54+
document.removeEventListener('keydown', handleKeydown)
55+
})
56+
57+
defineExpose({
58+
toggleFullscreen,
59+
})
60+
</script>
61+
62+
<template><span></span></template>
63+
64+
<style lang="less" scoped></style>

frontend/src/views/dashboard/css/CanvasStyle.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
position: relative;
33
user-select: none;
44
width: 100%;
5+
height: 100%;
56

67
* {
78
box-sizing: border-box;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import CanvasCore from '@/views/dashboard/canvas/CanvasCore.vue'
33
import { nextTick, onMounted, type PropType, ref } from 'vue'
44
import type { CanvasItem } from '@/utils/canvas.ts'
5-
import { useEmittLazy } from '@/utils/useEmitt.ts'
5+
import { useEmitt, useEmittLazy } from '@/utils/useEmitt.ts'
66
77
const canvasCoreRef = ref(null)
88
const dashboardEditorRef = ref(null)
@@ -85,6 +85,11 @@ const addItemToBox = (item: CanvasItem) => {
8585
canvasCoreRef.value.addItemBox(item)
8686
}
8787
88+
useEmitt({
89+
name: 'custom-canvas-resize',
90+
callback: canvasSizeInit,
91+
})
92+
8893
defineExpose({
8994
canvasSizeInit,
9095
addItemToBox,

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import icon_redo_outlined from '@/assets/svg/icon_redo_outlined.svg'
1414
import icon_arrow_left_outlined from '@/assets/svg/icon_arrow-left_outlined.svg'
1515
import { saveDashboardResource } from '@/views/dashboard/utils/canvasUtils.ts'
1616
import ChatChartSelection from '@/views/dashboard/editor/ChatChartSelection.vue'
17-
17+
import icon_pc_outlined from '@/assets/svg/icon_pc_outlined.svg'
18+
const fullScreeRef = ref(null)
1819
const { t } = useI18n()
1920
const dashboardStore = dashboardStoreWithOut()
20-
const { dashboardInfo } = storeToRefs(dashboardStore)
21+
const { dashboardInfo, fullscreenFlag } = storeToRefs(dashboardStore)
2122
2223
const snapshotStore = snapshotStoreWithOut()
2324
const { snapshotIndex } = storeToRefs(snapshotStore)
@@ -30,6 +31,7 @@ const openViewDialog = () => {
3031
}
3132
3233
import cloneDeep from 'lodash/cloneDeep'
34+
import SQFullscreen from '@/views/dashboard/common/SQFullscreen.vue'
3335
3436
let nameEdit = ref(false)
3537
let inputName = ref('')
@@ -136,10 +138,16 @@ const addChatChart = (views: any) => {
136138
emits('addComponent', 'SQView', cloneDeep(view))
137139
})
138140
}
141+
142+
const previewInner = () => {
143+
if (fullScreeRef.value) {
144+
fullScreeRef.value.toggleFullscreen()
145+
}
146+
}
139147
</script>
140148

141149
<template>
142-
<div class="toolbar-main">
150+
<div class="toolbar-main" :class="{ 'toolbar-main-hidden': fullscreenFlag }">
143151
<el-icon class="custom-el-icon back-icon" @click="backToMain()">
144152
<Icon name="icon_left_outlined">
145153
<icon_arrow_left_outlined class="toolbar-hover-icon toolbar-icon" />
@@ -204,6 +212,14 @@ const addChatChart = (views: any) => {
204212
</component-button-label>
205213
</div>
206214
<div class="right-toolbar">
215+
<el-button secondary @click="previewInner">
216+
<template #icon>
217+
<icon name="icon_pc_outlined">
218+
<icon_pc_outlined class="svg-icon" />
219+
</icon>
220+
</template>
221+
{{ t('dashboard.preview') }}
222+
</el-button>
207223
<el-button
208224
style="float: right; margin-right: 12px"
209225
type="primary"
@@ -226,10 +242,14 @@ const addChatChart = (views: any) => {
226242
@add-chat-chart="addChatChart"
227243
@finish="chartSelectionFinish"
228244
></ChatChartSelection>
245+
<SQFullscreen ref="fullScreeRef" show-position="edit"></SQFullscreen>
229246
</div>
230247
</template>
231248

232249
<style scoped lang="less">
250+
.toolbar-main-hidden {
251+
display: none !important;
252+
}
233253
.toolbar-main {
234254
width: 100%;
235255
height: 56px;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useI18n } from 'vue-i18n'
1313
1414
const { t } = useI18n()
1515
const dashboardStore = dashboardStoreWithOut()
16-
const { componentData, canvasViewInfo } = storeToRefs(dashboardStore)
16+
const { componentData, canvasViewInfo, fullscreenFlag } = storeToRefs(dashboardStore)
1717
1818
const dataInitState = ref(true)
1919
const state = reactive({
@@ -75,7 +75,7 @@ const baseParams = computed(() => {
7575
</script>
7676

7777
<template>
78-
<div class="editor-content">
78+
<div class="editor-content" :class="{ 'editor-content-fullscreen': fullscreenFlag }">
7979
<div class="editor-main">
8080
<Toolbar :base-params="baseParams" @add-component="addComponent"></Toolbar>
8181
<DashboardEditor
@@ -97,6 +97,10 @@ const baseParams = computed(() => {
9797
background: #fff;
9898
overflow: hidden;
9999
}
100+
101+
.editor-content-fullscreen {
102+
padding: 0 !important;
103+
}
100104
.editor-main {
101105
border-radius: 12px;
102106
position: relative;

0 commit comments

Comments
 (0)