From f74f4e841afd704790d993eb8f1316fe952ee44b Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Wed, 17 Sep 2025 17:24:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E6=95=B0=E6=8D=AE=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/table/table-info.ts | 10 +++-- .../js/panel/charts/table/table-normal.ts | 9 +++-- .../js/panel/charts/table/table-pivot.ts | 9 ++++- .../js/panel/common/common_table.ts | 38 ------------------- 4 files changed, 19 insertions(+), 47 deletions(-) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts index ceda44174a..ee0c97e128 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-info.ts @@ -22,7 +22,6 @@ import { getRowIndex, SortTooltip, summaryRowStyle, - configEmptyDataStyle, getLeafNodes, getColumns, drawImage, @@ -198,7 +197,12 @@ export class TableInfo extends S2ChartView { ? ScrollbarPositionType.CONTENT : ScrollbarPositionType.CANVAS }, - frozen: {} + frozen: {}, + placeholder: { + empty: { + description: t('data_set.no_data') + } + } } s2Options.style = this.configStyle(chart, s2DataConfig) // 自适应列宽模式下,URL 字段的宽度固定为 120 @@ -332,8 +336,6 @@ export class TableInfo extends S2ChartView { ev.colsHierarchy.width = lastNode.x + lastNode.width }) } - // 空数据时表格样式 - configEmptyDataStyle(newChart, basicStyle, newData, container) // click newChart.on(S2Event.DATA_CELL_CLICK, ev => { const cell = newChart.getCell(ev.target) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts index ef8ada4de1..eb33b59e38 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-normal.ts @@ -1,7 +1,6 @@ import { useI18n } from '@/hooks/web/useI18n' import { formatterItem, valueFormatter } from '@/views/chart/components/js/formatter' import { - configEmptyDataStyle, copyContent, CustomDataCell, getSummaryRow, @@ -157,7 +156,12 @@ export class TableNormal extends S2ChartView { ? ScrollbarPositionType.CONTENT : ScrollbarPositionType.CANVAS }, - frozen: {} + frozen: {}, + placeholder: { + empty: { + description: t('data_set.no_data') + } + } } // 列宽设置 s2Options.style = this.configStyle(chart, s2DataConfig) @@ -240,7 +244,6 @@ export class TableNormal extends S2ChartView { ev.colsHierarchy.width = lastNode.x + lastNode.width }) } - configEmptyDataStyle(newChart, basicStyle, newData, container) // click newChart.on(S2Event.DATA_CELL_CLICK, ev => { const cell = newChart.getCell(ev.target) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts index 1e081dda77..416e73271d 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/table/table-pivot.ts @@ -438,6 +438,11 @@ export class TablePivot extends S2ChartView { }, dataCell: meta => { return new CustomDataCell(meta, meta.spreadsheet) + }, + placeholder: { + empty: { + description: t('data_set.no_data') + } } } // options @@ -1251,8 +1256,8 @@ class EmptyDataCell extends MergedCell { this.meta.fieldValue = ' ' super.drawTextShape() const { rowHeader, columnHeader } = this.spreadsheet.facet - const offsetX = columnHeader.style.viewportWidth / 2 - const offsetY = rowHeader.style.viewportHeight / 2 + const offsetX = columnHeader.headerConfig.viewportWidth / 2 + const offsetY = rowHeader.headerConfig.viewportHeight / 2 const style = this.getTextStyle() this.appendChild( new Text({ diff --git a/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts b/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts index 2e4eb5b06c..7cc3c50923 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/common/common_table.ts @@ -2079,44 +2079,6 @@ export class SummaryCell extends CustomDataCell { } } -/** - * 配置空数据样式 - * @param newChart - * @param basicStyle - * @param newData - * @param container - */ -export const configEmptyDataStyle = (newChart, basicStyle, newData, container) => { - /** - * 辅助函数:移除空数据dom - */ - const removeEmptyDom = () => { - const emptyElement = document.getElementById(container + '_empty') - if (emptyElement) { - emptyElement.parentElement.removeChild(emptyElement) - } - } - removeEmptyDom() - if (newData.length) return - newChart.on(S2Event.LAYOUT_AFTER_HEADER_LAYOUT, ev => { - removeEmptyDom() - if (!newData.length) { - const emptyDom = document.createElement('div') - const left = Math.min(newChart.options.width, ev.colsHierarchy.width) / 2 - 32 - emptyDom.id = container + '_empty' - emptyDom.textContent = i18nt('data_set.no_data') - emptyDom.setAttribute( - 'style', - `position: absolute; - left: ${left}px; - top: 50%;` - ) - const parent = document.getElementById(container) - parent.insertBefore(emptyDom, parent.firstChild) - } - }) -} - export const getLeafNodes = (tree: Array): ColumnNode[] => { const result: ColumnNode[] = [] const inorderTraversal = node => {