feat: 账号数据看板/ 统一table、checkbox组件样式
This commit is contained in:
@ -54,3 +54,31 @@ export function formatNumberShow(...args: any[]): string | number {
|
||||
return split ? `${splitNumber(_n)}亿` : `${toFixed(_n, len)}亿`;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatTableField(fieldItem: any, rowValue: any, showExactValue = false) {
|
||||
// 获取嵌套属性值的函数
|
||||
const getNestedValue = (obj: any, path: string) => {
|
||||
if (!obj || !path) return undefined;
|
||||
|
||||
// 如果路径包含点号,说明是链式取值
|
||||
if (path.includes('.')) {
|
||||
return path.split('.').reduce((current, key) => {
|
||||
return current && current[key] !== undefined ? current[key] : undefined;
|
||||
}, obj);
|
||||
}
|
||||
|
||||
// 普通属性取值
|
||||
return obj[path];
|
||||
};
|
||||
|
||||
const _getValue = (value: any) => {
|
||||
if (isNaN(value)) return value;
|
||||
return formatNumberShow({ value, showExactValue });
|
||||
};
|
||||
|
||||
// 使用链式取值获取数据
|
||||
const rawValue = getNestedValue(rowValue, fieldItem.dataIndex);
|
||||
const value = _getValue(rawValue ?? '-');
|
||||
|
||||
return `${fieldItem.prefix || ''}${value}${fieldItem.suffix || ''}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user