feat(dashboard): 接入汇率引擎,实现多资产交叉汇率折算与 CNY 统一计价看板
This commit is contained in:
+31
-8
@@ -1,6 +1,6 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { getPortfolioPositions } from '@/actions/portfolio';
|
||||
import { formatQuantity } from '@/lib/formatters';
|
||||
import { getPortfolioSummary } from '@/actions/portfolio';
|
||||
import { formatQuantity, formatAmount } from '@/lib/formatters';
|
||||
import AllocationChart from '@/components/dashboard/allocation-chart';
|
||||
|
||||
const CHART_COLORS = [
|
||||
@@ -13,12 +13,13 @@ const CHART_COLORS = [
|
||||
];
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const positions = await getPortfolioPositions();
|
||||
const { positions, totalCnyValue, chartData } = await getPortfolioSummary();
|
||||
|
||||
const chartData = positions.map((pos, index) => ({
|
||||
name: pos.symbol,
|
||||
value: Number(pos.quantity),
|
||||
fill: CHART_COLORS[index % CHART_COLORS.length],
|
||||
const formattedTotal = formatAmount(totalCnyValue);
|
||||
|
||||
const displayChartData = chartData.map((item) => ({
|
||||
...item,
|
||||
value: Number(item.value),
|
||||
}));
|
||||
|
||||
return (
|
||||
@@ -28,6 +29,22 @@ export default async function DashboardPage() {
|
||||
<p className="text-muted-foreground">您的跨界记账中枢。</p>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardContent className="pt-6 pb-6">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-2xl font-semibold text-muted-foreground">
|
||||
¥
|
||||
</span>
|
||||
<span className="text-5xl font-bold">
|
||||
{formattedTotal}
|
||||
</span>
|
||||
<span className="text-xl text-muted-foreground ml-2">
|
||||
总资产 (CNY)
|
||||
</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
{positions.length === 0 ? (
|
||||
<Card>
|
||||
@@ -58,6 +75,12 @@ export default async function DashboardPage() {
|
||||
<span className="text-muted-foreground">结算币种</span>
|
||||
<span className="font-medium">{pos.baseCurrency}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted-foreground">CNY 估值</span>
|
||||
<span className="font-medium text-green-600">
|
||||
¥{formatAmount(pos.cnyValue)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -70,7 +93,7 @@ export default async function DashboardPage() {
|
||||
<CardTitle>资产分布</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<AllocationChart data={chartData} />
|
||||
<AllocationChart data={displayChartData} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user