From 11fbe453c33028b673ca5301c46e2213ddb4af73 Mon Sep 17 00:00:00 2001 From: wisonic Date: Wed, 9 Oct 2024 16:17:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E9=80=8F=E8=A7=86?= =?UTF-8?q?=E8=A1=A8=E6=A0=91=E5=BD=A2=E6=A8=A1=E5=BC=8F=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=B1=87=E6=80=BB=E5=88=97=E6=80=BB=E8=AE=A1=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=94=99=E8=AF=AF=20#12291?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../js/panel/charts/table/table-pivot.ts | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) 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 100b84970f..92a00d8c47 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 @@ -232,7 +232,7 @@ export class TablePivot extends S2ChartView { return p }, {}) total.calcFunc = (query, data, _, status) => { - return customCalcFunc(query, data, status, totalCfgMap, axisMap, customCalc) + return customCalcFunc(query, data, status, chart, totalCfgMap, axisMap, customCalc) } } }) @@ -440,7 +440,7 @@ export class TablePivot extends S2ChartView { super('table-pivot', []) } } -function customCalcFunc(query, data, status, totalCfgMap, axisMap, customCalc) { +function customCalcFunc(query, data, status, chart, totalCfgMap, axisMap, customCalc) { if (!data?.length || !query[EXTRA_FIELD]) { return 0 } @@ -470,7 +470,7 @@ function customCalcFunc(query, data, status, totalCfgMap, axisMap, customCalc) { return result?.[query[EXTRA_FIELD]] } case 'CUSTOM': { - const val = getCustomCalcResult(query, axisMap, status, customCalc || {}) + const val = getCustomCalcResult(query, axisMap, chart, status, customCalc || {}) if (val === '') { return val } @@ -484,7 +484,7 @@ function customCalcFunc(query, data, status, totalCfgMap, axisMap, customCalc) { } } -function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { +function getCustomCalcResult(query, axisMap, chart: ChartObj, status: TotalStatus, customCalc) { const quotaField = query[EXTRA_FIELD] const { row, col } = axisMap // 行列交叉总计 @@ -493,12 +493,28 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { } // 列总计 if (status.isColTotal && !status.isRowSubTotal) { - const { colTotal } = customCalc + const { colTotal, rowSubInColTotal } = customCalc + const { tableLayoutMode } = chart.customAttr.basicStyle const path = getTreePath(query, row) let val - if (path.length && colTotal) { - path.push(quotaField) - val = get(colTotal.data, path) + if (path.length) { + if (tableLayoutMode === 'grid' && colTotal) { + path.push(quotaField) + val = get(colTotal.data, path) + } + // 树形模式的行小计放在列总计里面 + if (tableLayoutMode === 'tree') { + const subLevel = getSubLevel(query, row) + if (subLevel + 1 === row.length && colTotal) { + path.push(quotaField) + val = get(colTotal.data, path) + } + if (subLevel + 1 < row.length && rowSubInColTotal) { + const data = rowSubInColTotal?.[subLevel]?.data + path.push(quotaField) + val = get(data, path) + } + } } return val } @@ -528,8 +544,7 @@ function getCustomCalcResult(query, axisMap, status: TotalStatus, customCalc) { } // 列维度为空,行维度不为空 if (!col.length && row.length) { - const path = [query[EXTRA_FIELD]] - val = get(rowTotal.data, path) + val = get(rowTotal.data, quotaField) } return val }