style(portfolio): 优化 CSV 导出字段格式,精准剥离价格末尾的无意义零

This commit is contained in:
2026-05-02 15:19:48 +08:00
parent 3e81c1dc5b
commit e692d47b6a
2 changed files with 17 additions and 2 deletions
+12 -2
View File
@@ -56,14 +56,24 @@ function formatNative(value: string, baseCurrency: string): string {
}
function exportToCSV(positions: any[]) {
const stripTrailingZeros = (val: any): string => {
if (val === null || val === undefined || val === '') return "0";
let str = String(val);
if (str.includes('.')) {
str = str.replace(/0+$/, '');
str = str.replace(/\.$/, '');
}
return str;
};
const headers = ["资产名称", "代码", "持仓量", "成本价", "现价", "总市值", "浮动盈亏", "累计盈亏"];
const rows = positions.map(item => [
item.name || item.symbol,
item.symbol,
item.quantity || '0',
new Big(item.avgCostNative || '0').toFixed(2),
item.latestPrice || '0',
stripTrailingZeros(new Big(item.avgCostNative || '0').toFixed(2)),
stripTrailingZeros(item.latestPrice || '0'),
new Big(item.marketValueNative || '0').toFixed(2),
new Big(item.floatingPnlNative || '0').toFixed(2),
new Big(item.cumulativePnlNative || '0').toFixed(2),