102 lines
3.3 KiB
TypeScript
102 lines
3.3 KiB
TypeScript
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||
import { getPortfolioSummary } from '@/actions/portfolio';
|
||
import { formatQuantity, formatAmount } from '@/lib/formatters';
|
||
import AllocationChart from '@/components/dashboard/allocation-chart';
|
||
|
||
const CHART_COLORS = [
|
||
'#3b82f6',
|
||
'#8b5cf6',
|
||
'#10b981',
|
||
'#f59e0b',
|
||
'#ef4444',
|
||
'#06b6d4',
|
||
];
|
||
|
||
export default async function DashboardPage() {
|
||
const { positions, totalCnyValue, chartData } = await getPortfolioSummary();
|
||
|
||
const formattedTotal = formatAmount(totalCnyValue);
|
||
|
||
const displayChartData = chartData.map((item) => ({
|
||
...item,
|
||
value: Number(item.value),
|
||
}));
|
||
|
||
return (
|
||
<div className="space-y-6">
|
||
<div>
|
||
<h1 className="text-3xl font-bold">欢迎来到 Omniledger</h1>
|
||
<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>
|
||
<CardContent className="pt-6">
|
||
<p className="text-muted-foreground">暂无持仓,请先添加资产和交易记录。</p>
|
||
</CardContent>
|
||
</Card>
|
||
) : (
|
||
positions.map((pos) => (
|
||
<Card key={pos.assetId}>
|
||
<CardHeader>
|
||
<CardTitle className="flex items-center justify-between">
|
||
<span>{pos.symbol}</span>
|
||
<span className="text-sm font-normal text-muted-foreground">
|
||
{pos.type}
|
||
</span>
|
||
</CardTitle>
|
||
</CardHeader>
|
||
<CardContent>
|
||
<div className="space-y-2">
|
||
<div className="flex justify-between">
|
||
<span className="text-muted-foreground">持仓数量</span>
|
||
<span className="font-medium">
|
||
{formatQuantity(pos.quantity, pos.type)}
|
||
</span>
|
||
</div>
|
||
<div className="flex justify-between">
|
||
<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>
|
||
))
|
||
)}
|
||
</div>
|
||
|
||
<Card>
|
||
<CardHeader>
|
||
<CardTitle>资产分布</CardTitle>
|
||
</CardHeader>
|
||
<CardContent>
|
||
<AllocationChart data={displayChartData} />
|
||
</CardContent>
|
||
</Card>
|
||
</div>
|
||
);
|
||
}
|