From da7d9e5bcb4a125de5cea934f91e6661d9200528 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Tue, 24 Dec 2024 16:34:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Safari=20=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E5=A4=8D=E5=88=B6/=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=8A=A5=E9=94=99=20(#3050)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../s2-core/src/utils/export/copy/base-data-cell-copy.ts | 7 +++++++ .../s2-core/src/utils/export/copy/pivot-data-cell-copy.ts | 2 +- packages/s2-core/src/utils/export/copy/table-copy.ts | 2 +- s2-site/docs/common/copy-export.zh.md | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/s2-core/src/utils/export/copy/base-data-cell-copy.ts b/packages/s2-core/src/utils/export/copy/base-data-cell-copy.ts index 8201f5fd91..3f6d1de3d2 100644 --- a/packages/s2-core/src/utils/export/copy/base-data-cell-copy.ts +++ b/packages/s2-core/src/utils/export/copy/base-data-cell-copy.ts @@ -91,4 +91,11 @@ export abstract class BaseDataCellCopy { return ((value) => value) as Formatter; } + + /** + * Safari 等不支持 requestIdleCallback 的浏览器, 降级为同步 + */ + protected isEnableASync() { + return this.config.async && !!window.requestIdleCallback; + } } diff --git a/packages/s2-core/src/utils/export/copy/pivot-data-cell-copy.ts b/packages/s2-core/src/utils/export/copy/pivot-data-cell-copy.ts index 72e21f42cb..19c82313f5 100644 --- a/packages/s2-core/src/utils/export/copy/pivot-data-cell-copy.ts +++ b/packages/s2-core/src/utils/export/copy/pivot-data-cell-copy.ts @@ -415,7 +415,7 @@ export class PivotDataCellCopy extends BaseDataCellCopy { let dataMatrix: SimpleData[][] = []; // 把两类导出都封装成异步的,保证导出类型的一致 - if (this.config.async) { + if (this.isEnableASync()) { dataMatrix = (await this.getDataMatrixByHeaderNodeRIC()) as SimpleData[][]; } else { diff --git a/packages/s2-core/src/utils/export/copy/table-copy.ts b/packages/s2-core/src/utils/export/copy/table-copy.ts index 92dbda7abb..dc346f9f11 100644 --- a/packages/s2-core/src/utils/export/copy/table-copy.ts +++ b/packages/s2-core/src/utils/export/copy/table-copy.ts @@ -227,7 +227,7 @@ class TableDataCellCopy extends BaseDataCellCopy { } async asyncProcessSelectedTable(allSelected = false): Promise { - const matrix = this.config.async + const matrix = this.isEnableASync() ? await this.getDataMatrixRIC() : await Promise.resolve(this.getDataMatrix()); diff --git a/s2-site/docs/common/copy-export.zh.md b/s2-site/docs/common/copy-export.zh.md index 1c30991fa3..77309efa5c 100644 --- a/s2-site/docs/common/copy-export.zh.md +++ b/s2-site/docs/common/copy-export.zh.md @@ -263,7 +263,7 @@ download(data, 'filename') // filename.csv | split | 分隔符 | `string` | | ✓ | | formatOptions | 是否使用 [S2DataConfig.Meta](/api/general/s2-data-config#meta) 进行格式化,可以分别对数据单元格和行列头进行格式化,传 `boolean` 会同时对单元格和行列头生效。 | `boolean \| { formatHeader?: boolean, formatData?: boolean }`| `true` | | | customTransformer | 导出时支持自定义 (transformer) 数据导出格式化方法 | (transformer: `Transformer`) => [`Partial`](#transformer) | | | -| async | 是否异步复制/导出 | boolean | `true` | | +| async | 是否异步复制/导出(当浏览器不支持 `requestIdleCallback` 时,会强制降级为**同步**) | boolean | `true` | | ##### copyToClipboard