feat: table element paging across multiple pages #41

pr675
Hufe 2 years ago committed by GitHub
parent 6d488aef48
commit 01b1104de4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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,31 +1314,33 @@ 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)
// 换页的是当前行则改变上下文 }
const positionContext = this.position.getPositionContext() }
if (positionContext.isTable) { // 表格经过分页处理-需要处理上下文
// 查找光标所在表格索引根据trId搜索 if (element.pagingId) {
let newPositionContextIndex = -1 const positionContext = this.position.getPositionContext()
let newPositionContextTrIndex = -1 if (positionContext.isTable) {
let tableIndex = i // 查找光标所在表格索引根据trId搜索
while (tableIndex < elementList.length) { let newPositionContextIndex = -1
const curElement = elementList[tableIndex] let newPositionContextTrIndex = -1
if (curElement.pagingId !== pagingId) break let tableIndex = i
const trIndex = curElement.trList!.findIndex( while (tableIndex < elementList.length) {
r => r.id === positionContext.trId const curElement = elementList[tableIndex]
) if (curElement.pagingId !== element.pagingId) break
if (~trIndex) { const trIndex = curElement.trList!.findIndex(
newPositionContextIndex = tableIndex r => r.id === positionContext.trId
newPositionContextTrIndex = trIndex )
break if (~trIndex) {
} newPositionContextIndex = tableIndex
tableIndex++ newPositionContextTrIndex = trIndex
} break
if (~newPositionContextIndex) {
positionContext.index = newPositionContextIndex
positionContext.trIndex = newPositionContextTrIndex
this.position.setPositionContext(positionContext)
} }
tableIndex++
}
if (~newPositionContextIndex) {
positionContext.index = newPositionContextIndex
positionContext.trIndex = newPositionContextTrIndex
this.position.setPositionContext(positionContext)
} }
} }
} }

Loading…
Cancel
Save