forked from github/dataease
Merge pull request #3181 from dataease/pr@dev@fix_rich-text-view-format
fix(仪表板): 修复富文本视图指标格式化未生效问题
This commit is contained in:
commit
17ad256d9f
@ -141,6 +141,7 @@ import { viewEditSave, viewPropsSave } from '@/api/chart/chart'
|
||||
import { checkAddHttp } from '@/utils/urlUtils'
|
||||
import DeRichTextView from '@/components/canvas/custom-component/DeRichTextView'
|
||||
import Vue from 'vue'
|
||||
import { formatterItem, valueFormatter } from '@/views/chart/chart/formatter'
|
||||
|
||||
export default {
|
||||
name: 'UserView',
|
||||
@ -653,7 +654,20 @@ export default {
|
||||
pre[next['dataeaseName']] = next['name']
|
||||
return pre
|
||||
}, {})
|
||||
let yAxis = []
|
||||
try {
|
||||
yAxis = JSON.parse(chartDetails.yaxis)
|
||||
} catch (err) {
|
||||
yAxis = JSON.parse(JSON.stringify(chartDetails.yaxis))
|
||||
}
|
||||
let yDataeaseNames = []
|
||||
let yDataeaseNamesCfg = []
|
||||
yAxis.forEach(yItem => {
|
||||
yDataeaseNames.push(yItem.dataeaseName)
|
||||
yDataeaseNamesCfg[yItem.dataeaseName]=yItem.formatterCfg
|
||||
})
|
||||
const rowData = chartDetails.data.tableRow[0]
|
||||
this.rowDataFormat(rowData,yDataeaseNames,yDataeaseNamesCfg)
|
||||
for (const key in rowData) {
|
||||
this.dataRowSelect[nameIdMap[key]] = rowData[key]
|
||||
this.dataRowNameSelect[sourceFieldNameIdMap[key]] = rowData[key]
|
||||
@ -666,6 +680,25 @@ export default {
|
||||
})
|
||||
}
|
||||
},
|
||||
rowDataFormat(rowData,yDataeaseNames,yDataeaseNamesCfg) {
|
||||
for (const key in rowData) {
|
||||
if(yDataeaseNames.includes(key)){
|
||||
let formatterCfg = yDataeaseNamesCfg[key]
|
||||
let value = rowData[key]
|
||||
if (value === null || value === undefined) {
|
||||
rowData[key] = '-'
|
||||
}
|
||||
if (formatterCfg) {
|
||||
const v = valueFormatter(value, formatterCfg)
|
||||
rowData[key] = v.includes('NaN') ? value : v
|
||||
} else {
|
||||
const v = valueFormatter(value, formatterItem)
|
||||
rowData[key] = v.includes('NaN') ? value : v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
viewIdMatch(viewIds, viewId) {
|
||||
return !viewIds || viewIds.length === 0 || viewIds.includes(viewId)
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user