diff --git a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/numeric/IndicatorHandler.java b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/numeric/IndicatorHandler.java index e39125fcb5..8ff6b8c71d 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/numeric/IndicatorHandler.java +++ b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/numeric/IndicatorHandler.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Component; import java.util.List; import java.util.Map; +import java.util.Objects; @Component public class IndicatorHandler extends YoyChartHandler { @@ -36,23 +37,19 @@ public class IndicatorHandler extends YoyChartHandler { var xAxis = formatResult.getAxisMap().get(ChartAxis.xAxis); var yAxis = formatResult.getAxisMap().get(ChartAxis.yAxis); var allFields = (List) filterResult.getContext().get("allFields"); - ChartViewFieldDTO chartViewFieldDTO = yAxis.get(0); - ChartFieldCompareDTO compareCalc = chartViewFieldDTO.getCompareCalc(); + ChartViewFieldDTO yAxisChartViewFieldDTO = yAxis.get(0); + ChartFieldCompareDTO compareCalc = yAxisChartViewFieldDTO.getCompareCalc(); boolean isYoy = org.apache.commons.lang3.StringUtils.isNotEmpty(compareCalc.getType()) && !org.apache.commons.lang3.StringUtils.equalsIgnoreCase(compareCalc.getType(), "none"); if (isYoy) { xAxis.clear(); // 设置维度字段,从同环比中获取用户选择的字段 - xAxis.addAll(allFields.stream().filter(i -> org.springframework.util.StringUtils.endsWithIgnoreCase(i.getId().toString(), yAxis.get(0).getCompareCalc().getField().toString())).toList()); + xAxis.addAll(allFields.stream().filter(i -> org.springframework.util.StringUtils.endsWithIgnoreCase(i.getId().toString(), compareCalc.getField().toString())).toList()); xAxis.get(0).setSort("desc"); - if (org.springframework.util.StringUtils.endsWithIgnoreCase("month_mom", compareCalc.getType())) { - xAxis.get(0).setDateStyle("y_M"); - } - if (org.springframework.util.StringUtils.endsWithIgnoreCase("day_mom", compareCalc.getType())) { + if(Objects.isNull(compareCalc.getCustom())){ xAxis.get(0).setDateStyle("y_M_d"); - } - if (org.springframework.util.StringUtils.endsWithIgnoreCase("year_mom", compareCalc.getType())) { - xAxis.get(0).setDateStyle("y"); + }else{ + xAxis.get(0).setDateStyle(compareCalc.getCustom().getTimeType()); } } formatResult.getAxisMap().put(ChartAxis.xAxis, xAxis); diff --git a/core/core-frontend/src/views/chart/components/editor/drag-item/components/CompareEdit.vue b/core/core-frontend/src/views/chart/components/editor/drag-item/components/CompareEdit.vue index 26c2b07681..f6903829c0 100644 --- a/core/core-frontend/src/views/chart/components/editor/drag-item/components/CompareEdit.vue +++ b/core/core-frontend/src/views/chart/components/editor/drag-item/components/CompareEdit.vue @@ -28,20 +28,48 @@ const props = defineProps({ } }) -const { compareItem, chart } = toRefs(props) +const {compareItem, chart} = toRefs(props) const state = reactive({ fieldList: [], - compareList: [] + compareList: [], + dateFormatter: 'y_M_d' }) +const dateFormatterList = [ + {name: '年', value: 'y'}, + {name: '年月', value: 'y_M'}, + {name: '年月日', value: 'y_M_d'} +] + +const changeDateFormatter = () => { + const checkedField = state.fieldList.filter(ele => ele.id === compareItem.value.compareCalc.field) + if (checkedField && checkedField.length > 0) { + checkedField[0].dateStyle = state.dateFormatter + if (!compareItem.value.compareCalc.custom) { + compareItem.value.compareCalc.custom = {timeType: 'y_M_d'} + } + compareItem.value.compareCalc.custom.timeType = state.dateFormatter + } + initCompareType() +} + +const initDateFormatter = () => { + const timeType = compareItem.value.compareCalc.custom?.timeType + if (isIndicator.value && timeType) { + state.dateFormatter = timeType + changeDateFormatter() + } +} + watch( () => props.chart, () => { initFieldList() initCompareType() + initDateFormatter() }, - { deep: true } + {deep: true} ) const isIndicator = computed(() => { @@ -109,15 +137,6 @@ const initCompareType = () => { } else { state.compareList = [] } - if (isIndicator.value) { - state.compareList = [ - { name: 'day_mom', value: 'day_mom' }, - { name: 'month_mom', value: 'month_mom' }, - { name: 'year_mom', value: 'year_mom' }, - { name: 'month_yoy', value: 'month_yoy' }, - { name: 'year_yoy', value: 'year_yoy' } - ] - } // 如果没有选中一个同环比类型,则默认选中第一个 if ( (!compareItem.value.compareCalc.type || @@ -136,9 +155,9 @@ const fieldFormatter = field => { return field.name + '(' + t('chart.' + field.dateStyle) + ')' } } - initFieldList() initCompareType() +initDateFormatter()