index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <content-box
  3. class="go-content-layers"
  4. :class="{ scoped: !chartLayoutStore.getLayers }"
  5. title="图层"
  6. :depth="2"
  7. @back="backHandle"
  8. >
  9. <template #icon>
  10. <n-icon size="16" :depth="2">
  11. <component :is="LayersIcon"></component>
  12. </n-icon>
  13. </template>
  14. <!-- 图层内容 -->
  15. <n-space v-if="reverseList.length === 0" justify="center">
  16. <n-text class="not-layer-text">暂无图层~</n-text>
  17. </n-space>
  18. <!-- https://github.com/SortableJS/vue.draggable.next -->
  19. <draggable
  20. item-key="id"
  21. tag="transition-group"
  22. v-model="reverseList"
  23. ghostClass="ghost"
  24. @change="onMoveCallback"
  25. >
  26. <template #item="{ element }">
  27. <layers-list-item
  28. :componentData="element"
  29. @mousedown="mousedownHandle(element)"
  30. @mouseenter="mouseenterHandle(element)"
  31. @mouseleave="mouseleaveHandle(element)"
  32. @contextmenu="handleContextMenu($event, element)"
  33. ></layers-list-item>
  34. </template>
  35. </draggable>
  36. </content-box>
  37. </template>
  38. <script setup lang="ts">
  39. import { computed, toRaw, ref, watch } from 'vue'
  40. import Draggable from 'vuedraggable'
  41. import cloneDeep from 'lodash/cloneDeep'
  42. import { ContentBox } from '../contentBox/index'
  43. import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
  44. import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
  45. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  46. import { CreateComponentType } from '@/packages/index.d'
  47. import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
  48. import { MenuEnum } from '@/enums/editPageEnum'
  49. import { LayersListItem } from './components/LayersListItem/index'
  50. import { icon } from '@/plugins'
  51. const { LayersIcon } = icon.ionicons5
  52. const chartLayoutStore = useChartLayoutStore()
  53. const chartEditStore = useChartEditStore()
  54. const { handleContextMenu } = useContextMenu()
  55. // 逆序展示
  56. const reverseList = computed(() => {
  57. const list: CreateComponentType[] = cloneDeep(chartEditStore.getComponentList)
  58. return list.reverse()
  59. })
  60. // 缩小
  61. const backHandle = () => {
  62. chartLayoutStore.setItem(ChartLayoutStoreEnum.LAYERS, false)
  63. }
  64. // 移动结束处理
  65. const onMoveCallback = (val: any) => {
  66. const { oldIndex, newIndex } = val.moved
  67. const moveTarget = toRaw(val.moved.element)
  68. if (newIndex - oldIndex > 0) {
  69. // 从上往下
  70. chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)
  71. chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
  72. } else {
  73. // 从下往上
  74. chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)
  75. if (newIndex === 0) {
  76. chartEditStore.getComponentList.push(moveTarget)
  77. } else {
  78. chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
  79. }
  80. }
  81. }
  82. // 点击事件
  83. const mousedownHandle = (item: CreateComponentType) => {
  84. chartEditStore.setTargetSelectChart(item.id)
  85. }
  86. // 进入事件
  87. const mouseenterHandle = (item: CreateComponentType) => {
  88. chartEditStore.setTargetHoverChart(item.id)
  89. }
  90. // 移出事件
  91. const mouseleaveHandle = (item: CreateComponentType) => {
  92. chartEditStore.setTargetHoverChart(undefined)
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. $wight: 170px;
  97. @include go(content-layers) {
  98. width: $wight;
  99. flex-shrink: 0;
  100. overflow: hidden;
  101. @extend .go-transition;
  102. .not-layer-text {
  103. position: relative;
  104. top: 10px;
  105. white-space: nowrap;
  106. opacity: 0.4;
  107. }
  108. &.scoped {
  109. width: 0;
  110. }
  111. .ghost {
  112. opacity: 0;
  113. }
  114. }
  115. </style>