fix: PC表格支持以百分比显示持有收益

This commit is contained in:
hzm
2026-02-27 10:50:21 +08:00
parent bf791949d0
commit 510664c4d3

View File

@@ -721,10 +721,17 @@ export default function HomePage() {
const todayProfitValue = profitToday; const todayProfitValue = profitToday;
const total = profit ? profit.profitTotal : null; const total = profit ? profit.profitTotal : null;
const principal =
holding && isNumber(holding.cost) && isNumber(holding.share)
? holding.cost * holding.share
: 0;
const asPercent = !!percentModes[f.code];
const holdingProfit = const holdingProfit =
total == null total == null
? '' ? ''
: `${total > 0 ? '+' : total < 0 ? '-' : ''}¥${Math.abs(total).toFixed(2)}`; : (asPercent && principal > 0
? `${total > 0 ? '+' : total < 0 ? '-' : ''}${Math.abs((total / principal) * 100).toFixed(2)}%`
: `${total > 0 ? '+' : total < 0 ? '-' : ''}¥${Math.abs(total).toFixed(2)}`);
const holdingProfitValue = total; const holdingProfitValue = total;
return { return {
@@ -748,7 +755,7 @@ export default function HomePage() {
holdingProfitValue, holdingProfitValue,
}; };
}), }),
[displayFunds, holdings, isTradingDay, todayStr, getHoldingProfit], [displayFunds, holdings, isTradingDay, todayStr, getHoldingProfit, percentModes],
); );
// 自动滚动选中 Tab 到可视区域 // 自动滚动选中 Tab 到可视区域