127 lines
3.5 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"
>
<template #icon>
<n-icon size="16" :depth="2">
<component :is="LayersIcon"></component>
2022-01-08 21:01:52 +08:00
</n-icon>
</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-04-03 15:06:32 +08:00
<!-- https://github.com/SortableJS/vue.draggable.next -->
<draggable
item-key="id"
tag="transition-group"
v-model="reverseList"
ghostClass="ghost"
@change="onMoveCallback"
>
<template #item="{ element }">
<layers-list-item
:componentData="element"
@mousedown="mousedownHandle(element)"
@mouseenter="mouseenterHandle(element)"
@mouseleave="mouseleaveHandle(element)"
@contextmenu="handleContextMenu($event, element)"
></layers-list-item>
</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">
2022-04-03 15:06:32 +08:00
import { computed, toRaw, ref, watch } from 'vue'
import Draggable from 'vuedraggable'
import cloneDeep from 'lodash/cloneDeep'
2022-03-10 14:57:34 +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'
2022-01-29 21:44:22 +08:00
import { CreateComponentType } from '@/packages/index.d'
2022-03-28 17:17:44 +08:00
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { MenuEnum } 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'
2022-01-08 21:01:52 +08:00
import { icon } from '@/plugins'
2022-01-28 21:17:49 +08:00
2022-01-08 21:01:52 +08:00
const { LayersIcon } = icon.ionicons5
const chartLayoutStore = useChartLayoutStore()
2022-03-04 20:57:36 +08:00
const chartEditStore = useChartEditStore()
2022-02-07 20:55:40 +08:00
2022-03-28 17:17:44 +08:00
const { handleContextMenu } = useContextMenu()
2022-01-28 21:17:49 +08:00
2022-04-03 15:06:32 +08:00
// 逆序展示
2022-03-14 19:56:09 +08:00
const reverseList = computed(() => {
2022-02-07 21:02:49 +08:00
const list: CreateComponentType[] = cloneDeep(chartEditStore.getComponentList)
return list.reverse()
})
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
const moveTarget = toRaw(val.moved.element)
if (newIndex - oldIndex > 0) {
// 从上往下
chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)
chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
} else {
// 从下往上
chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)
if (newIndex === 0) {
chartEditStore.getComponentList.push(moveTarget)
} else {
chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
}
}
}
2022-01-29 21:44:22 +08:00
// 点击事件
const mousedownHandle = (item: CreateComponentType) => {
chartEditStore.setTargetSelectChart(item.id)
}
// 进入事件
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-01-29 21:44:22 +08:00
$wight: 170px;
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;
opacity: .4;
}
2022-01-08 21:01:52 +08:00
&.scoped {
width: 0;
}
2022-04-03 15:06:32 +08:00
.ghost {
opacity: 0;
}
2022-01-06 13:45:51 +08:00
}
</style>