Skip to content

Commit 152773b

Browse files
committed
feat: dashboard tab move out
1 parent 167aacb commit 152773b

File tree

7 files changed

+159
-103
lines changed

7 files changed

+159
-103
lines changed

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

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {findComponent} from "@/views/dashboard/components/component-list.ts";
88
99
const dashboardStore = dashboardStoreWithOut()
1010
const canvasLocked = ref(false) // Is the canvas movement locked, Default false
11+
const emits = defineEmits(["parentAddItemBox"]);
1112
// @ts-ignore
1213
let currentInstance
1314
// Props
@@ -400,11 +401,26 @@ function removeItem(index: number) {
400401
canvasComponentData.value.splice(index, 1)
401402
}
402403
404+
function getNextDragId() {
405+
if (!canvasComponentData.value || canvasComponentData.value.length === 0) {
406+
return 0;
407+
}
408+
//@ts-ignore
409+
const validIds = canvasComponentData.value.map(item => item._dragId).filter(id => id != null && id !== ''); // 过滤 null、undefined 和空字符串
410+
411+
if (validIds.length === 0) {
412+
return 0;
413+
}
414+
//@ts-ignore
415+
const maxDragId = Math.max(...validIds);
416+
return maxDragId + 1;
417+
}
418+
403419
function addItem(item: CanvasItem, index: any) {
404420
if (index < 0) {
405421
index = canvasComponentData.value.length
406422
}
407-
item._dragId = index
423+
item._dragId = getNextDragId()
408424
checkItemPosition(item, {x: item.x, y: item.y})
409425
emptyTargetCell(item)
410426
addItemToPositionBox(item)
@@ -899,15 +915,25 @@ function startMove(e: MouseEvent, item: CanvasItem, index: number) {
899915
if (canvasLocked.value) {
900916
const moveItem = infoBox.value.moveItem
901917
// Get the SQTab currently being moved in
902-
const curActiveSQTab = canvasComponentData?.value.find(item => item.component === 'SQTab' && item.moveInActive === true);
903-
if (curActiveSQTab) {
904-
// @ts-ignore
905-
const refTabInstance = currentInstance.refs['shape_component_' + curActiveSQTab.id][0]
906-
refTabInstance.addTabItem(moveItem)
918+
const curActiveMoveInSQTab = canvasComponentData?.value.find(item => item.component === 'SQTab' && item.collisionActive === true);
919+
if (curActiveMoveInSQTab) {
920+
if (curActiveMoveInSQTab.moveInActive) {
921+
// @ts-ignore
922+
const refTabInstance = currentInstance.refs['shape_component_' + curActiveMoveInSQTab.id][0]
923+
refTabInstance.addTabItem(moveItem)
924+
removeItemById(moveItem.id)
925+
}
926+
curActiveMoveInSQTab.collisionActive = false
927+
curActiveMoveInSQTab.moveInActive = false
928+
}
929+
930+
// move out
931+
if (props.parentConfigItem && props.parentConfigItem.moveOutActive) {
932+
emits('parentAddItemBox', _.cloneDeep(moveItem))
907933
removeItemById(moveItem.id)
908-
curActiveSQTab.collisionActive = false
909-
curActiveSQTab.moveInActive = false
934+
props.parentConfigItem.moveOutActive = false
910935
}
936+
911937
}
912938
canvasLocked.value = false
913939
}
@@ -1045,6 +1071,7 @@ function tabMoveOutCheckSQ() {
10451071
const top = cloneItem.offsetTop
10461072
const {tw} = getItemStylePosition(props.parentConfigItem)
10471073
props.parentConfigItem.moveOutActive = left < -tabMoveOutXOffset || top < -tabMoveOutYOffset || (left + width - tw) > tabMoveOutXOffset;
1074+
canvasLocked.value = props.parentConfigItem.moveOutActive
10481075
}
10491076
}
10501077
@@ -1135,7 +1162,8 @@ defineExpose({
11351162
<component :ref="'shape_component_'+item.id"
11361163
class="sql-component slot-component dragHandle"
11371164
:is="findComponent(item.component)"
1138-
:config-item="item">
1165+
:config-item="item"
1166+
@parentAddItemBox=" (subItem:any) => addItemBox(subItem)">
11391167
</component>
11401168
</CanvasShape>
11411169
</template>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const { draggable } = toRefs(props)
4242
<template>
4343
<div :class="{
4444
item: true,
45+
itemCursorDefault: configItem.component === 'SQTab',
4546
moveAnimation: moveAnimate,
4647
movingItem: configItem.isPlayer,
4748
canNotDrag: !draggable

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const shadowStyle = (size: number, index: number) => {
3232
height: `${size}px`
3333
}
3434
} else if (index === 3) {
35-
return {
35+
return {
3636
top: 0,
3737
left: 0,
3838
width: `${size}px`,
@@ -44,10 +44,15 @@ const shadowStyle = (size: number, index: number) => {
4444
</script>
4545

4646
<template>
47-
<div class="dragHandle" v-for="(size,index) in sizeList" :style="shadowStyle(size,index)"></div>
47+
<div class="dragHandle dragArea" v-for="(size,index) in sizeList" :style="shadowStyle(size,index)"></div>
4848
</template>
4949

5050
<style scoped lang="less">
51+
52+
.dragArea {
53+
opacity: 0.05;
54+
}
55+
5156
.dragHandle {
5257
background: #c1e2e8;
5358
position: absolute;

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const showTabTitleFlag = ref(true)
1212
let currentInstance
1313
import _ from 'lodash'
1414
15+
const emits = defineEmits(["parentAddItemBox"]);
16+
1517
const tabBaseMatrixCount = {
1618
x: 36,
1719
y: 12
@@ -130,7 +132,7 @@ defineExpose({
130132
</script>
131133

132134
<template>
133-
<div>
135+
<div :class="{'tab-moveout':configItem.moveOutActive}">
134136
<drag-handle></drag-handle>
135137
<custom-tab
136138
v-model="editableTabsValue"
@@ -142,7 +144,7 @@ defineExpose({
142144
:border-active-color="state.headBorderActiveColor"
143145
:hide-title="!showTabTitleFlag"
144146
>
145-
-------{{ configItem.collisionActive }} -- -- {{ configItem.moveInActive }}-- -- {{ configItem.moveOutActive }}
147+
<!-- {{ configItem.collisionActive }} & {{ configItem.moveInActive }}${{ configItem.moveOutActive }}-->
146148
<template :key="tabItem.name" v-for="tabItem in configItem.propValue">
147149
<el-tab-pane
148150
class="el-tab-pane-custom"
@@ -193,12 +195,14 @@ defineExpose({
193195
:class="{ 'switch-hidden': editableTabsValue !== tabItem.name }"
194196
>
195197
<DashboardEditor
198+
class="tab-dashboard-editor-main"
196199
:ref="'tabEditorRef_'+index"
197200
:canvas-component-data="tabItem.componentData"
198201
:move-in-active="configItem.moveInActive"
199202
:base-matrix-count="tabBaseMatrixCount"
200203
:canvas-id="tabItem.name"
201204
:parent-config-item="configItem"
205+
@parentAddItemBox=" item => emits('parentAddItemBox',item)"
202206
>
203207
</DashboardEditor>
204208
</div>
@@ -218,4 +222,18 @@ defineExpose({
218222
height: 100%;
219223
}
220224
225+
.tab-dashboard-editor-main{
226+
height: 100%!important;
227+
}
228+
229+
.tab-moveout {
230+
::v-deep(.ed-tabs__content) {
231+
overflow: visible !important;
232+
}
233+
234+
::v-deep(.dashboard-editor-main) {
235+
overflow: visible !important;
236+
}
237+
}
238+
221239
</style>
Lines changed: 87 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,104 @@
1-
.dragAndResize
2-
{
3-
position: relative;
4-
user-select: none;
5-
width: 100%;
6-
*
7-
{
8-
box-sizing: border-box;
9-
margin: 0;
10-
padding: 0;
11-
}
12-
.item
13-
{
14-
position: absolute;
15-
width: 100px;
16-
height: 100px;
17-
cursor: move;
18-
border: 1px solid #59c7f9;
19-
background-color: #fff;
20-
.resizeHandle
21-
{
22-
position: absolute;
23-
background: #fff;
24-
border: 1px solid #59c7f9;
25-
width: 8px;
26-
height: 8px;
27-
border-radius: 50%;
28-
z-index: 5;
29-
}
30-
.sql-component {
31-
width: 100%;
32-
height: 100%;
33-
}
34-
}
35-
.moveAnimation
36-
{
37-
transition: top 80ms ease;
1+
.dragAndResize {
2+
position: relative;
3+
user-select: none;
4+
width: 100%;
5+
6+
* {
7+
box-sizing: border-box;
8+
margin: 0;
9+
padding: 0;
10+
}
11+
12+
.itemCursorDefault {
13+
cursor: default!important;
14+
}
15+
.item {
16+
position: absolute;
17+
width: 100px;
18+
height: 100px;
19+
border: 1px solid #59c7f9;
20+
background-color: #fff;
21+
cursor: move;
22+
.resizeHandle {
23+
position: absolute;
24+
background: #fff;
25+
border: 1px solid #59c7f9;
26+
width: 8px;
27+
height: 8px;
28+
border-radius: 50%;
29+
z-index: 5;
3830
}
39-
.canNotDrag
40-
{
41-
cursor: default!important;
31+
32+
.sql-component {
33+
width: 100%;
34+
height: 100%;
4235
}
36+
}
37+
38+
.moveAnimation {
39+
transition: top 80ms ease;
40+
}
41+
42+
.canNotDrag {
43+
cursor: default !important;
44+
}
4345

44-
.cloneNode
45-
{
46-
z-index: 100;
46+
.cloneNode {
47+
z-index: 100;
4748

48-
transition: none;
49+
transition: none;
4950

50-
opacity: .5;
51+
opacity: .5;
52+
}
53+
54+
.movingItem {
55+
position: absolute;
56+
57+
border: none;
58+
59+
&:before {
60+
position: absolute;
61+
z-index: 2;
62+
top: 0;
63+
left: 0;
64+
width: 100%;
65+
height: 100%;
66+
content: '';
67+
background-color: #b8d3f9;
5168
}
5269

53-
.movingItem
54-
{
55-
position: absolute;
56-
57-
border: none;
58-
&:before
59-
{
60-
position: absolute;
61-
z-index: 2;
62-
top: 0;
63-
left: 0;
64-
width: 100%;
65-
height: 100%;
66-
content: '';
67-
background-color: #b8d3f9;
68-
}
69-
.resizeHandle
70-
{
71-
display: none;
72-
}
73-
.slot-component {
74-
display: none;
75-
}
70+
.resizeHandle {
71+
display: none;
7672
}
7773

78-
.positionBox
79-
{
80-
position: fixed;
81-
top: 0;
82-
right: 100px;
74+
.slot-component {
75+
display: none;
76+
}
77+
}
8378

84-
overflow: auto;
79+
.positionBox {
80+
position: fixed;
81+
top: 0;
82+
right: 100px;
8583

86-
width: 500px;
87-
height: 500px;
84+
overflow: auto;
8885

89-
border: 1px solid;
90-
}
86+
width: 500px;
87+
height: 500px;
9188

92-
.coords
93-
{
94-
position: fixed;
95-
right: 100px;
96-
bottom: 200px;
89+
border: 1px solid;
90+
}
9791

98-
overflow: auto;
92+
.coords {
93+
position: fixed;
94+
right: 100px;
95+
bottom: 200px;
9996

100-
width: 200px;
101-
height: 200px;
97+
overflow: auto;
10298

103-
border: 1px solid;
104-
}
99+
width: 200px;
100+
height: 200px;
101+
102+
border: 1px solid;
103+
}
105104
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ onMounted(() => {
8383
}
8484
})
8585
})
86+
const emits = defineEmits(["parentAddItemBox"]);
8687
</script>
8788

8889
<template>
@@ -99,6 +100,7 @@ onMounted(() => {
99100
:canvas-component-data="canvasComponentData"
100101
:parent-config-item="parentConfigItem"
101102
:canvas-id="canvasId"
103+
@parentAddItemBox=" item => emits('parentAddItemBox',item)"
102104
></CanvasCore>
103105
</div>
104106

0 commit comments

Comments
 (0)