0.3.0.0
This commit is contained in:
+49
-18
@@ -3,15 +3,16 @@
|
||||
import type React from "react"
|
||||
import Link from "next/link"
|
||||
import Image from "next/image"
|
||||
import dynamic from "next/dynamic"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { SiteHeader } from "@/components/site-header"
|
||||
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, Calculator } from "lucide-react"
|
||||
import { UserPlus, Network, Map, Calendar, Users, ArrowRight, Clock, Search, BookOpen, BarChart3, Calculator, Loader2 } from "lucide-react"
|
||||
import { useFamily } from "@/context/family-context"
|
||||
import { useMemo, useState, useEffect, useRef } from "react"
|
||||
import { StatisticsCharts } from "@/components/dashboard/statistics-charts"
|
||||
import { useMemo, useState, useEffect, useRef, useCallback } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { format } from "date-fns"
|
||||
import { useSession } from "next-auth/react"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
@@ -20,6 +21,20 @@ import { permissions } from "@/lib/permissions"
|
||||
import { isInCurrentMonth, solar2lunar, lunar2solar } from "@/lib/lunar-calendar"
|
||||
import { MemberNameWithStatus } from "@/components/member-name-with-status"
|
||||
|
||||
// 动态导入统计图表组件(减少初始加载体积)
|
||||
const StatisticsCharts = dynamic(
|
||||
() => import("@/components/dashboard/statistics-charts").then(mod => ({ default: mod.StatisticsCharts })),
|
||||
{
|
||||
ssr: false,
|
||||
loading: () => (
|
||||
<div className="w-full h-64 flex items-center justify-center">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
||||
<span className="ml-2 text-muted-foreground">加载统计图表...</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
interface ActivityLog {
|
||||
id: string
|
||||
action: string
|
||||
@@ -38,17 +53,14 @@ export default function DashboardPage() {
|
||||
const { treeData, isLoading, currentTree } = useFamily()
|
||||
const { data: session } = useSession()
|
||||
const [recentActivities, setRecentActivities] = useState<ActivityLog[]>([])
|
||||
const router = useRouter()
|
||||
|
||||
// 检查是否首次登录,如果是则跳转到帮助页面
|
||||
// 首次登录跳转到使用帮助
|
||||
useEffect(() => {
|
||||
if (session?.user?.id) {
|
||||
const hasVisited = localStorage.getItem(`user_${session.user.id}_visited`)
|
||||
if (!hasVisited) {
|
||||
localStorage.setItem(`user_${session.user.id}_visited`, 'true')
|
||||
window.location.href = '/help'
|
||||
}
|
||||
}
|
||||
}, [session?.user?.id])
|
||||
if (!session?.user?.id) return
|
||||
if (session.user.hasSeenHelp) return
|
||||
router.replace('/help')
|
||||
}, [router, session?.user?.id, session?.user?.hasSeenHelp])
|
||||
|
||||
// 加载最近的操作日志
|
||||
useEffect(() => {
|
||||
@@ -578,12 +590,31 @@ export default function DashboardPage() {
|
||||
activity.action === 'DELETE' ? '删除' : '导入'}
|
||||
</span>
|
||||
{activity.entityId && activity.entityType === 'MEMBER' ? (
|
||||
<Link
|
||||
href={`/members/${activity.entityId}${currentTree?.id ? `?treeId=${currentTree.id}` : ''}`}
|
||||
className="font-medium hover:text-primary hover:underline transition-colors"
|
||||
>
|
||||
{activity.entityName || '未知'}
|
||||
</Link>
|
||||
(() => {
|
||||
const member = treeData.members[activity.entityId!]
|
||||
if (member) {
|
||||
return (
|
||||
<MemberNameWithStatus
|
||||
name={activity.entityName || member.fullName || '未知'}
|
||||
isDead={!!member.deathDate}
|
||||
memberId={activity.entityId}
|
||||
treeId={currentTree?.id}
|
||||
className="font-medium"
|
||||
/>
|
||||
)
|
||||
}
|
||||
// 成员不存在(可能已删除),不显示状态点,但保留链接(如果不是删除操作)
|
||||
return activity.action === 'DELETE' ? (
|
||||
<span className="font-medium">{activity.entityName || '未知'}</span>
|
||||
) : (
|
||||
<Link
|
||||
href={`/members/${activity.entityId}${currentTree?.id ? `?treeId=${currentTree.id}` : ''}`}
|
||||
className="font-medium hover:text-primary hover:underline transition-colors"
|
||||
>
|
||||
{activity.entityName || '未知'}
|
||||
</Link>
|
||||
)
|
||||
})()
|
||||
) : (
|
||||
<span className="font-medium">{activity.entityName || '未知'}</span>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user