fix(图表): 图表指标快速计算优化,不支持的图表指标累加功能置灰,修复了设置同环比时不能默认选择第一个同比类型、以及配置同环比后不勾选的问题

This commit is contained in:
jianneng-fit2cloud
2025-02-20 20:11:03 +08:00
committed by jianneng-fit2cloud
parent f70b115b90
commit 4a09ed1ae4
3 changed files with 57 additions and 18 deletions

View File

@@ -15,7 +15,7 @@ import { useI18n } from '@/hooks/web/useI18n'
import { computed, onMounted, reactive, ref, toRefs, watch } from 'vue'
import { formatterItem } from '@/views/chart/components/js/formatter'
import { getItemType, resetValueFormatter } from '@/views/chart/components/editor/drag-item/utils'
import { quotaViews } from '@/views/chart/components/js/util'
import { quotaViews, notSupportAccumulateViews } from '@/views/chart/components/js/util'
import { SUPPORT_Y_M } from '@/views/chart/components/editor/util/chart'
import { fieldType } from '@/utils/attr'
import { iconFieldMap } from '@/components/icon-group/field-list'
@@ -27,7 +27,8 @@ const tagType = ref('success')
const state = reactive({
formatterItem: formatterItem,
disableEditCompare: false,
quotaViews: quotaViews
quotaViews: quotaViews,
notSupportAccumulateViews: notSupportAccumulateViews
})
const props = defineProps({
@@ -93,6 +94,13 @@ watch(
() => props.chart,
() => {
isEnableCompare()
// 不支持累加计算的图表,自动设置快速计算为无
if (
state.notSupportAccumulateViews.indexOf(chart.value.type) > -1 &&
item.value.compareCalc.type === 'accumulate'
) {
quickCalc({ type: 'none' })
}
},
{ deep: true }
)
@@ -318,6 +326,9 @@ const showSort = computed(() => {
)
})
// 同环比计算类型
const yoyLabel = ['day_mom', 'month_yoy', 'year_yoy', 'month_mom', 'year_mom']
onMounted(() => {
isEnableCompare()
getItemTagType()
@@ -651,26 +662,30 @@ onMounted(() => {
:disabled="state.disableEditCompare"
:command="beforeQuickCalc('setting')"
>
<span
<div
class="sub-menu-content"
:class="'yoy_label' === item.compareCalc.type ? 'content-active' : ''"
:class="yoyLabel.includes(item.compareCalc.type) ? 'content-active' : ''"
:disabled="state.disableEditCompare"
>
{{ t('chart.yoy_label') }}
<el-icon class="sub-menu-content--icon">
<Icon name="icon_done_outlined" v-if="'yoy_label' === item.compareCalc.type"
<Icon
name="icon_done_outlined"
v-if="yoyLabel.includes(item.compareCalc.type)"
><icon_done_outlined class="svg-icon"
/></Icon>
</el-icon>
</span>
</div>
</el-dropdown-item>
<el-dropdown-item
class="menu-item-padding"
:disabled="state.quotaViews.indexOf(chart.type) > -1"
:command="beforeQuickCalc('percent')"
>
<span
<div
class="sub-menu-content"
:class="'percent' === item.compareCalc.type ? 'content-active' : ''"
:disabled="state.quotaViews.indexOf(chart.type) > -1"
>
{{ t('chart.percent') }}
<el-icon class="sub-menu-content--icon">
@@ -678,16 +693,17 @@ onMounted(() => {
><icon_done_outlined class="svg-icon"
/></Icon>
</el-icon>
</span>
</div>
</el-dropdown-item>
<el-dropdown-item
class="menu-item-padding"
:disabled="state.quotaViews.indexOf(chart.type) > -1"
:disabled="state.notSupportAccumulateViews.indexOf(chart.type) > -1"
:command="beforeQuickCalc('accumulate')"
>
<span
<div
class="sub-menu-content"
:class="'accumulate' === item.compareCalc.type ? 'content-active' : ''"
:disabled="state.notSupportAccumulateViews.indexOf(chart.type) > -1"
>
{{ t('chart.accumulate') }}
<el-icon class="sub-menu-content--icon">
@@ -697,7 +713,7 @@ onMounted(() => {
><icon_done_outlined class="svg-icon"
/></Icon>
</el-icon>
</span>
</div>
</el-dropdown-item>
</el-dropdown-menu>
</template>

View File

@@ -204,7 +204,8 @@ const initFieldList = () => {
compareItem.value.compareCalc.field = state.fieldList[0].id
}
}
// 同环比计算类型
const yoyLabel = ['day_mom', 'month_yoy', 'year_yoy', 'month_mom', 'year_mom']
// 获得不同字段格式对应能计算的同环比列表
const initCompareType = () => {
const checkedField = state.fieldList.filter(ele => ele.id === compareItem.value.compareCalc.field)
@@ -226,12 +227,7 @@ const initCompareType = () => {
state.compareList = []
}
// 如果没有选中一个同环比类型,则默认选中第一个
if (
(!compareItem.value.compareCalc.type ||
compareItem.value.compareCalc.type === '' ||
compareItem.value.compareCalc.type === 'none') &&
state.compareList.length > 0
) {
if (!yoyLabel.includes(compareItem.value.compareCalc.type) && state.compareList.length > 0) {
compareItem.value.compareCalc.type = state.compareList[0].value
}
}

View File

@@ -241,6 +241,33 @@ export function getRemark(chart) {
}
export const quotaViews = ['label', 'richTextView', 'indicator', 'gauge', 'liquid']
// 地图
const mapChartTypes = ['bubble-map', 'flow-map', 'heat-map', 'map', 'symbolic-map']
// 分布图
const distributionChartTypes = [
'pie',
'pie-donut',
'pie-rose',
'pie-donut-rose',
'radar',
'treemap',
'word-cloud'
]
// 关系图
const relationChartTypes = ['scatter', 'quadrant', 'funnel', 'sankey', 'circle-packing']
// 不支持指标累加的图表
export const notSupportAccumulateViews = [
...quotaViews,
...mapChartTypes,
...distributionChartTypes,
...relationChartTypes,
'table-info',
't-heatmap',
'percentage-bar-stack',
'percentage-bar-stack-horizontal',
'progress-bar',
'stock-line'
]
export function handleEmptyDataStrategy<O extends PickOptions>(chart: Chart, options: O): O {
const { data } = options as unknown as Options