refactor(图表): 优化明细表合并单元格的显示效果,不显示被覆盖单元格的文字和背景颜色

This commit is contained in:
wisonic
2025-10-28 15:41:25 +08:00
committed by wisonic-s
parent 192ee65a15
commit 1890de2e5b
2 changed files with 29 additions and 0 deletions

View File

@@ -503,6 +503,16 @@ export class TableInfo extends S2ChartView<TableSheet> {
const summaryObj = getSummaryRow(data, axis, basicStyle.seriesSummary) as any
data.push(summaryObj)
}
const { mergeCells } = tableCell
const mergedCellsInfoMap: Record<string, boolean> = {}
if (mergeCells) {
s2Options.mergedCellsInfo?.reduce((p, n) => {
n.forEach(cell => {
p[`${cell.rowIndex}-${cell.colIndex}`] = true
})
return p
}, mergedCellsInfoMap)
}
s2Options.dataCell = viewMeta => {
// 总计行处理
if (showSummary && viewMeta.rowIndex === data.length - 1) {
@@ -533,6 +543,10 @@ export class TableInfo extends S2ChartView<TableSheet> {
// 配置文本自动换行参数
viewMeta.autoWrap = tableCell.mergeCells ? false : basicStyle.autoWrap
viewMeta.maxLines = basicStyle.maxLines
// 合并单元格标记
if (mergeCells && mergedCellsInfoMap[`${viewMeta.rowIndex}-${viewMeta.colIndex}`]) {
viewMeta.isMergedCell = true
}
return new CustomDataCell(viewMeta, viewMeta?.spreadsheet)
}
}

View File

@@ -2135,6 +2135,7 @@ class CustomMergedCell extends MergedCell {
}
drawTextShape(): void {
console.log(this.meta.fieldValue)
if (this.meta.deFieldType === 7) {
drawImage.apply(this)
} else {
@@ -2158,11 +2159,25 @@ export class CustomDataCell extends TableDataCell {
})
}
public getBackgroundColor() {
let bgColorInfo = super.getBackgroundColor()
if (this.meta.isMergedCell) {
bgColorInfo = {
...bgColorInfo,
backgroundColorOpacity: 0
}
}
return bgColorInfo
}
/**
* 重写绘制文本内容的方法
* @protected
*/
protected drawTextShape() {
if(this.meta.isMergedCell) {
return
}
if (this.meta.autoWrap) {
drawTextShape(this, false)
} else {