feat: table header appears repeatedly when paging #541
Co-authored-by: Hufe921 <huangyunfeihufe@hotmail.com>
This commit is contained in:
@@ -771,6 +771,7 @@ export class CommandAdapt {
|
||||
if (activeControl) return
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
if (!~startIndex && !~endIndex) return
|
||||
const { defaultTrMinHeight } = this.options.table
|
||||
const elementList = this.draw.getElementList()
|
||||
let offsetX = 0
|
||||
if (elementList[startIndex]?.listId) {
|
||||
@@ -794,7 +795,7 @@ export class CommandAdapt {
|
||||
for (let r = 0; r < row; r++) {
|
||||
const tdList: ITd[] = []
|
||||
const tr: ITr = {
|
||||
height: this.options.defaultTrMinHeight,
|
||||
height: defaultTrMinHeight,
|
||||
tdList
|
||||
}
|
||||
for (let c = 0; c < col; c++) {
|
||||
@@ -992,7 +993,7 @@ export class CommandAdapt {
|
||||
// 重新计算宽度
|
||||
const colgroup = element.colgroup!
|
||||
colgroup.splice(curTdIndex, 0, {
|
||||
width: this.options.defaultColMinWidth
|
||||
width: this.options.table.defaultColMinWidth
|
||||
})
|
||||
const colgroupWidth = colgroup.reduce((pre, cur) => pre + cur.width, 0)
|
||||
const width = this.draw.getOriginalInnerWidth()
|
||||
@@ -1051,7 +1052,7 @@ export class CommandAdapt {
|
||||
// 重新计算宽度
|
||||
const colgroup = element.colgroup!
|
||||
colgroup.splice(curTdIndex, 0, {
|
||||
width: this.options.defaultColMinWidth
|
||||
width: this.options.table.defaultColMinWidth
|
||||
})
|
||||
const colgroupWidth = colgroup.reduce((pre, cur) => pre + cur.width, 0)
|
||||
const width = this.draw.getOriginalInnerWidth()
|
||||
|
||||
@@ -398,7 +398,10 @@ export class Draw {
|
||||
}
|
||||
|
||||
public getTdPadding(): IPadding {
|
||||
const { tdPadding, scale } = this.options
|
||||
const {
|
||||
table: { tdPadding },
|
||||
scale
|
||||
} = this.options
|
||||
return <IPadding>tdPadding.map(m => m * scale)
|
||||
}
|
||||
|
||||
@@ -1124,8 +1127,13 @@ export class Draw {
|
||||
|
||||
public computeRowList(payload: IComputeRowListPayload) {
|
||||
const { innerWidth, elementList, isPagingMode = false } = payload
|
||||
const { defaultSize, defaultRowMargin, scale, tdPadding, defaultTabWidth } =
|
||||
this.options
|
||||
const {
|
||||
defaultSize,
|
||||
defaultRowMargin,
|
||||
scale,
|
||||
table: { tdPadding },
|
||||
defaultTabWidth
|
||||
} = this.options
|
||||
const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight()
|
||||
const canvas = document.createElement('canvas')
|
||||
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D
|
||||
@@ -1214,7 +1222,10 @@ export class Draw {
|
||||
while (tableIndex < elementList.length) {
|
||||
const nextElement = elementList[tableIndex]
|
||||
if (nextElement.pagingId === element.pagingId) {
|
||||
element.trList!.push(...nextElement.trList!)
|
||||
const nexTrList = nextElement.trList!.filter(
|
||||
tr => !tr.pagingRepeat
|
||||
)
|
||||
element.trList!.push(...nexTrList)
|
||||
element.height! += nextElement.height!
|
||||
tableIndex++
|
||||
combineCount++
|
||||
@@ -1226,6 +1237,7 @@ export class Draw {
|
||||
elementList.splice(i + 1, combineCount)
|
||||
}
|
||||
}
|
||||
element.pagingIndex = element.pagingIndex ?? 0
|
||||
// 计算表格行列
|
||||
this.tableParticle.computeRowColInfo(element)
|
||||
// 计算表格内元素信息
|
||||
@@ -1323,11 +1335,12 @@ export class Draw {
|
||||
curPagePreHeight += row.height
|
||||
}
|
||||
}
|
||||
// 当前剩余高度是否能容下当前表格第一行(可拆分)的高度
|
||||
// 当前剩余高度是否能容下当前表格第一行(可拆分)的高度,排除掉表头类型
|
||||
const rowMarginHeight = rowMargin * 2 * scale
|
||||
if (
|
||||
curPagePreHeight + element.trList![0].height! + rowMarginHeight >
|
||||
height
|
||||
height ||
|
||||
(element.pagingIndex !== 0 && element.trList![0].pagingRepeat)
|
||||
) {
|
||||
// 无可拆分行则切换至新页
|
||||
curPagePreHeight = marginHeight
|
||||
@@ -1378,6 +1391,14 @@ export class Draw {
|
||||
// 追加拆分表格
|
||||
const cloneElement = deepClone(element)
|
||||
cloneElement.pagingId = pagingId
|
||||
cloneElement.pagingIndex = element.pagingIndex! + 1
|
||||
// 处理分页重复表头
|
||||
const repeatTrList = trList.filter(tr => tr.pagingRepeat)
|
||||
if (repeatTrList.length) {
|
||||
const cloneRepeatTrList = deepClone(repeatTrList)
|
||||
cloneRepeatTrList.forEach(tr => (tr.id = getUUID()))
|
||||
cloneTrList.unshift(...cloneRepeatTrList)
|
||||
}
|
||||
cloneElement.trList = cloneTrList
|
||||
cloneElement.id = getUUID()
|
||||
this.spliceElementList(elementList, i + 1, 0, cloneElement)
|
||||
@@ -1742,7 +1763,12 @@ export class Draw {
|
||||
// 优先绘制高亮元素
|
||||
this._drawHighlight(ctx, payload)
|
||||
// 绘制元素、下划线、删除线、选区
|
||||
const { scale, tdPadding, group, lineBreak } = this.options
|
||||
const {
|
||||
scale,
|
||||
table: { tdPadding },
|
||||
group,
|
||||
lineBreak
|
||||
} = this.options
|
||||
const {
|
||||
rowList,
|
||||
pageNo,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { IElement } from '../../../..'
|
||||
import { EDITOR_PREFIX } from '../../../../dataset/constant/Editor'
|
||||
import { TableOrder } from '../../../../dataset/enum/table/TableTool'
|
||||
import { DeepRequired } from '../../../../interface/Common'
|
||||
import { IEditorOption } from '../../../../interface/Editor'
|
||||
import { Position } from '../../../position/Position'
|
||||
import { Draw } from '../../Draw'
|
||||
@@ -22,7 +23,7 @@ export class TableTool {
|
||||
|
||||
private draw: Draw
|
||||
private canvas: HTMLCanvasElement
|
||||
private options: Required<IEditorOption>
|
||||
private options: DeepRequired<IEditorOption>
|
||||
private position: Position
|
||||
private container: HTMLDivElement
|
||||
private toolRowContainer: HTMLDivElement | null
|
||||
@@ -255,7 +256,7 @@ export class TableTool {
|
||||
const trList = element.trList!
|
||||
const tr = trList[index] || trList[index - 1]
|
||||
// 最大移动高度-向上移动超出最小高度限定,则减少移动量
|
||||
const { defaultTrMinHeight } = this.options
|
||||
const { defaultTrMinHeight } = this.options.table
|
||||
if (dy < 0 && tr.height + dy < defaultTrMinHeight) {
|
||||
dy = defaultTrMinHeight - tr.height
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import { Draw } from '../draw/Draw'
|
||||
import { EditorMode, EditorZone } from '../../dataset/enum/Editor'
|
||||
import { deepClone } from '../../utils'
|
||||
import { ImageDisplay } from '../../dataset/enum/Common'
|
||||
import { DeepRequired } from '../../interface/Common'
|
||||
|
||||
export class Position {
|
||||
private cursorPosition: IElementPosition | null
|
||||
@@ -27,7 +28,7 @@ export class Position {
|
||||
private floatPositionList: IFloatPosition[]
|
||||
|
||||
private draw: Draw
|
||||
private options: Required<IEditorOption>
|
||||
private options: DeepRequired<IEditorOption>
|
||||
|
||||
constructor(draw: Draw) {
|
||||
this.positionList = []
|
||||
@@ -114,7 +115,10 @@ export class Position {
|
||||
innerWidth,
|
||||
zone
|
||||
} = payload
|
||||
const { scale, tdPadding } = this.options
|
||||
const {
|
||||
scale,
|
||||
table: { tdPadding }
|
||||
} = this.options
|
||||
let x = startX
|
||||
let y = startY
|
||||
let index = startIndex
|
||||
|
||||
Reference in New Issue
Block a user