Browse Source

feat(dashboard): hide overview panel for non-admin users

对于非 admin token 用户,在首页隐藏概览面板,包括:
- 当前并发、今日请求、今日消耗、平均响应等统计指标
- 活跃 Session 列表
- 点击查看详情按钮

admin 用户保持原有功能不变。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
ding113 3 months ago
parent
commit
2bc5223301
2 changed files with 12 additions and 2 deletions
  1. 4 1
      src/app/dashboard/page.tsx
  2. 8 1
      src/components/customs/overview-panel.tsx

+ 4 - 1
src/app/dashboard/page.tsx

@@ -27,9 +27,12 @@ export default async function DashboardPage() {
     getSystemSettings(),
   ]);
 
+  // 检查是否是 admin 用户
+  const isAdmin = session?.user?.role === "admin";
+
   return (
     <div className="space-y-6">
-      <OverviewPanel currencyCode={systemSettings.currencyDisplay} />
+      <OverviewPanel currencyCode={systemSettings.currencyDisplay} isAdmin={isAdmin} />
 
       <div>
         <StatisticsWrapper

+ 8 - 1
src/components/customs/overview-panel.tsx

@@ -151,6 +151,7 @@ function SessionListItem({
 
 interface OverviewPanelProps {
   currencyCode?: CurrencyCode;
+  isAdmin?: boolean;
 }
 
 /**
@@ -158,13 +159,14 @@ interface OverviewPanelProps {
  * 左侧:4个指标卡片
  * 右侧:简洁的活跃 Session 列表
  */
-export function OverviewPanel({ currencyCode = "USD" }: OverviewPanelProps) {
+export function OverviewPanel({ currencyCode = "USD", isAdmin = false }: OverviewPanelProps) {
   const router = useRouter();
 
   const { data, isLoading } = useQuery<OverviewData, Error>({
     queryKey: ["overview-data"],
     queryFn: fetchOverviewData,
     refetchInterval: REFRESH_INTERVAL,
+    enabled: isAdmin, // 仅当用户是 admin 时才获取数据
   });
 
   // 格式化响应时间
@@ -181,6 +183,11 @@ export function OverviewPanel({ currencyCode = "USD" }: OverviewPanelProps) {
     recentSessions: [],
   };
 
+  // 对于非 admin 用户,不显示概览面板
+  if (!isAdmin) {
+    return null;
+  }
+
   return (
     <div className="grid grid-cols-1 lg:grid-cols-12 gap-4 w-full">
       {/* 左侧:指标卡片区域 */}