From a4021cbfd62c84f6d6a5f96871b225f24b268f29 Mon Sep 17 00:00:00 2001 From: Tyr Date: Sun, 25 Jun 2023 16:15:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BA=A4=E5=8F=89=E8=A1=A8=E5=9C=88?= =?UTF-8?q?=E9=80=89=E8=A1=A8=E5=A4=B4=E5=A4=8D=E5=88=B6=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=20(#2254)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/utils/export/copy.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/s2-core/src/utils/export/copy.ts b/packages/s2-core/src/utils/export/copy.ts index 74b628114a..39704259c0 100644 --- a/packages/s2-core/src/utils/export/copy.ts +++ b/packages/s2-core/src/utils/export/copy.ts @@ -4,6 +4,7 @@ import { filter, forEach, isEmpty, + isEqual, isNil, map, max, @@ -12,25 +13,25 @@ import { repeat, zip, } from 'lodash'; +import type { ColCell, RowCell } from '../../cell'; import { - type CellMeta, CellTypes, CopyType, EMPTY_PLACEHOLDER, EXTRA_FIELD, ID_SEPARATOR, InteractionStateName, - VALUE_FIELD, SERIES_NUMBER_FIELD, + VALUE_FIELD, + type CellMeta, type RowData, } from '../../common'; import type { DataType } from '../../data-set/interface'; import type { Node } from '../../facet/layout/node'; import type { SpreadSheet } from '../../sheet-type'; import { copyToClipboard } from '../../utils/export'; -import type { ColCell, RowCell } from '../../cell'; -import { getEmptyPlaceholder } from '../text'; import { flattenDeep } from '../data-set-operate'; +import { getEmptyPlaceholder } from '../text'; export function keyEqualTo(key: string, compareKey: string) { if (!key || !compareKey) { @@ -659,11 +660,20 @@ function getCellMatrix( const meta = cell.getMeta(); const { id, label, isTotals, level } = meta; let cellId = id; + // 为总计小计补齐高度 if (isTotals && level !== maxLevel) { cellId = id + ID_SEPARATOR + repeat(label, maxLevel - level); } - return getHeaderList(cellId, allLevel.size); + + // 将指标维度单元格的标签替换为实际文本 + const actualText = cell.getActualText(); + const headerList = getHeaderList(cellId, allLevel.size); + const formattedHeaderList = map(headerList, (header) => + isEqual(header, label) ? actualText : header, + ); + + return formattedHeaderList; }); }