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 91800b02bf..63239b5133 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 @@ -5,6 +5,7 @@ import { S2ChartView, S2DrawOptions } from '../../types/impl/s2' import { TABLE_EDITOR_PROPERTY, TABLE_EDITOR_PROPERTY_INNER } from './common' import { useI18n } from '@/hooks/web/useI18n' import { isNumber } from 'lodash-es' +import { copyContent } from '@/views/chart/components/js/panel/common/common_table' const { t } = useI18n() @@ -161,6 +162,8 @@ export class TableInfo extends S2ChartView { // header resize newChart.on(S2Event.LAYOUT_RESIZE_COL_WIDTH, ev => resizeAction(ev)) + // right click + newChart.on(S2Event.GLOBAL_CONTEXT_MENU, event => copyContent(newChart, event, meta)) // theme const customTheme = this.configTheme(chart) newChart.setThemeCfg({ theme: customTheme }) 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 0b88390ea7..ba5ee4075a 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 @@ -2,7 +2,7 @@ import { S2ChartView, S2DrawOptions } from '@/views/chart/components/js/panel/ty import { S2Event, S2Options, TableSheet, TableColCell } from '@antv/s2' import { parseJson } from '@/views/chart/components/js/util' import { formatterItem, valueFormatter } from '@/views/chart/components/js/formatter' -import { getCurrentField } from '@/views/chart/components/js/panel/common/common_table' +import { copyContent, getCurrentField } from '@/views/chart/components/js/panel/common/common_table' import { TABLE_EDITOR_PROPERTY, TABLE_EDITOR_PROPERTY_INNER } from './common' import { useI18n } from '@/hooks/web/useI18n' import { isNumber } from 'lodash-es' @@ -155,6 +155,8 @@ export class TableNormal extends S2ChartView { }) // header resize newChart.on(S2Event.LAYOUT_RESIZE_COL_WIDTH, ev => resizeAction(ev)) + // right click + newChart.on(S2Event.GLOBAL_CONTEXT_MENU, event => copyContent(newChart, event, meta)) // theme const customTheme = this.configTheme(chart) newChart.setThemeCfg({ theme: customTheme }) 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 915993f697..8a79f602ec 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 @@ -5,6 +5,7 @@ import { S2ChartView, S2DrawOptions } from '../../types/impl/s2' import { TABLE_EDITOR_PROPERTY_INNER } from './common' import { useI18n } from '@/hooks/web/useI18n' import { maxBy, merge, minBy } from 'lodash-es' +import { copyContent } from '../../common/common_table' const { t } = useI18n() @@ -189,7 +190,8 @@ export class TablePivot extends S2ChartView { s2.on(S2Event.DATA_CELL_CLICK, ev => this.dataCellClickAction(chart, ev, s2, action)) s2.on(S2Event.ROW_CELL_CLICK, ev => this.headerCellClickAction(chart, ev, s2, action)) s2.on(S2Event.COL_CELL_CLICK, ev => this.headerCellClickAction(chart, ev, s2, action)) - + // right click + s2.on(S2Event.GLOBAL_CONTEXT_MENU, event => copyContent(s2, event, meta)) // theme const customTheme = this.configTheme(chart) s2.setThemeCfg({ theme: customTheme }) 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 1b6ca6aad5..d21ff51469 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 @@ -14,7 +14,7 @@ import { S2Options, SERIES_NUMBER_FIELD } from '@antv/s2' -import { keys, intersection, filter, cloneDeep, merge } from 'lodash-es' +import { keys, intersection, filter, cloneDeep, merge, find } from 'lodash-es' import { createVNode, render } from 'vue' import TableTooltip from '@/views/chart/components/editor/common/TableTooltip.vue' @@ -658,3 +658,29 @@ export function configTooltip(option: S2Options) { } ] } + +export function copyContent(s2Instance, event, fieldMap) { + event.preventDefault() + const cell = s2Instance.getCell(event.target) + const valueField = cell.getMeta().valueField + const cellMeta = cell.getMeta() + let content + // 单元格 + if (cellMeta?.data) { + const value = cellMeta.data[valueField] + const metaObj = find(fieldMap, m => m.field === valueField) + content = value?.toString() + if (metaObj) { + content = metaObj.formatter(value) + } + } else { + // 列头&行头 + content = cellMeta.value + if (fieldMap?.[content]) { + content = fieldMap[content] + } + } + if (content) { + navigator.clipboard.writeText(content) + } +}