feat: table element paging across multiple pages #41
This commit is contained in:
@@ -1154,6 +1154,7 @@ export class Draw {
|
|||||||
const nextElement = elementList[tableIndex]
|
const nextElement = elementList[tableIndex]
|
||||||
if (nextElement.pagingId === element.pagingId) {
|
if (nextElement.pagingId === element.pagingId) {
|
||||||
element.trList!.push(...nextElement.trList!)
|
element.trList!.push(...nextElement.trList!)
|
||||||
|
element.height! += nextElement.height!
|
||||||
tableIndex++
|
tableIndex++
|
||||||
combineCount++
|
combineCount++
|
||||||
} else {
|
} else {
|
||||||
@@ -1259,8 +1260,16 @@ export class Draw {
|
|||||||
curPagePreHeight += row.height
|
curPagePreHeight += row.height
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 表格高度超过页面高度
|
// 当前剩余高度是否能容下当前表格第一行(可拆分)的高度
|
||||||
const rowMarginHeight = rowMargin * 2 * scale
|
const rowMarginHeight = rowMargin * 2 * scale
|
||||||
|
if (
|
||||||
|
curPagePreHeight + element.trList![0].height! + rowMarginHeight >
|
||||||
|
height
|
||||||
|
) {
|
||||||
|
// 无可拆分行则切换至新页
|
||||||
|
curPagePreHeight = marginHeight
|
||||||
|
}
|
||||||
|
// 表格高度超过页面高度开始截断行
|
||||||
if (curPagePreHeight + rowMarginHeight + elementHeight > height) {
|
if (curPagePreHeight + rowMarginHeight + elementHeight > height) {
|
||||||
const trList = element.trList!
|
const trList = element.trList!
|
||||||
// 计算需要移除的行数
|
// 计算需要移除的行数
|
||||||
@@ -1294,7 +1303,7 @@ export class Draw {
|
|||||||
(pre, cur) => pre + cur.height,
|
(pre, cur) => pre + cur.height,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
const pagingId = getUUID()
|
const pagingId = element.pagingId || getUUID()
|
||||||
element.pagingId = pagingId
|
element.pagingId = pagingId
|
||||||
element.height -= cloneTrHeight
|
element.height -= cloneTrHeight
|
||||||
metrics.height -= cloneTrHeight
|
metrics.height -= cloneTrHeight
|
||||||
@@ -1305,7 +1314,10 @@ export class Draw {
|
|||||||
cloneElement.trList = cloneTrList
|
cloneElement.trList = cloneTrList
|
||||||
cloneElement.id = getUUID()
|
cloneElement.id = getUUID()
|
||||||
this.spliceElementList(elementList, i + 1, 0, cloneElement)
|
this.spliceElementList(elementList, i + 1, 0, cloneElement)
|
||||||
// 换页的是当前行则改变上下文
|
}
|
||||||
|
}
|
||||||
|
// 表格经过分页处理-需要处理上下文
|
||||||
|
if (element.pagingId) {
|
||||||
const positionContext = this.position.getPositionContext()
|
const positionContext = this.position.getPositionContext()
|
||||||
if (positionContext.isTable) {
|
if (positionContext.isTable) {
|
||||||
// 查找光标所在表格索引(根据trId搜索)
|
// 查找光标所在表格索引(根据trId搜索)
|
||||||
@@ -1314,7 +1326,7 @@ export class Draw {
|
|||||||
let tableIndex = i
|
let tableIndex = i
|
||||||
while (tableIndex < elementList.length) {
|
while (tableIndex < elementList.length) {
|
||||||
const curElement = elementList[tableIndex]
|
const curElement = elementList[tableIndex]
|
||||||
if (curElement.pagingId !== pagingId) break
|
if (curElement.pagingId !== element.pagingId) break
|
||||||
const trIndex = curElement.trList!.findIndex(
|
const trIndex = curElement.trList!.findIndex(
|
||||||
r => r.id === positionContext.trId
|
r => r.id === positionContext.trId
|
||||||
)
|
)
|
||||||
@@ -1332,7 +1344,6 @@ export class Draw {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (element.type === ElementType.SEPARATOR) {
|
} else if (element.type === ElementType.SEPARATOR) {
|
||||||
element.width = availableWidth / scale
|
element.width = availableWidth / scale
|
||||||
metrics.width = availableWidth
|
metrics.width = availableWidth
|
||||||
|
|||||||
Reference in New Issue
Block a user