factor:布局颜色重构

This commit is contained in:
2025-11-20 13:37:56 +08:00
parent 50d7657a93
commit 8f0f641d37
10 changed files with 159 additions and 118 deletions

View File

@@ -26,3 +26,28 @@ PageResult<T> convertPageResponse<T>(
'Expected a Map for page response conversion, but got ${data.runtimeType}',
);
}
/// 将数字格式化为中文单位(万/亿)
String formatChineseDecimal(num number, {int decimalPlaces = 2}) {
if (number < 10000) {
return number.toString();
} else if (number < 100000000) {
// 万单位
double result = number / 10000.0;
return '${_formatDecimal(result, decimalPlaces)}';
} else {
// 亿单位
double result = number / 100000000.0;
return '${_formatDecimal(result, decimalPlaces)}亿';
}
}
String _formatDecimal(double number, int decimalPlaces) {
// 去除末尾的0和小数点
String formatted = number.toStringAsFixed(decimalPlaces);
if (formatted.contains('.')) {
formatted = formatted.replaceAll(RegExp(r'0*$'), '');
formatted = formatted.replaceAll(RegExp(r'\.$'), '');
}
return formatted;
}