diff --git a/core/core-frontend/src/views/chart/components/editor/editor-style/components/table/TableHeaderGroupConfig.vue b/core/core-frontend/src/views/chart/components/editor/editor-style/components/table/TableHeaderGroupConfig.vue index 04ec767e1c..d5c086ce8f 100644 --- a/core/core-frontend/src/views/chart/components/editor/editor-style/components/table/TableHeaderGroupConfig.vue +++ b/core/core-frontend/src/views/chart/components/editor/editor-style/components/table/TableHeaderGroupConfig.vue @@ -30,7 +30,8 @@ import { getColumns, getCustomTheme, getLeafNodes, - mapKeyToField + mapKeyToField, + setupColumnTitle } from '@/views/chart/components/js/panel/common/common_table' const { t } = useI18n() @@ -487,27 +488,6 @@ const renderTable = (chart: ChartObj) => { }) } -const getNonLeafNodes = (tree: Array): string[] => { - const result: string[] = [] - - const inorderTraversal = (node: ColumnNode) => { - // 如果有子节点,则为非叶子节点 - if (node.children?.length > 0) { - result.push(node.field) - - // 递归处理子节点 - for (let i = 0; i < node.children.length; i++) { - inorderTraversal(node.children[i] as ColumnNode) - } - } - } - - // 遍历树中所有节点 - tree.forEach(node => inorderTraversal(node)) - - return result -} - const getTreesMaxDepth = (nodes: Array): number => { if (!nodes?.length) { return 0 @@ -527,22 +507,6 @@ const getTreesMaxDepth = (nodes: Array): number => { return Math.max(...rootDepths) } -const setupColumnTitle = (nodes: Array, nameMap: Record) => { - nodes.forEach(node => { - if (node.children) { - node.children.forEach(child => { - if (nameMap[child.field]) { - child.title = nameMap[child.field] - } - }) - setupColumnTitle(node.children as Array, nameMap) - } else { - if (nameMap[node.field]) { - node.title = nameMap[node.field] - } - } - }) -} const resize = debounce((width, height) => { if (s2) { s2.changeSheetSize(width, height) diff --git a/core/core-frontend/src/views/chart/components/editor/util/chart.ts b/core/core-frontend/src/views/chart/components/editor/util/chart.ts index f9b53acc07..0b8ea63aca 100644 --- a/core/core-frontend/src/views/chart/components/editor/util/chart.ts +++ b/core/core-frontend/src/views/chart/components/editor/util/chart.ts @@ -477,8 +477,7 @@ export const DEFAULT_TABLE_HEADER: ChartTableHeaderAttr = { isColBolder: true, headerGroup: false, headerGroupConfig: { - columns: [], - meta: [] + columns: [] } } export const DEFAULT_TABLE_CELL: ChartTableCellAttr = { 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 93a172a405..3d4a15dd40 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 @@ -27,7 +27,9 @@ import { getColumns, drawImage, getSummaryRow, - SummaryCell + SummaryCell, + mapKeyToField, + setupColumnTitle } from '@/views/chart/components/js/panel/common/common_table' const { t } = useI18n() @@ -110,10 +112,9 @@ export class TableInfo extends S2ChartView { if (f?.hide === true) { return } - columns.push(ele.dataeaseName) + columns.push({ field: ele.dataeaseName, title: ele.chartShowName ?? ele.name }) meta.push({ field: ele.dataeaseName, - name: ele.chartShowName ?? ele.name, formatter: function (value) { if (!f) { return value @@ -138,18 +139,32 @@ export class TableInfo extends S2ChartView { if (headerGroup && showTableHeader !== false) { const { headerGroupConfig } = tableHeader if (headerGroupConfig?.columns?.length) { - const allKeys = columns.map(c => drillFieldMap[c] || c) + // 存量配置转换 + if (headerGroupConfig.columns[0].key) { + mapKeyToField(headerGroupConfig.columns as unknown as ColumnNode[]) + } + const nameMap = + chart.xAxis?.reduce((pre, cur) => { + pre[cur.dataeaseName] = cur.name + return pre + }, {}) || {} + if (headerGroupConfig.meta?.length) { + headerGroupConfig.meta.forEach(m => { + nameMap[m.field] = m.name + }) + } + setupColumnTitle(headerGroupConfig.columns as unknown as ColumnNode[], nameMap) + const allKeys = columns.map(c => drillFieldMap[c] || c.field) const leafNodes = getLeafNodes(headerGroupConfig.columns as ColumnNode[]) - const leafKeys = leafNodes.map(c => c.key) + const leafKeys = leafNodes.map(c => c.field) if (isEqual(leafKeys, allKeys)) { if (Object.keys(drillFieldMap).length) { const originField = Object.values(drillFieldMap)[0] const drillField = Object.keys(drillFieldMap)[0] const [drillCol] = getColumns([originField], headerGroupConfig.columns as ColumnNode[]) - drillCol.key = drillField + drillCol.field = drillField } columns.splice(0, columns.length, ...headerGroupConfig.columns) - meta.push(...headerGroupConfig.meta) } } } 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 a5a297b52b..1ebdffd6b9 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 @@ -2157,6 +2157,23 @@ export const mapKeyToField = (nodes: Array) => { }) } +export const setupColumnTitle = (nodes: Array, nameMap: Record) => { + nodes.forEach(node => { + if (node.children) { + node.children.forEach(child => { + if (nameMap[child.field]) { + child.title = nameMap[child.field] + } + }) + setupColumnTitle(node.children as Array, nameMap) + } else { + if (nameMap[node.field]) { + node.title = nameMap[node.field] + } + } + }) +} + export const getColumns = (fields, cols: Array): Array => { const result = [] for (let i = 0; i < cols.length; i++) { diff --git a/core/core-frontend/src/views/chart/components/js/panel/types/impl/s2.ts b/core/core-frontend/src/views/chart/components/js/panel/types/impl/s2.ts index 6a8e5479d8..4b160e506d 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/types/impl/s2.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/types/impl/s2.ts @@ -92,9 +92,9 @@ export abstract class S2ChartView

extends AntVAbstractCha break case 'rowCell': case 'colCell': - content = meta.field - field = find(metaConfig, item => item.field === content) - if (field) { + content = meta.value + field = metaConfig.find(item => item.field === content) + if (field?.name) { content = field.name } break