Skip to content

Commit 6de49c8

Browse files
committed
refactor: dashboard rich text
1 parent d4982ef commit 6de49c8

10 files changed

Lines changed: 226 additions & 80 deletions

File tree

frontend/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ declare module '@vue/runtime-core' {
1313
ElAvatar: typeof import('element-plus-secondary/es')['ElAvatar']
1414
ElButton: typeof import('element-plus-secondary/es')['ElButton']
1515
ElCheckbox: typeof import('element-plus-secondary/es')['ElCheckbox']
16+
ElCheckboxGroup: typeof import('element-plus-secondary/es')['ElCheckboxGroup']
17+
ElCol: typeof import('element-plus-secondary/es')['ElCol']
1618
ElContainer: typeof import('element-plus-secondary/es')['ElContainer']
1719
ElDialog: typeof import('element-plus-secondary/es')['ElDialog']
1820
ElDivider: typeof import('element-plus-secondary/es')['ElDivider']
@@ -30,15 +32,21 @@ declare module '@vue/runtime-core' {
3032
ElMenuItem: typeof import('element-plus-secondary/es')['ElMenuItem']
3133
ElOption: typeof import('element-plus-secondary/es')['ElOption']
3234
ElPagination: typeof import('element-plus-secondary/es')['ElPagination']
35+
ElRadio: typeof import('element-plus-secondary/es')['ElRadio']
36+
ElRadioGroup: typeof import('element-plus-secondary/es')['ElRadioGroup']
37+
ElRow: typeof import('element-plus-secondary/es')['ElRow']
3338
ElScrollbar: typeof import('element-plus-secondary/es')['ElScrollbar']
3439
ElSelect: typeof import('element-plus-secondary/es')['ElSelect']
3540
ElSlider: typeof import('element-plus-secondary/es')['ElSlider']
41+
ElStep: typeof import('element-plus-secondary/es')['ElStep']
42+
ElSteps: typeof import('element-plus-secondary/es')['ElSteps']
3643
ElSwitch: typeof import('element-plus-secondary/es')['ElSwitch']
3744
ElTable: typeof import('element-plus-secondary/es')['ElTable']
3845
ElTableColumn: typeof import('element-plus-secondary/es')['ElTableColumn']
3946
ElTabPane: typeof import('element-plus-secondary/es')['ElTabPane']
4047
ElTabs: typeof import('element-plus-secondary/es')['ElTabs']
4148
ElTooltip: typeof import('element-plus-secondary/es')['ElTooltip']
49+
ElUpload: typeof import('element-plus-secondary/es')['ElUpload']
4250
Icon: typeof import('./src/components/icon-custom/src/Icon.vue')['default']
4351
Layout: typeof import('./src/components/layout/index.vue')['default']
4452
RouterLink: typeof import('vue-router')['RouterLink']

frontend/src/stores/dashboard/dashboard.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const dashboardStore = defineStore('dashboard', {
77
tabCollisionActiveId: null,
88
tabMoveInActiveId: null,
99
curComponent: null,
10+
curComponentId: null,
1011
canvasStyle: {},
1112
componentData: [],
1213
dashboardInfo: {
@@ -29,6 +30,7 @@ export const dashboardStore = defineStore('dashboard', {
2930
actions: {
3031
setCurComponent(value: any) {
3132
this.curComponent = value
33+
this.curComponentId = value && value.id ? value.id : null
3234
},
3335
setComponentData(value: any) {
3436
this.componentData = value

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {dashboardStoreWithOut} from '@/stores/dashboard/dashboard'
55
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";
8+
import {storeToRefs} from "pinia";
89
910
const dashboardStore = dashboardStoreWithOut()
1011
const canvasLocked = ref(false) // Is the canvas movement locked, Default false
1112
const emits = defineEmits(["parentAddItemBox"]);
13+
const {curComponentId, curComponent} = storeToRefs(dashboardStore)
1214
// @ts-ignore
1315
let currentInstance
1416
// Props
@@ -411,7 +413,7 @@ function getNextDragId() {
411413
if (validIds.length === 0) {
412414
return 0;
413415
}
414-
//@ts-ignore
416+
//@ts-ignore
415417
const maxDragId = Math.max(...validIds);
416418
return maxDragId + 1;
417419
}
@@ -420,7 +422,7 @@ function addItem(item: CanvasItem, index: any) {
420422
if (index < 0) {
421423
index = canvasComponentData.value.length
422424
}
423-
item._dragId = getNextDragId()
425+
item._dragId = item.id || getNextDragId()
424426
checkItemPosition(item, {x: item.x, y: item.y})
425427
emptyTargetCell(item)
426428
addItemToPositionBox(item)
@@ -702,15 +704,23 @@ function startResize(e: MouseEvent, point: string, item: CanvasItem, index: numb
702704
infoBox.value.point = point
703705
}
704706
707+
function containerClick() {
708+
// remove current component info
709+
dashboardStore.setCurComponent(null)
710+
}
711+
705712
function containerMouseDown(e: MouseEvent) {
706-
// e.preventDefault();
707713
if (!infoBox.value) {
708714
infoBox.value = {} // Reinitialize
709715
}
710716
infoBox.value.startX = e.pageX
711717
infoBox.value.startY = e.pageY
712-
e.preventDefault()
713-
e.stopPropagation()
718+
// @ts-ignore
719+
if (curComponent.value?.component !== 'SQText') {
720+
e.preventDefault()
721+
e.stopPropagation()
722+
}
723+
714724
}
715725
716726
function getNowPosition(addSizeX: number, addSizeY: number, moveXSize: number, moveYSize: number) {
@@ -959,6 +969,7 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
959969
window.removeEventListener('mouseup', itemMouseUp)
960970
}
961971
972+
// This will prevent click events from being passed to the parent level
962973
window.addEventListener('mouseup', itemMouseUp)
963974
}
964975
@@ -1147,10 +1158,12 @@ defineExpose({
11471158
</script>
11481159

11491160
<template>
1150-
<div class="dragAndResize" ref="containerRef" @mousedown="containerMouseDown($event)" @mouseup="endMove()"
1161+
<div class="dragAndResize" ref="containerRef" @click="containerClick" @mousedown="containerMouseDown($event)"
1162+
@mouseup="endMove()"
11511163
@mousemove="moving()">
11521164
<template v-if="renderOk">
11531165
<CanvasShape v-for="(item, index) in canvasComponentData"
1166+
:active="curComponentId === item.id"
11541167
:config-item="item"
11551168
:draggable="draggable"
11561169
:item-index="index"

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const props = defineProps({
1010
type: Object as PropType<CanvasItem>,
1111
required: true
1212
},
13+
active: {
14+
type: Boolean,
15+
default: false
16+
},
1317
itemIndex: {
1418
type: Number,
1519
required: true
@@ -37,18 +41,23 @@ const props = defineProps({
3741
})
3842
3943
const { draggable } = toRefs(props)
44+
const shapeClick = (e: MouseEvent) => {
45+
e.stopPropagation()
46+
e.preventDefault()
47+
}
4048
</script>
4149

4250
<template>
4351
<div :class="{
4452
item: true,
53+
itemActive: active,
4554
itemCursorDefault: configItem.component === 'SQTab',
4655
moveAnimation: moveAnimate,
4756
movingItem: configItem.isPlayer,
4857
canNotDrag: !draggable
49-
}" @mousedown="startMove($event, configItem, itemIndex)" ref="shapeRef">
58+
}" @click="shapeClick" @mousedown="startMove($event, configItem, itemIndex)" ref="shapeRef">
5059
<slot></slot>
51-
<resize-handle
60+
<resize-handle v-if="active"
5261
:start-resize="(event : MouseEvent, point: string) => startResize(event, point, configItem, itemIndex)">
5362
</resize-handle>
5463
</div>

frontend/src/views/dashboard/components/component-list.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const COMPONENT_LIST = [
1212
icon: 'icon_graphical',
1313
innerType: 'bar',
1414
locked: false,
15+
editing: false,
1516
x: 1,
1617
y: 1,
1718
sizeX: 36,
@@ -36,6 +37,7 @@ const COMPONENT_LIST = [
3637
}
3738
],
3839
canvasActive: false,
40+
editing: false,
3941
x: 1,
4042
y: 1,
4143
sizeX: 36,
@@ -47,7 +49,8 @@ const COMPONENT_LIST = [
4749
component: 'SQText',
4850
name: 'new text',
4951
locked: false,
50-
propValue: '&nbsp;',
52+
propValue: 'Double click to edit text',
53+
editing: false,
5154
x: 1,
5255
y: 1,
5356
sizeX: 36,

frontend/src/views/dashboard/components/sq-tab/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ defineExpose({
220220
position: absolute;
221221
width: 100%;
222222
height: 100%;
223+
margin: 2px!important;// border size
223224
}
224225
225226
.tab-dashboard-editor-main{

frontend/src/views/dashboard/components/sq-text/SQRichText.vue

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)