fix: 解决部分图表改成层级丢失响应式的 bug

This commit is contained in:
奔跑的面条 2022-09-11 01:26:55 +08:00
parent e1521a31ac
commit 99aea4b9d3

View File

@ -17,7 +17,7 @@
<n-text class="not-layer-text">暂无图层~</n-text> <n-text class="not-layer-text">暂无图层~</n-text>
</n-space> </n-space>
<!-- https://github.com/SortableJS/vue.draggable.next --> <!-- https://github.com/SortableJS/vue.draggable.next -->
<draggable item-key="id" v-model="reverseList" ghostClass="ghost" @change="onMoveCallback"> <draggable item-key="id" v-model="layerList" ghostClass="ghost" @change="onMoveCallback">
<template #item="{ element }"> <template #item="{ element }">
<div class="go-content-layer-box"> <div class="go-content-layer-box">
<!-- 组合 --> <!-- 组合 -->
@ -27,7 +27,7 @@
v-else v-else
:componentData="element" :componentData="element"
@mousedown="mousedownHandle($event, element)" @mousedown="mousedownHandle($event, element)"
@mouseenter="mouseenterHandle(element)" @mouseenter="mouseenterHandle(element)"
@mouseleave="mouseleaveHandle(element)" @mouseleave="mouseleaveHandle(element)"
@contextmenu="handleContextMenu($event, element, optionsHandle)" @contextmenu="handleContextMenu($event, element, optionsHandle)"
></layers-list-item> ></layers-list-item>
@ -38,7 +38,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, toRaw } from 'vue' import { computed, ref, watch } from 'vue'
import Draggable from 'vuedraggable' import Draggable from 'vuedraggable'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
import { ContentBox } from '../ContentBox/index' import { ContentBox } from '../ContentBox/index'
@ -58,9 +58,23 @@ import { icon } from '@/plugins'
const { LayersIcon } = icon.ionicons5 const { LayersIcon } = icon.ionicons5
const chartLayoutStore = useChartLayoutStore() const chartLayoutStore = useChartLayoutStore()
const chartEditStore = useChartEditStore() const chartEditStore = useChartEditStore()
const { handleContextMenu, onClickOutSide } = useContextMenu() const { handleContextMenu, onClickOutSide } = useContextMenu()
const layerList = ref<any>([])
//
const reverseList = computed(() => {
const list: Array<CreateComponentType | CreateComponentGroupType> = cloneDeep(chartEditStore.getComponentList)
return list.reverse()
})
watch(
() => reverseList.value,
newValue => {
layerList.value = newValue
}
)
// //
const optionsHandle = ( const optionsHandle = (
targetList: MenuOptionsItemType[], targetList: MenuOptionsItemType[],
@ -80,12 +94,6 @@ const optionsHandle = (
} }
return targetList return targetList
} }
//
const reverseList = computed(() => {
const list: Array<CreateComponentType | CreateComponentGroupType> = cloneDeep(chartEditStore.getComponentList)
return list.reverse()
})
// //
const backHandle = () => { const backHandle = () => {
@ -95,14 +103,13 @@ const backHandle = () => {
// //
const onMoveCallback = (val: any) => { const onMoveCallback = (val: any) => {
const { oldIndex, newIndex } = val.moved const { oldIndex, newIndex } = val.moved
const moveTarget = toRaw(val.moved.element)
if (newIndex - oldIndex > 0) { if (newIndex - oldIndex > 0) {
// //
chartEditStore.getComponentList.splice(-(oldIndex + 1), 1) const moveTarget = chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)[0]
chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget) chartEditStore.getComponentList.splice(-newIndex, 0, moveTarget)
} else { } else {
// //
chartEditStore.getComponentList.splice(-(oldIndex + 1), 1) const moveTarget = chartEditStore.getComponentList.splice(-(oldIndex + 1), 1)[0]
if (newIndex === 0) { if (newIndex === 0) {
chartEditStore.getComponentList.push(moveTarget) chartEditStore.getComponentList.push(moveTarget)
} else { } else {