220 lines
6.6 KiB
Vue
Raw Normal View History

2022-01-06 13:45:51 +08:00
<template>
2022-03-14 19:52:01 +08:00
<content-box
2022-01-08 21:01:52 +08:00
class="go-content-layers"
:class="{ scoped: !chartLayoutStore.getLayers }"
title="图层"
2022-01-11 20:56:19 +08:00
:depth="2"
2022-01-08 21:01:52 +08:00
@back="backHandle"
@mousedown="boxMousedownHandle($event)"
2022-01-08 21:01:52 +08:00
>
<template #icon>
2022-09-27 20:14:00 +08:00
<n-icon size="16" :depth="2" :component="LayersIcon" />
2022-01-08 21:01:52 +08:00
</template>
2022-09-27 20:14:00 +08:00
<template #top-right>
<n-button-group style="display: flex">
<n-button
v-for="(item, index) in layerModeEnumList"
:key="index"
ghost
size="small"
:type="layerMode === item.value ? 'primary' : 'tertiary'"
@click="layerMode = item.value as LayerModeEnum"
>
<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>
2022-09-27 20:14:00 +08:00
</template>
2022-01-19 19:59:11 +08:00
<!-- 图层内容 -->
2022-04-06 19:55:31 +08:00
<n-space v-if="reverseList.length === 0" justify="center">
<n-text class="not-layer-text">暂无图层~</n-text>
</n-space>
2022-09-27 20:14:00 +08:00
2022-04-03 15:06:32 +08:00
<!-- https://github.com/SortableJS/vue.draggable.next -->
<draggable item-key="id" v-model="layerList" ghostClass="ghost" @change="onMoveCallback">
2022-04-03 15:06:32 +08:00
<template #item="{ element }">
2022-08-15 20:11:04 +08:00
<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)"
2022-08-13 18:38:36 +08:00
@contextmenu="handleContextMenu($event, element, optionsHandle)"
></layers-list-item>
</div>
2022-04-03 15:06:32 +08:00
</template>
</draggable>
2022-03-14 19:52:01 +08:00
</content-box>
2022-01-06 13:45:51 +08:00
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
2022-04-03 15:06:32 +08:00
import Draggable from 'vuedraggable'
import cloneDeep from 'lodash/cloneDeep'
2022-05-10 18:21:50 +08:00
import { ContentBox } from '../ContentBox/index'
2022-01-08 21:01:52 +08:00
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
2022-01-20 21:25:35 +08:00
import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
2022-03-04 20:57:36 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
2022-08-13 18:38:36 +08:00
import { MenuOptionsItemType } from '@/views/chart/hooks/useContextMenu.hook.d'
2022-03-28 17:17:44 +08:00
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { MenuEnum, MouseEventButton, WinKeyboard, MacKeyboard } from '@/enums/editPageEnum'
2022-01-29 21:44:22 +08:00
2022-03-14 19:56:09 +08:00
import { LayersListItem } from './components/LayersListItem/index'
import { LayersGroupListItem } from './components/LayersGroupListItem/index'
import { LayerModeEnum } from './index.d'
2022-01-08 21:01:52 +08:00
import { icon } from '@/plugins'
2022-01-28 21:17:49 +08:00
const { LayersIcon, ImageIcon, ImagesIcon, ListIcon } = icon.ionicons5
2022-01-08 21:01:52 +08:00
const chartLayoutStore = useChartLayoutStore()
2022-03-04 20:57:36 +08:00
const chartEditStore = useChartEditStore()
const { handleContextMenu, onClickOutSide } = useContextMenu()
2022-01-28 21:17:49 +08:00
const layerList = ref<any>([])
const layerModeEnumList = [
{ label: '缩略图', icon: ImagesIcon, value: 'thumbnail' },
{ label: '文本列表', icon: ListIcon, value: 'text' }
]
const layerMode = ref<LayerModeEnum>('thumbnail')
// 逆序展示
const reverseList = computed(() => {
const list: Array<CreateComponentType | CreateComponentGroupType> = cloneDeep(chartEditStore.getComponentList)
return list.reverse()
})
watch(
() => reverseList.value,
newValue => {
layerList.value = newValue
}
)
2022-08-13 18:38:36 +08:00
// 右键事件
const optionsHandle = (
targetList: MenuOptionsItemType[],
allList: MenuOptionsItemType[],
2022-08-14 01:04:03 +08:00
targetInstance: CreateComponentType
2022-08-13 18:38:36 +08:00
) => {
// 多选处理
if (chartEditStore.getTargetChart.selectId.length > 1) {
return targetList.filter(i => i.key === MenuEnum.GROUP)
2022-08-13 18:38:36 +08:00
}
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))
2022-08-13 18:38:36 +08:00
}
2022-02-07 21:02:49 +08:00
2022-04-03 15:06:32 +08:00
// 缩小
2022-01-08 21:01:52 +08:00
const backHandle = () => {
2022-01-20 21:25:35 +08:00
chartLayoutStore.setItem(ChartLayoutStoreEnum.LAYERS, false)
2022-01-08 21:01:52 +08:00
}
2022-01-29 21:44:22 +08:00
2022-04-03 15:06:32 +08:00
// 移动结束处理
const onMoveCallback = (val: any) => {
const { oldIndex, newIndex } = val.moved
if (newIndex - oldIndex > 0) {
// 从上往下
const moveTarget = chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)[0]
2022-04-03 15:06:32 +08:00
chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
} else {
// 从下往上
const moveTarget = chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)[0]
2022-04-03 15:06:32 +08:00
if (newIndex === 0) {
chartEditStore.getComponentList.push(moveTarget)
} else {
chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
}
}
}
const boxMousedownHandle = (e: MouseEvent) => {
2022-08-15 20:11:04 +08:00
const box = document.querySelector('.go-content-layer-box')
if ((e.target as any).contains(box)) {
chartEditStore.setTargetSelectChart()
}
}
2022-01-29 21:44:22 +08:00
// 点击事件
const mousedownHandle = (e: MouseEvent, item: CreateComponentType) => {
onClickOutSide()
// 若此时按下了 CTRL, 表示多选
const id = item.id
if (
e.buttons === MouseEventButton.LEFT &&
(window.$KeyboardActive?.has(WinKeyboard.CTRL_SOURCE_KEY) ||
window.$KeyboardActive?.has(MacKeyboard.CTRL_SOURCE_KEY))
) {
// 若已选中,则去除
if (chartEditStore.targetChart.selectId.includes(id)) {
const exList = chartEditStore.targetChart.selectId.filter(e => e !== id)
chartEditStore.setTargetSelectChart(exList)
} else {
chartEditStore.setTargetSelectChart(id, true)
}
return
}
chartEditStore.setTargetSelectChart(id)
2022-01-29 21:44:22 +08:00
}
// 进入事件
const mouseenterHandle = (item: CreateComponentType) => {
chartEditStore.setTargetHoverChart(item.id)
}
// 移出事件
const mouseleaveHandle = (item: CreateComponentType) => {
chartEditStore.setTargetHoverChart(undefined)
}
2022-01-06 13:45:51 +08:00
</script>
<style lang="scss" scoped>
$wight: 200px;
2022-01-06 13:45:51 +08:00
@include go(content-layers) {
width: $wight;
2022-01-28 21:17:49 +08:00
flex-shrink: 0;
2022-01-08 21:01:52 +08:00
overflow: hidden;
@extend .go-transition;
2022-04-06 19:55:31 +08:00
.not-layer-text {
position: relative;
top: 10px;
2022-04-06 21:53:00 +08:00
white-space: nowrap;
2022-04-07 19:33:14 +08:00
opacity: 0.4;
2022-04-06 19:55:31 +08:00
}
2022-01-08 21:01:52 +08:00
&.scoped {
width: 0;
}
2022-04-03 15:06:32 +08:00
.ghost {
opacity: 0;
}
2022-09-27 20:14:00 +08:00
.go-layer-mode-active {
color: #51d6a9;
}
2022-01-06 13:45:51 +08:00
}
</style>