From 6b3b1f5fc707ca05fdd4d633ec145616919c5aab Mon Sep 17 00:00:00 2001 From: ulleo Date: Thu, 26 Dec 2024 16:35:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9B=BE=E8=A1=A8):=20=E9=80=8F=E8=A7=86?= =?UTF-8?q?=E8=A1=A8=E8=A1=8C=E6=B1=87=E6=80=BB=E5=B0=8F=E8=AE=A1=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=A0=B9=E6=8D=AE=E7=BB=B4=E5=BA=A6=E7=81=B5=E6=B4=BB?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=20#11336?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/models/chart/chart-attr.d.ts | 4 + .../components/table/TableTotalSelector.vue | 100 +++++++++++++++++- .../chart/components/editor/util/chart.ts | 1 + .../js/panel/charts/table/table-pivot.ts | 4 +- 4 files changed, 104 insertions(+), 5 deletions(-) diff --git a/core/core-frontend/src/models/chart/chart-attr.d.ts b/core/core-frontend/src/models/chart/chart-attr.d.ts index a8dffeb79b..064cbeebed 100644 --- a/core/core-frontend/src/models/chart/chart-attr.d.ts +++ b/core/core-frontend/src/models/chart/chart-attr.d.ts @@ -558,6 +558,10 @@ declare interface TotalConfig { * 小计维度 */ subTotalsDimensions: string[] + /** + * 兼容旧版的判断 + */ + subTotalsDimensionsNew: boolean /** * 总计汇总设置 */ diff --git a/core/core-frontend/src/views/chart/components/editor/editor-style/components/table/TableTotalSelector.vue b/core/core-frontend/src/views/chart/components/editor/editor-style/components/table/TableTotalSelector.vue index 7529b62b74..93da19b17b 100644 --- a/core/core-frontend/src/views/chart/components/editor/editor-style/components/table/TableTotalSelector.vue +++ b/core/core-frontend/src/views/chart/components/editor/editor-style/components/table/TableTotalSelector.vue @@ -2,7 +2,7 @@ import { onMounted, PropType, reactive, watch, ref, inject, nextTick } from 'vue' import { useI18n } from '@/hooks/web/useI18n' import { DEFAULT_TABLE_TOTAL } from '@/views/chart/components/editor/util/chart' -import { cloneDeep, defaultsDeep } from 'lodash-es' +import { cloneDeep, defaultsDeep, find } from 'lodash-es' import CustomAggrEdit from './CustomAggrEdit.vue' const { t } = useI18n() @@ -43,9 +43,61 @@ const state = reactive({ colTotalItem: {} as DeepPartial, totalCfg: [] as CalcTotalCfg[], totalCfgAttr: '', - totalItem: {} as DeepPartial + totalItem: {} as DeepPartial, + selectedSubTotalDimensionName: '', + selectedSubTotalDimension: undefined as { name: string; checked: boolean }, + subTotalDimensionList: [] }) +function onSelectedSubTotalDimensionNameChange(name) { + state.selectedSubTotalDimension = find(state.subTotalDimensionList, d => d.name === name) +} + +function changeRowSubTableTotal() { + const list = [] + for (let i = 0; i < state.subTotalDimensionList.length; i++) { + if (state.subTotalDimensionList[i].checked) { + list.push(state.subTotalDimensionList[i].name) + } + } + state.tableTotalForm.row.subTotalsDimensions = list + changeTableTotal('row') +} + +const initSubTotalDimensionList = () => { + const list = [] + if (props.chart.xAxis.length > 2) { + for (let i = 0; i < props.chart.xAxis.length - 1; i++) { + //排除最后一个 + const old = find( + state.tableTotalForm.row.subTotalsDimensions, + s => s === props.chart.xAxis[i].dataeaseName + ) + list.push({ + displayName: props.chart.xAxis[i].name, + name: props.chart.xAxis[i].dataeaseName, + checked: state.tableTotalForm.row.subTotalsDimensionsNew ? old != undefined : true + }) + } + } + state.subTotalDimensionList = list + + const existItem = find( + state.subTotalDimensionList, + s => s.name === state.selectedSubTotalDimensionName + ) + if (existItem) { + state.selectedSubTotalDimension = existItem + } else { + state.selectedSubTotalDimensionName = list[0]?.name + state.selectedSubTotalDimension = list[0] + } + if (!state.tableTotalForm.row.subTotalsDimensionsNew) { + state.tableTotalForm.row.subTotalsDimensionsNew = true + changeRowSubTableTotal() + } +} + const emit = defineEmits(['onTableTotalChange']) const changeTableTotal = prop => { @@ -55,6 +107,9 @@ const changeTableTotal = prop => { const init = () => { const tableTotal = props.chart?.customAttr?.tableTotal if (tableTotal) { + if (tableTotal.row) { + tableTotal.row.subTotalsDimensionsNew = !!tableTotal.row?.subTotalsDimensionsNew + } state.tableTotalForm = defaultsDeep(cloneDeep(tableTotal), cloneDeep(DEFAULT_TABLE_TOTAL)) } const yAxis = props.chart.yAxis @@ -102,6 +157,7 @@ const init = () => { total.originName = totalCfg[0].originName } }) + initSubTotalDimensionList() } const showProperty = prop => props.propertyInner?.includes(prop) const changeTotal = (totalItem, totals) => { @@ -357,10 +413,46 @@ onMounted(() => { v-model="state.tableTotalForm.row.showSubTotals" :disabled="chart.xAxis.length < 2" @change="changeTableTotal('row')" - >{{ t('chart.show') }} + {{ t('chart.show') }} + -
+
+
+
+
+ + + + + + + + {{ t('chart.show') }} + + +
+
+ { // total config const { basicStyle, tooltip, tableTotal } = parseJson(chart.customAttr) - tableTotal.row.subTotalsDimensions = r + if (!tableTotal.row.subTotalsDimensionsNew || tableTotal.row.subTotalsDimensions == undefined) { + tableTotal.row.subTotalsDimensions = r + } tableTotal.col.subTotalsDimensions = c // 解析合计、小计排序