Merge pull request #10402 from dataease/pr@dev-v2@feat_rich-text-threshold

fix(仪表板、数据大屏): 富文本支持阈值设置 #9371 #9627
This commit is contained in:
王嘉豪 2024-06-20 13:27:49 +08:00 committed by GitHub
commit 41c67d04b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 9 deletions

View File

@ -59,6 +59,8 @@ import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import ChartError from '@/views/chart/components/views/components/ChartError.vue' import ChartError from '@/views/chart/components/views/components/ChartError.vue'
import { useEmitt } from '@/hooks/web/useEmitt' import { useEmitt } from '@/hooks/web/useEmitt'
import { valueFormatter } from '@/views/chart/components/js/formatter' import { valueFormatter } from '@/views/chart/components/js/formatter'
import { parseJson } from '@/views/chart/components/js/util'
import { mappingColor } from '@/views/chart/components/js/panel/common/common_table'
const snapshotStore = snapshotStoreWithOut() const snapshotStore = snapshotStoreWithOut()
const errMsg = ref('') const errMsg = ref('')
const dvMainStore = dvMainStoreWithOut() const dvMainStore = dvMainStoreWithOut()
@ -103,6 +105,7 @@ const { element, editMode, active, disabled, showPosition } = toRefs(props)
const state = reactive({ const state = reactive({
data: null, data: null,
viewDataInfo: null,
totalItems: 0 totalItems: 0
}) })
const dataRowSelect = ref({}) const dataRowSelect = ref({})
@ -216,16 +219,18 @@ const initCurFieldsChange = () => {
const assignment = content => { const assignment = content => {
const on = content.match(/\[(.+?)\]/g) const on = content.match(/\[(.+?)\]/g)
if (on) { if (on) {
const thresholdStyleInfo = conditionAdaptor(state.viewDataInfo)
on.forEach(itm => { on.forEach(itm => {
if (dataRowFiledName.value.includes(itm)) { if (dataRowFiledName.value.includes(itm)) {
const ele = itm.slice(1, -1) const ele = itm.slice(1, -1)
if (initReady.value) { if (initReady.value) {
content = content.replace( const thresholdStyle = thresholdStyleInfo[ele]
itm, let value =
dataRowNameSelect.value[ele] !== undefined dataRowNameSelect.value[ele] !== undefined ? dataRowNameSelect.value[ele] : null
? dataRowNameSelect.value[ele] if (value && thresholdStyle) {
: '[未获取字段值]' value = `<span style="color:${thresholdStyle.color};background-color: ${thresholdStyle.backgroundColor}">${value}</span>`
) }
content = content.replace(itm, !!value ? value : '[未获取字段值]')
} else { } else {
content = content.replace( content = content.replace(
itm, itm,
@ -359,6 +364,7 @@ const calcData = (view: Chart, callback) => {
errMsg.value = res.msg errMsg.value = res.msg
} else { } else {
state.data = res?.data state.data = res?.data
state.viewDataInfo = res
state.totalItems = res?.totalItems state.totalItems = res?.totalItems
const curViewInfo = canvasViewInfo.value[element.value.id] const curViewInfo = canvasViewInfo.value[element.value.id]
curViewInfo['curFields'] = res.data.fields curViewInfo['curFields'] = res.data.fields
@ -449,6 +455,40 @@ const renderChart = () => {
initCurFieldsChange() initCurFieldsChange()
} }
const conditionAdaptor = (chart: Chart) => {
if (!chart) {
return
}
const { threshold } = parseJson(chart.senior)
if (!threshold.enable) {
return
}
const res = {}
const conditions = threshold.tableThreshold ?? []
if (conditions?.length > 0) {
for (let i = 0; i < conditions.length; i++) {
const field = conditions[i]
let defaultValueColor = 'none'
let defaultBgColor = 'none'
res[field.field.name] = {
color: mappingColor(
dataRowNameSelect.value[field.field.name],
defaultValueColor,
field,
'color'
),
backgroundColor: mappingColor(
dataRowNameSelect.value[field.field.name],
defaultBgColor,
field,
'backgroundColor'
)
}
}
}
return res
}
onMounted(() => { onMounted(() => {
viewInit() viewInit()
}) })

View File

@ -6,9 +6,10 @@ const { t } = useI18n()
* 富文本图表 * 富文本图表
*/ */
export class RichTextChartView extends AbstractChartView { export class RichTextChartView extends AbstractChartView {
properties: EditorProperty[] = ['background-overall-component'] properties: EditorProperty[] = ['background-overall-component', 'threshold']
propertyInner: EditorPropertyInner = { propertyInner: EditorPropertyInner = {
'background-overall-component': ['all'] 'background-overall-component': ['all'],
threshold: ['tableThreshold']
} }
axis: AxisType[] = ['xAxis', 'yAxis', 'filter'] axis: AxisType[] = ['xAxis', 'yAxis', 'filter']
axisConfig: AxisConfig = { axisConfig: AxisConfig = {

View File

@ -458,7 +458,7 @@ export function getConditions(chart: Chart) {
return res return res
} }
function mappingColor(value, defaultColor, field, type) { export function mappingColor(value, defaultColor, field, type) {
let color let color
for (let i = 0; i < field.conditions.length; i++) { for (let i = 0; i < field.conditions.length; i++) {
let flag = false let flag = false