fix(仪表板): 修复有隐藏组件时,tab移入后主画布组件未删除问题

This commit is contained in:
wangjiahao
2025-02-13 17:10:14 +08:00
committed by 王嘉豪
parent 2d4eea233f
commit 0e092ab66e
2 changed files with 32 additions and 12 deletions

View File

@@ -161,7 +161,12 @@ import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { storeToRefs } from 'pinia'
import { guid } from '@/views/visualized/data/dataset/form/util'
import eventBus from '@/utils/eventBus'
import { canvasChangeAdaptor, findComponentIndexById, isDashboard } from '@/utils/canvasUtils'
import {
canvasChangeAdaptor,
findComponentIndexById,
findComponentIndexByIdWithFilterHidden,
isDashboard
} from '@/utils/canvasUtils'
import DeCustomTab from '@/custom-component/de-tabs/DeCustomTab.vue'
import DePreview from '@/components/data-visualization/canvas/DePreview.vue'
import { getPanelAllLinkageInfo } from '@/api/visualization/linkage'
@@ -407,10 +412,9 @@ const componentMoveIn = component => {
element.value.propValue.forEach((tabItem, index) => {
if (editableTabsValue.value === tabItem.name) {
//获取主画布当前组件的index
const curIndex = findComponentIndexById(component.id)
if (curIndex > -1) {
// 从主画布中移除
if (isDashboard()) {
if (isDashboard()) {
const curIndex = findComponentIndexByIdWithFilterHidden(component.id)
if (curIndex > -1) {
eventBus.emit('removeMatrixItem-canvas-main', curIndex)
dvMainStore.setCurComponent({ component: null, index: null })
component.canvasId = element.value.id + '--' + tabItem.name
@@ -428,14 +432,15 @@ const componentMoveIn = component => {
refInstance.canvasInitImmediately()
})
}
} else {
// 从主画布删除
dvMainStore.deleteComponent(curIndex)
dvMainStore.setCurComponent({ component: null, index: null })
component.canvasId = element.value.id + '--' + tabItem.name
dataVTabComponentAdd(component, element.value)
tabItem.componentData.push(component)
}
} else {
const curIndex = findComponentIndexById(component.id)
// 从主画布删除
dvMainStore.deleteComponent(curIndex)
dvMainStore.setCurComponent({ component: null, index: null })
component.canvasId = element.value.id + '--' + tabItem.name
dataVTabComponentAdd(component, element.value)
tabItem.componentData.push(component)
}
}
})

View File

@@ -738,6 +738,21 @@ export function isTabCanvas(canvasId) {
return canvasId && !canvasId.includes('Group') && !isMainCanvas(canvasId)
}
export function findComponentIndexByIdWithFilterHidden(
componentId,
componentDataMatch = componentData.value
) {
let indexResult = -1
componentDataMatch
.filter(item => !item.dashboardHidden)
.forEach((component, index) => {
if (component.id === componentId) {
indexResult = index
}
})
return indexResult
}
export function findComponentIndexById(componentId, componentDataMatch = componentData.value) {
let indexResult = -1
componentDataMatch.forEach((component, index) => {