diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index 4f61b41..2ad68f9 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -118,26 +118,30 @@ export default async function DashboardPage() { {pos.holdingDays} 天 -
- 持仓成本 ({pos.baseCurrency}) - - {formatAmount(pos.totalCostNative)} - -
-
- 当前盈亏 ({pos.baseCurrency}) - - {posPnlNativePositive ? '+' : ''}{formatAmount(pos.pnlNative)} - -
+ {pos.baseCurrency !== 'CNY' && ( + <> +
+ 持仓成本 ({pos.baseCurrency}) + + {formatAmount(pos.totalCostNative)} + +
+
+ 当前盈亏 ({pos.baseCurrency}) + + {posPnlNativePositive ? '+' : ''}{formatAmount(pos.pnlNative)} + +
+ + )}
- 成本 (CNY) + 投入本金 (CNY) ¥{formatAmount(pos.totalCostCny)}
- 盈亏 (CNY) + 综合总盈亏 (CNY) {posPnlPositive ? '+' : ''}{formattedPosPnl} diff --git a/src/actions/portfolio.ts b/src/actions/portfolio.ts index 73757ed..16c7d99 100644 --- a/src/actions/portfolio.ts +++ b/src/actions/portfolio.ts @@ -26,6 +26,7 @@ interface Position { holdingDays: number; exchange: string; accumulatedDividendsCny: string; + accumulatedDividendsNative: string; } interface RawRate { @@ -159,6 +160,7 @@ export async function getPortfolioPositions(): Promise { // 已实现盈亏 realizedPnlCny: Big; accumulatedDividendsCny: Big; + accumulatedDividendsNative: Big; // 首次买入日期 firstBuyDate: Date | null; }>(); @@ -182,6 +184,7 @@ export async function getPortfolioPositions(): Promise { totalBuyQuantity: new Big('0'), realizedPnlCny: new Big('0'), accumulatedDividendsCny: new Big('0'), + accumulatedDividendsNative: new Big('0'), firstBuyDate: null, }); } @@ -235,6 +238,7 @@ export async function getPortfolioPositions(): Promise { const dividendAmountNative = new Big(tx.quantity).times(new Big(tx.price)); const dividendCny = dividendAmountNative.times(new Big(tx.exchangeRate || '1')); holding.accumulatedDividendsCny = holding.accumulatedDividendsCny.plus(dividendCny); + holding.accumulatedDividendsNative = holding.accumulatedDividendsNative.plus(dividendAmountNative); } if (tx.assetLatestPrice) { @@ -261,7 +265,7 @@ export async function getPortfolioPositions(): Promise { const totalPnlCny = unrealizedPnlCny.plus(holding.realizedPnlCny).plus(holding.accumulatedDividendsCny); const currentNativeValue = new Big(holding.latestPrice).times(holding.quantity); - const pnlNative = currentNativeValue.minus(holding.totalBuyCostNative); + const pnlNative = currentNativeValue.minus(holding.totalBuyCostNative).plus(holding.accumulatedDividendsNative); // 平均成本 = 总买入成本 / 总买入数量 let avgCost = new Big('0'); @@ -300,8 +304,9 @@ export async function getPortfolioPositions(): Promise { avgCost: avgCost.toString(), dilutedCost: dilutedCost.toString(), holdingDays, - exchange: holding.exchange, + exchange: holding.exchange, accumulatedDividendsCny: holding.accumulatedDividendsCny.toString(), + accumulatedDividendsNative: holding.accumulatedDividendsNative.toString(), }); }