index.vue
6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<template>
<content-box
class="go-content-layers"
:class="{ scoped: !chartLayoutStore.getLayers }"
title="图层"
:depth="2"
@back="backHandle"
@mousedown="boxMousedownHandle($event)"
>
<template #icon>
<n-icon size="16" :depth="2" :component="LayersIcon" />
</template>
<template #top-right>
<n-button-group style="display: flex">
<n-button
v-for="(item, index) in layerModeList"
:key="index"
ghost
size="small"
:type="layerMode === item.value ? 'primary' : 'tertiary'"
@click="changeLayerType(item.value)"
>
<n-tooltip :show-arrow="false" trigger="hover">
<template #trigger>
<n-icon size="14" :component="item.icon" />
</template>
{{ item.label }}
</n-tooltip>
</n-button>
</n-button-group>
</template>
<!-- 图层内容 -->
<n-space v-if="reverseList.length === 0" justify="center">
<n-text class="not-layer-text">暂无图层~</n-text>
</n-space>
<!-- https://github.com/SortableJS/vue.draggable.next -->
<draggable item-key="id" v-model="layerList" ghostClass="ghost" @change="onMoveCallback">
<template #item="{ element }">
<div class="go-content-layer-box">
<!-- 组合 -->
<layers-group-list-item
v-if="element.isGroup"
:componentGroupData="element"
:layer-mode="layerMode"
></layers-group-list-item>
<!-- 单组件 -->
<layers-list-item
v-else
:componentData="element"
:layer-mode="layerMode"
@mousedown="mousedownHandle($event, element)"
@mouseenter="mouseenterHandle(element)"
@mouseleave="mouseleaveHandle(element)"
@contextmenu="handleContextMenu($event, element, optionsHandle)"
></layers-list-item>
</div>
</template>
</draggable>
</content-box>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import Draggable from 'vuedraggable'
import cloneDeep from 'lodash/cloneDeep'
import { ContentBox } from '../ContentBox/index'
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
import { ChartLayoutStoreEnum, LayerModeEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
import { MenuOptionsItemType } from '@/views/chart/hooks/useContextMenu.hook.d'
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { MenuEnum, MouseEventButton, WinKeyboard, MacKeyboard } from '@/enums/editPageEnum'
import { LayersListItem } from './components/LayersListItem/index'
import { LayersGroupListItem } from './components/LayersGroupListItem/index'
import { icon } from '@/plugins'
const { LayersIcon, GridIcon, ListIcon } = icon.ionicons5
const { LaptopIcon } = icon.carbon
const chartLayoutStore = useChartLayoutStore()
const chartEditStore = useChartEditStore()
const { handleContextMenu, onClickOutSide } = useContextMenu()
const layerModeList = [
{ label: '缩略图', icon: LaptopIcon, value: LayerModeEnum.THUMBNAIL },
{ label: '文本列表', icon: ListIcon, value: LayerModeEnum.TEXT }
]
const layerList = ref<any>([])
const layerMode = ref<LayerModeEnum>(chartLayoutStore.getLayerType)
// 逆序展示
const reverseList = computed(() => {
const list: Array<CreateComponentType | CreateComponentGroupType> = cloneDeep(chartEditStore.getComponentList)
return list.reverse()
})
watch(
() => reverseList.value,
newValue => {
layerList.value = newValue
}
)
// 右键事件
const optionsHandle = (
targetList: MenuOptionsItemType[],
allList: MenuOptionsItemType[],
targetInstance: CreateComponentType
) => {
// 多选处理
if (chartEditStore.getTargetChart.selectId.length > 1) {
return targetList.filter(i => i.key === MenuEnum.GROUP)
}
const statusMenuEnums: MenuEnum[] = []
// 处理锁定与隐藏
if (targetInstance.status.lock) {
statusMenuEnums.push(MenuEnum.LOCK)
} else {
statusMenuEnums.push(MenuEnum.UNLOCK)
}
if (targetInstance.status.hide) {
statusMenuEnums.push(MenuEnum.HIDE)
} else {
statusMenuEnums.push(MenuEnum.SHOW)
}
return targetList.filter(item => !statusMenuEnums.includes(item.key as MenuEnum))
}
// 缩小
const backHandle = () => {
chartLayoutStore.setItem(ChartLayoutStoreEnum.LAYERS, false)
}
// 移动结束处理
const onMoveCallback = (val: any) => {
const { oldIndex, newIndex } = val.moved
if (newIndex - oldIndex > 0) {
// 从上往下
const moveTarget = chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)[0]
chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
} else {
// 从下往上
const moveTarget = chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)[0]
if (newIndex === 0) {
chartEditStore.getComponentList.push(moveTarget)
} else {
chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
}
}
}
const boxMousedownHandle = (e: MouseEvent) => {
const box = document.querySelector('.go-content-layer-box')
if ((e.target as any).contains(box)) {
chartEditStore.setTargetSelectChart()
}
}
// 点击事件
const mousedownHandle = (e: MouseEvent, item: CreateComponentType) => {
onClickOutSide()
// 若此时按下了 CTRL, 表示多选
const id = item.id
if (e.buttons === MouseEventButton.LEFT && window.$KeyboardActive?.ctrl) {
// 若已选中,则去除
if (chartEditStore.getTargetChart.selectId.includes(id)) {
const exList = chartEditStore.getTargetChart.selectId.filter(e => e !== id)
chartEditStore.setTargetSelectChart(exList)
} else {
chartEditStore.setTargetSelectChart(id, true)
}
return
}
chartEditStore.setTargetSelectChart(id)
}
// 进入事件
const mouseenterHandle = (item: CreateComponentType) => {
chartEditStore.setTargetHoverChart(item.id)
}
// 移出事件
const mouseleaveHandle = (item: CreateComponentType) => {
chartEditStore.setTargetHoverChart(undefined)
}
// 修改图层展示方式
const changeLayerType = (value: LayerModeEnum) => {
layerMode.value = value
chartLayoutStore.setItem(ChartLayoutStoreEnum.LAYER_TYPE, value)
}
</script>
<style lang="scss" scoped>
$wight: 200px;
@include go('content-layers') {
width: $wight;
overflow: hidden;
@extend .go-transition;
.not-layer-text {
position: relative;
top: 10px;
white-space: nowrap;
opacity: 0.4;
}
&.scoped {
width: 0;
}
.ghost {
opacity: 0;
}
.go-layer-mode-active {
color: #51d6a9;
}
}
</style>