refactor(仪表板): 优化复用仪表板组件最终放置位置,防止复用仪表板较长时,复用的视图在仪表板中部

This commit is contained in:
wangjiahao 2024-10-08 18:05:57 +08:00
parent 9a1c186bc3
commit c9f551dee7
2 changed files with 13 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import eventBus from '@/utils/eventBus'
import { adaptCurThemeCommonStyle } from '@/utils/canvasStyle'
import { composeStoreWithOut } from '@/store/modules/data-visualization/compose'
import { snapshotStoreWithOut } from '@/store/modules/data-visualization/snapshot'
import { maxYComponentCount } from '@/utils/canvasUtils'
const dvMainStore = dvMainStoreWithOut()
const composeStore = composeStoreWithOut()
@ -62,7 +63,7 @@ export const copyStore = defineStore('copy', {
}
// dataV 数据大屏
newComponent.x = newComponent.sizeX * xPositionOffset + 1
newComponent.y = 200
newComponent.y = maxYComponentCount() + 10
// dataV 数据大屏
newComponent.style.left = 0
newComponent.style.top = 0

View File

@ -731,3 +731,14 @@ export function componentPreSort(componentData) {
})
}
}
export function maxYComponentCount() {
if (componentData.value.length === 0) {
return 1
} else {
return componentData.value
.filter(item => item.y)
.map(item => item.y + item.sizeY) // 计算每个元素的 y + sizeY
.reduce((max, current) => Math.max(max, current), 0)
}
}