Merge pull request #11886 from dataease/pr@dev-v2@refactor_batch-move
refactor(数据大屏): 优化批量上移下移置顶置底等批操作位移逻辑
This commit is contained in:
commit
114637a735
@ -119,7 +119,13 @@ const deleteComponent = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const upComponent = () => {
|
const upComponent = () => {
|
||||||
layerStore.upComponent()
|
if (curComponent.value && !isGroupArea.value) {
|
||||||
|
layerStore.upComponent(curComponent.value.id)
|
||||||
|
} else if (areaData.value.components.length) {
|
||||||
|
areaData.value.components.forEach(component => {
|
||||||
|
layerStore.upComponent(component.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
snapshotStore.recordSnapshotCache('upComponent')
|
snapshotStore.recordSnapshotCache('upComponent')
|
||||||
menuOpt('upComponent')
|
menuOpt('upComponent')
|
||||||
}
|
}
|
||||||
@ -131,13 +137,25 @@ const downComponent = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const topComponent = () => {
|
const topComponent = () => {
|
||||||
layerStore.topComponent()
|
if (curComponent.value && !isGroupArea.value) {
|
||||||
|
layerStore.topComponent(curComponent.value.id)
|
||||||
|
} else if (areaData.value.components.length) {
|
||||||
|
areaData.value.components.forEach(component => {
|
||||||
|
layerStore.topComponent(component.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
snapshotStore.recordSnapshotCache('topComponent')
|
snapshotStore.recordSnapshotCache('topComponent')
|
||||||
menuOpt('topComponent')
|
menuOpt('topComponent')
|
||||||
}
|
}
|
||||||
|
|
||||||
const bottomComponent = () => {
|
const bottomComponent = () => {
|
||||||
layerStore.bottomComponent()
|
if (curComponent.value && !isGroupArea.value) {
|
||||||
|
layerStore.bottomComponent(curComponent.value.id)
|
||||||
|
} else if (areaData.value.components.length) {
|
||||||
|
areaData.value.components.forEach(component => {
|
||||||
|
layerStore.bottomComponent(component.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
snapshotStore.recordSnapshotCache('bottomComponent')
|
snapshotStore.recordSnapshotCache('bottomComponent')
|
||||||
menuOpt('bottomComponent')
|
menuOpt('bottomComponent')
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,20 +3,37 @@ import { dvMainStoreWithOut } from './dvMain'
|
|||||||
const dvMainStore = dvMainStoreWithOut()
|
const dvMainStore = dvMainStoreWithOut()
|
||||||
const { curComponent, componentData } = storeToRefs(dvMainStore)
|
const { curComponent, componentData } = storeToRefs(dvMainStore)
|
||||||
|
|
||||||
export const getCurInfo = () => {
|
export const getComponentById = (componentId?) => {
|
||||||
if (curComponent.value) {
|
const curInfo = getCurInfo(componentId)
|
||||||
const curComponentId = curComponent.value.id
|
if (curInfo) {
|
||||||
|
return curInfo.targetComponent
|
||||||
|
} else return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getCurInfo = (componentId?) => {
|
||||||
|
if (componentId) {
|
||||||
|
return getCurInfoById(componentId)
|
||||||
|
} else if (curComponent.value) {
|
||||||
|
return getCurInfoById(curComponent.value.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getCurInfoById = curComponentId => {
|
||||||
|
if (curComponentId) {
|
||||||
let curIndex = 0
|
let curIndex = 0
|
||||||
let curTabIndex = 0
|
let curTabIndex = 0
|
||||||
let curComponentData = componentData.value
|
let curComponentData = componentData.value
|
||||||
|
let targetComponent = null
|
||||||
componentData.value.forEach((component, index) => {
|
componentData.value.forEach((component, index) => {
|
||||||
if (curComponentId === component.id) {
|
if (curComponentId === component.id) {
|
||||||
curIndex = index
|
curIndex = index
|
||||||
|
targetComponent = component
|
||||||
}
|
}
|
||||||
if (component.component === 'Group') {
|
if (component.component === 'Group') {
|
||||||
component.propValue.forEach((subComponent, subIndex) => {
|
component.propValue.forEach((subComponent, subIndex) => {
|
||||||
if (curComponentId === subComponent.id) {
|
if (curComponentId === subComponent.id) {
|
||||||
curIndex = subIndex
|
curIndex = subIndex
|
||||||
|
targetComponent = subComponent
|
||||||
curComponentData = component.propValue
|
curComponentData = component.propValue
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -27,6 +44,7 @@ export const getCurInfo = () => {
|
|||||||
tabItem.componentData.forEach((tabComponent, subIndex) => {
|
tabItem.componentData.forEach((tabComponent, subIndex) => {
|
||||||
if (curComponentId === tabComponent.id) {
|
if (curComponentId === tabComponent.id) {
|
||||||
curIndex = subIndex
|
curIndex = subIndex
|
||||||
|
targetComponent = tabComponent
|
||||||
curComponentData = tabItem.componentData
|
curComponentData = tabItem.componentData
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -36,6 +54,7 @@ export const getCurInfo = () => {
|
|||||||
return {
|
return {
|
||||||
index: curIndex,
|
index: curIndex,
|
||||||
tabIndex: curTabIndex,
|
tabIndex: curTabIndex,
|
||||||
|
targetComponent: targetComponent,
|
||||||
componentData: curComponentData
|
componentData: curComponentData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,15 +3,15 @@ import { store } from '../../index'
|
|||||||
import { dvMainStoreWithOut } from './dvMain'
|
import { dvMainStoreWithOut } from './dvMain'
|
||||||
import { swap } from '@/utils/utils'
|
import { swap } from '@/utils/utils'
|
||||||
import { useEmitt } from '@/hooks/web/useEmitt'
|
import { useEmitt } from '@/hooks/web/useEmitt'
|
||||||
import { getCurInfo } from '@/store/modules/data-visualization/common'
|
import { getComponentById, getCurInfo } from '@/store/modules/data-visualization/common'
|
||||||
|
|
||||||
const dvMainStore = dvMainStoreWithOut()
|
const dvMainStore = dvMainStoreWithOut()
|
||||||
const { curComponentIndex, curComponent } = storeToRefs(dvMainStore)
|
const { curComponentIndex, curComponent } = storeToRefs(dvMainStore)
|
||||||
|
|
||||||
export const layerStore = defineStore('layer', {
|
export const layerStore = defineStore('layer', {
|
||||||
actions: {
|
actions: {
|
||||||
upComponent() {
|
upComponent(componentId?) {
|
||||||
const curInfo = getCurInfo()
|
const curInfo = getCurInfo(componentId)
|
||||||
if (curInfo) {
|
if (curInfo) {
|
||||||
const { index, componentData } = curInfo
|
const { index, componentData } = curInfo
|
||||||
// 上移图层 index,表示元素在数组中越往后
|
// 上移图层 index,表示元素在数组中越往后
|
||||||
@ -22,8 +22,8 @@ export const layerStore = defineStore('layer', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
downComponent() {
|
downComponent(componentId?) {
|
||||||
const curInfo = getCurInfo()
|
const curInfo = getCurInfo(componentId)
|
||||||
if (curInfo) {
|
if (curInfo) {
|
||||||
const { index, componentData } = curInfo
|
const { index, componentData } = curInfo
|
||||||
// 下移图层 index,表示元素在数组中越往前
|
// 下移图层 index,表示元素在数组中越往前
|
||||||
@ -34,51 +34,53 @@ export const layerStore = defineStore('layer', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
topComponent() {
|
topComponent(componentId?) {
|
||||||
// 置顶
|
// 置顶
|
||||||
const curInfo = getCurInfo()
|
const curInfo = getCurInfo(componentId)
|
||||||
if (curInfo) {
|
if (curInfo) {
|
||||||
const { index, componentData } = curInfo
|
const { index, componentData, targetComponent } = curInfo
|
||||||
if (index < componentData.length - 1) {
|
if (index < componentData.length - 1) {
|
||||||
componentData.splice(curComponentIndex.value, 1)
|
componentData.splice(targetComponent, 1)
|
||||||
componentData.push(curComponent.value)
|
componentData.push(targetComponent)
|
||||||
curComponentIndex.value = componentData.length - 1
|
curComponentIndex.value = componentData.length - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
bottomComponent() {
|
bottomComponent(componentId?) {
|
||||||
// 置底
|
// 置底
|
||||||
const curInfo = getCurInfo()
|
const curInfo = getCurInfo(componentId)
|
||||||
if (curInfo) {
|
if (curInfo) {
|
||||||
const { index, componentData } = curInfo
|
const { index, componentData, targetComponent } = curInfo
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
componentData.splice(index, 1)
|
componentData.splice(index, 1)
|
||||||
componentData.unshift(curComponent.value)
|
componentData.unshift(targetComponent)
|
||||||
curComponentIndex.value = 0
|
curComponentIndex.value = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hideComponent() {
|
hideComponent(componentId?) {
|
||||||
|
const targetComponent = getComponentById(componentId)
|
||||||
// 隐藏
|
// 隐藏
|
||||||
if (curComponent && curComponent.value) {
|
if (targetComponent) {
|
||||||
curComponent.value.isShow = false
|
targetComponent.isShow = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showComponent() {
|
showComponent(componentId?) {
|
||||||
// 显示
|
// 显示
|
||||||
if (curComponent && curComponent.value) {
|
const targetComponent = getComponentById(componentId)
|
||||||
curComponent.value.isShow = true
|
if (targetComponent) {
|
||||||
if (curComponent.value.component == 'Group') {
|
targetComponent.isShow = true
|
||||||
curComponent.value.propValue.forEach(item => {
|
if (targetComponent.component == 'Group') {
|
||||||
|
targetComponent.propValue.forEach(item => {
|
||||||
if (item.innerType?.indexOf('table') !== -1) {
|
if (item.innerType?.indexOf('table') !== -1) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
useEmitt().emitter.emit('renderChart-' + item.id)
|
useEmitt().emitter.emit('renderChart-' + item.id)
|
||||||
}, 400)
|
}, 400)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (curComponent.value?.innerType?.indexOf('table') !== -1) {
|
} else if (targetComponent?.innerType?.indexOf('table') !== -1) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
useEmitt().emitter.emit('renderChart-' + curComponent.value.id)
|
useEmitt().emitter.emit('renderChart-' + curComponent.value.id)
|
||||||
}, 400)
|
}, 400)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user