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