refactor: 富文本条件样式支持自定义字段

This commit is contained in:
王嘉豪
2026-06-04 16:42:46 +08:00
committed by wangjiahao
parent 7e035a6ab6
commit e5822fd38a
4 changed files with 60 additions and 16 deletions

View File

@@ -221,7 +221,7 @@ const conditionAdaptor = (chart: Chart) => {
defaultValueColor,
field,
'url'
)
).color
if (checkResult) {
state.showUrl = checkResult
}

View File

@@ -711,6 +711,18 @@ const conditionAdaptor = (chart: Chart) => {
if (!threshold.enable) {
return
}
const idNameMapping = {}
if (chart.xAxis && Array.isArray(chart.xAxis)) {
chart.xAxis.forEach(item => {
idNameMapping[item.id] = item.name
})
}
if (chart.yAxis && Array.isArray(chart.yAxis)) {
chart.yAxis.forEach(item => {
idNameMapping[item.id] = item.name
})
}
const res = {}
const conditions = threshold.tableThreshold ?? []
if (conditions?.length > 0) {
@@ -718,19 +730,21 @@ const conditionAdaptor = (chart: Chart) => {
const field = conditions[i]
let defaultValueColor = 'none'
let defaultBgColor = 'none'
res[field.field.name] = {
color: mappingColorCustom(
dataRowNameSelectSource.value[field.field.name],
defaultValueColor,
field,
'color'
),
backgroundColor: mappingColorCustom(
dataRowNameSelectSource.value[field.field.name],
defaultBgColor,
field,
'backgroundColor'
)
const colorCondition = mappingColorCustom(
dataRowNameSelectSource.value[field.field.name],
defaultValueColor,
field,
'color'
)
const backgroundColorCondition = mappingColorCustom(
dataRowNameSelectSource.value[field.field.name],
defaultBgColor,
field,
'backgroundColor'
)
res[idNameMapping[colorCondition.targetFieldId] || field.field.name] = {
color: colorCondition.color,
backgroundColor: backgroundColorCondition.color
}
}
}

View File

@@ -2,7 +2,7 @@
import icon_info_filled from '@/assets/svg/icon_info_filled.svg'
import icon_deleteTrash_outlined from '@/assets/svg/icon_delete-trash_outlined.svg'
import icon_add_outlined from '@/assets/svg/icon_add_outlined.svg'
import { PropType, reactive } from 'vue'
import { computed, PropType, reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { COLOR_PANEL } from '../../../util/chart'
import { fieldType } from '@/utils/attr'
@@ -171,6 +171,21 @@ const valueOptions = [
]
const predefineColors = COLOR_PANEL
const targetOptions = computed(() => {
if (props.chart.type === 'rich-text') {
return [
{ label: t('chart.self'), value: 'self' },
{ label: t('chart.custom'), value: 'custom' }
]
} else {
return [
{ label: t('chart.self'), value: 'self' },
{ label: t('chart.total_row'), value: 'total_row' },
{ label: t('chart.custom'), value: 'custom' }
]
}
})
const state = reactive({
thresholdArr: [] as TableThreshold[],
fields: [],

View File

@@ -698,6 +698,7 @@ export function getConditions(chart: Chart) {
export function mappingColor(value, defaultColor, field, type, filedValueMap?, rowData?) {
let color = null
let hitCondition = null;
for (let i = 0; i < field.conditions.length; i++) {
let flag = false
const t = field.conditions[i]
@@ -759,6 +760,7 @@ export function mappingColor(value, defaultColor, field, type, filedValueMap?, r
flag = true
}
if (flag) {
hitCondition = t
break
} else if (i === field.conditions.length - 1) {
color = defaultColor
@@ -799,6 +801,7 @@ export function mappingColor(value, defaultColor, field, type, filedValueMap?, r
flag = true
}
if (flag) {
hitCondition = t
break
} else if (i === field.conditions.length - 1) {
color = defaultColor
@@ -843,13 +846,25 @@ export function mappingColor(value, defaultColor, field, type, filedValueMap?, r
flag = true
}
if (flag) {
hitCondition = fc
break
} else if (i === field.conditions.length - 1) {
color = defaultColor
}
}
}
return color
if(hitCondition && hitCondition.target === 'custom'){
return {
targetFieldId: hitCondition.targetFieldId,
color
}
}else{
return {
targetFieldId: field.fieldId,
color
}
}
}
function getFieldValueMap(view) {