This commit is contained in:
freedakgmail
2025-11-23 00:49:16 +08:00
parent c033e46782
commit 626d7dddde
184 changed files with 321926 additions and 2720 deletions
+48 -28
View File
@@ -9,11 +9,20 @@ import { ScrollArea } from "@/components/ui/scroll-area"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { UserPlus, Network, Map, Calendar, Users, ArrowRight, Clock, Search, BookOpen, BarChart3 } from "lucide-react"
import { useFamily } from "@/context/family-context"
import { useMemo } from "react"
import { useMemo, useState, useEffect } from "react"
import { StatisticsCharts } from "@/components/dashboard/statistics-charts"
import { getActivityLogs } from "@/lib/activity-logger"
import type { ActivityLog } from "@/lib/db"
import { format } from "date-fns"
export default function DashboardPage() {
const { treeData } = useFamily()
const [recentActivities, setRecentActivities] = useState<ActivityLog[]>([])
// 加载最近的操作日志
useEffect(() => {
getActivityLogs(10).then(setRecentActivities)
}, [treeData])
// 计算统计数据
const stats = useMemo(() => {
@@ -161,37 +170,48 @@ export default function DashboardPage() {
</CardHeader>
<CardContent>
<ScrollArea className="h-[400px] pr-4">
<div className="space-y-6">
{recentMembers.length > 0 ? (
recentMembers.map((member, i) => (
<Link href={`/members/${member.id}`} key={member.id}>
<div className="flex gap-4 group hover:bg-muted/30 p-2 rounded-lg transition-colors cursor-pointer">
<div className="relative flex flex-col items-center">
<div className="h-full w-px bg-border group-last:hidden"></div>
<div className="absolute top-2 h-2 w-2 rounded-full bg-primary ring-4 ring-background"></div>
</div>
<div className="pb-2 flex-1">
<div className="flex items-center gap-2 mb-1">
<span className="font-medium">{member.fullName}</span>
<span className="text-xs px-2 py-0.5 rounded-full bg-secondary/20 text-secondary-foreground">
{member.generation}
</span>
<span className="text-xs text-muted-foreground">
{member.gender === 'male' ? '男' : '女'}
</span>
</div>
<p className="text-sm text-muted-foreground">
{member.birthDate && `生于 ${member.birthDate.split('-')[0]}`}
{member.deathDate && ` · 卒于 ${member.deathDate.split('-')[0]}`}
{!member.deathDate && member.birthDate && ` · 在世`}
</p>
</div>
<div className="space-y-4">
{recentActivities.length > 0 ? (
recentActivities.map((activity, i) => (
<div key={activity.id} className="flex gap-3 group hover:bg-muted/30 p-2 rounded-lg transition-colors">
<div className="relative flex flex-col items-center">
<div className="h-full w-px bg-border group-last:hidden"></div>
<div className={`absolute top-2 h-2 w-2 rounded-full ring-4 ring-background ${
activity.action === 'create' ? 'bg-green-500' :
activity.action === 'update' ? 'bg-blue-500' :
activity.action === 'delete' ? 'bg-red-500' :
'bg-purple-500'
}`}></div>
</div>
</Link>
<div className="pb-2 flex-1">
<div className="flex items-center gap-2 mb-1 flex-wrap">
<span className={`text-xs px-2 py-0.5 rounded-full ${
activity.action === 'create' ? 'bg-green-100 text-green-700' :
activity.action === 'update' ? 'bg-blue-100 text-blue-700' :
activity.action === 'delete' ? 'bg-red-100 text-red-700' :
'bg-purple-100 text-purple-700'
}`}>
{activity.action === 'create' ? '创建' :
activity.action === 'update' ? '更新' :
activity.action === 'delete' ? '删除' : '导入'}
</span>
<span className="font-medium">{activity.entityName || '未知'}</span>
<span className="text-xs text-muted-foreground">
{format(new Date(activity.timestamp), 'MM-dd HH:mm')}
</span>
</div>
<p className="text-xs text-muted-foreground">
{activity.action === 'create' && '新增了家族成员'}
{activity.action === 'update' && '更新了成员信息'}
{activity.action === 'delete' && '删除了成员'}
{activity.action === 'import' && '导入了家族数据'}
</p>
</div>
</div>
))
) : (
<div className="text-center text-muted-foreground py-8">
</div>
)}
</div>