feat(仪表板): 仪表板点击组件可连续横向自动占位排列

This commit is contained in:
wangjiahao 2024-01-11 17:42:49 +08:00
parent cc4af0d423
commit 00b3f520e0
2 changed files with 47 additions and 1 deletions

View File

@ -601,6 +601,50 @@ function resetPositionBox() {
}
}
/**
* 查找位置盒子
*/
function findPositionX(item) {
const width = item.sizeX
let resultX = 1
let checkPointYIndex = -1 // -1 Y
//
let pb = positionBox.value
if (width <= 0) return
// component y1
componentData.value.forEach((component, index) => {
const componentYIndex = component.y + component.sizeY - 2
if (checkPointYIndex < componentYIndex) {
checkPointYIndex = componentYIndex
}
})
if (checkPointYIndex < 0) {
return 1
} else {
// X
const pbX = pb[checkPointYIndex]
// X i
// width checkEndIndex = i + width - 1
// 退checkEndIndex pbX
for (let i = 0, checkEndIndex = width - 1; checkEndIndex < pbX.length; i++, checkEndIndex++) {
let adaptorCount = 0
//
for (let k = 0; k < width; k++) {
// pbX[i + k].el === false width i
if (!pbX[i + k].el) {
adaptorCount++
}
}
if (adaptorCount === width) {
resultX = i + 1
break
}
}
return resultX
}
}
/**
* 填充位置盒子
*/
@ -1321,7 +1365,8 @@ defineExpose({
handleDragOver,
getMoveItem,
handleMouseUp,
handleMouseDown
handleMouseDown,
findPositionX
})
</script>

View File

@ -80,6 +80,7 @@ const handleNewFromCanvasMain = newComponentInfo => {
syncShapeItemStyle(component, baseWidth.value, baseHeight.value)
component.id = guid()
component.y = 200
component.x = cyGridster.value.findPositionX(component)
dvMainStore.addComponent({
component: component,
index: undefined,