213 lines
6.4 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-radio-group v-model:value="layerMode" name="radiobuttongroup1" size="small" class="go-flex-center">
<n-radio-button value="thumbnail">
<n-icon size="16" class="go-d-block" title="缩略图" :depth="2" :component="ImageIcon" />
</n-radio-button>
<n-radio-button value="text">
<n-icon size="16" class="go-d-block" title="文字列表" :depth="2" :component="ListIcon" />
</n-radio-button>
</n-radio-group>
<!-- <n-icon
size="16"
class="go-cursor-pointer go-d-block"
title="缩略图"
:depth="2"
:component="ImageIcon"
:class="{ 'go-layer-mode-active': layerMode === 'thumbnail' }"
/>
<n-icon
size="16"
class="go-cursor-pointer go-d-block"
title="文字列表"
:depth="2"
:component="ListIcon"
:class="{ 'go-layer-mode-active': layerMode === 'text' }"
/> -->
</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"></layers-group-list-item>
<!-- 单组件 -->
<layers-list-item
v-else
:componentData="element"
@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'
2022-01-08 21:01:52 +08:00
import { icon } from '@/plugins'
2022-01-28 21:17:49 +08:00
2022-09-27 20:14:00 +08:00
const { LayersIcon, ImageIcon, 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>([])
2022-09-27 20:14:00 +08:00
const layerMode = ref<'thumbnail' | 'text'>('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) {
const list: MenuOptionsItemType[] = []
targetList.forEach(item => {
// 成组
if (item.key === MenuEnum.GROUP) {
list.push(item)
}
})
return list
}
return targetList
}
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>
2022-09-27 20:14:00 +08:00
$wight: 180px;
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>