From 7d7a7804a67ff890c8f08daf09777a7ff2b5d5c5 Mon Sep 17 00:00:00 2001 From: kennethcheng Date: Tue, 28 Apr 2026 19:18:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ui):=20=E8=A7=84=E8=8C=83=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E5=8D=A1=E7=89=87=E6=9C=AF=E8=AF=AD=EF=BC=8C=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E9=9A=90=E8=97=8F=E5=90=8C=E5=B8=81=E7=A7=8D=E5=8F=8C?= =?UTF-8?q?=E8=BD=A8=E5=88=B6=E5=86=97=E4=BD=99=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/dashboard/page.tsx | 32 ++++++++++++++++++-------------- src/actions/portfolio.ts | 9 +++++++-- 2 files changed, 25 insertions(+), 16 deletions(-) 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(), }); }