perf: 优化数字格式
This commit is contained in:
@@ -3,6 +3,17 @@ import {useParams} from 'react-router'
|
||||
import {amisRender, commonInfo, readOnlyDialogOptions, remoteMappings} from '../../util/amis.tsx'
|
||||
import type {Schema} from 'amis'
|
||||
|
||||
// 格式化财务数字显示的公共函数
|
||||
const formatFinanceNumber = (value: number): string => {
|
||||
if (value >= 100000000) {
|
||||
return (value / 100000000).toFixed(2) + '亿'
|
||||
} else if (value >= 10000) {
|
||||
return (value / 10000).toFixed(2) + '万'
|
||||
} else {
|
||||
return value.toLocaleString()
|
||||
}
|
||||
}
|
||||
|
||||
const financePropertyLabel = (id: string | undefined, label: string, type: string, field: string): Schema => {
|
||||
if (!id) {
|
||||
return {
|
||||
@@ -45,6 +56,10 @@ const financePropertyLabel = (id: string | undefined, label: string, type: strin
|
||||
color: '#333',
|
||||
},
|
||||
padding: [10, 15],
|
||||
formatter: (params: any) => {
|
||||
const item = params[0]
|
||||
return `${item.name}<br/>${item.marker}${formatFinanceNumber(item.value)}`
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
left: '5%',
|
||||
@@ -90,6 +105,9 @@ const financePropertyLabel = (id: string | undefined, label: string, type: strin
|
||||
axisLabel: {
|
||||
color: '#999',
|
||||
fontSize: 12,
|
||||
formatter: (value: number) => {
|
||||
return formatFinanceNumber(value)
|
||||
},
|
||||
},
|
||||
axisTick: {
|
||||
show: false,
|
||||
@@ -134,6 +152,9 @@ const financePropertyLabel = (id: string | undefined, label: string, type: strin
|
||||
color: '#333',
|
||||
fontWeight: 'bold',
|
||||
fontSize: 12,
|
||||
formatter: (params: any) => {
|
||||
return formatFinanceNumber(params.value)
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user