From 3126efc00dafb429e1f2c6200b979b005aa68bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Mon, 21 Apr 2025 12:09:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=AE=A1=E5=90=8E=E5=8F=B0=20-=20?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E6=A6=82=E8=BF=B0=E8=8E=B7=E5=8F=96=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E7=BB=9F=E8=AE=A1=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SuperAdmin/app/dashboard/page.tsx | 90 +++++++++++++++---------------- 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/SuperAdmin/app/dashboard/page.tsx b/SuperAdmin/app/dashboard/page.tsx index c3fb6c2d..3550cf9f 100644 --- a/SuperAdmin/app/dashboard/page.tsx +++ b/SuperAdmin/app/dashboard/page.tsx @@ -1,65 +1,59 @@ "use client" -import { useEffect, useState } from "react" +import { useState, useEffect } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" -import { Users, FolderKanban, UserCog } from "lucide-react" -import useAuthCheck from "@/hooks/useAuthCheck" -import { getAdminInfo, getGreeting } from "@/lib/utils" -import ClientOnly from "@/components/ClientOnly" +import { Building2, Users, UserCog } from "lucide-react" +import { toast } from "sonner" + +interface DashboardStats { + companyCount: number + adminCount: number + customerCount: number +} export default function DashboardPage() { - const [greeting, setGreeting] = useState("") - const [userName, setUserName] = useState("") - - // 验证用户是否已登录 - useAuthCheck() + const [stats, setStats] = useState({ + companyCount: 0, + adminCount: 0, + customerCount: 0 + }) + const [isLoading, setIsLoading] = useState(true) useEffect(() => { - // 获取用户信息 - const adminInfo = getAdminInfo() - if (adminInfo) { - setUserName(adminInfo.name || "管理员") - } else { - setUserName("管理员") - } - }, []) + const fetchStats = async () => { + try { + const response = await fetch("http://yishi.com/dashboard/base") + const data = await response.json() - // 单独处理问候语,避免依赖问题 - useEffect(() => { - // 设置问候语 - const updateGreeting = () => { - if (userName) { - setGreeting(getGreeting(userName)) + if (data.code === 200) { + setStats(data.data) + } else { + toast.error(data.msg || "获取统计信息失败") + } + } catch (error) { + toast.error("网络错误,请稍后重试") + } finally { + setIsLoading(false) } } - - updateGreeting() - - // 每分钟更新一次问候语,以防用户长时间停留在页面 - const interval = setInterval(updateGreeting, 60000) - - return () => clearInterval(interval) - }, [userName]) + + fetchStats() + }, []) return (
-

欢迎使用超级管理员后台

-

- - {greeting || getGreeting(userName)} - - !通过此平台,您可以管理项目、客户和管理员权限。 -

+

仪表盘

-
+
项目总数 - + -
24
-

较上月增长 12%

+
+ {isLoading ? "..." : stats.companyCount} +
@@ -69,8 +63,9 @@ export default function DashboardPage() { -
1,284
-

较上月增长 8%

+
+ {isLoading ? "..." : stats.customerCount} +
@@ -80,8 +75,9 @@ export default function DashboardPage() { -
8
-

较上月增长 2 人

+
+ {isLoading ? "..." : stats.adminCount} +