import { useState, useEffect } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Users, Settings, Shield, Activity, AlertTriangle, Search, Edit, Trash2, UserPlus, Database, Server, BarChart3 } from "lucide-react"; import { api } from "@/shared/config/database"; import type { Profile } from "@/shared/types"; import { toast } from "sonner"; export default function AdminDashboard() { const user = null as any; const [profiles, setProfiles] = useState([]); const [loading, setLoading] = useState(true); const [searchTerm, setSearchTerm] = useState(""); const [editingUser, setEditingUser] = useState(null); const [showEditDialog, setShowEditDialog] = useState(false); useEffect(() => { loadProfiles(); }, []); const loadProfiles = async () => { try { setLoading(true); const data = await api.getAllProfiles(); setProfiles(data); } catch (error) { console.error('Failed to load profiles:', error); toast.error("加载用户数据失败"); } finally { setLoading(false); } }; const handleUpdateUserRole = async (userId: string, newRole: 'admin' | 'member') => { try { await api.updateProfile(userId, { role: newRole }); toast.success("用户角色更新成功"); loadProfiles(); } catch (error) { console.error('Failed to update user role:', error); toast.error("更新用户角色失败"); } }; const formatDate = (dateString: string) => { return new Date(dateString).toLocaleDateString('zh-CN', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }); }; const filteredProfiles = profiles.filter(profile => profile.full_name?.toLowerCase().includes(searchTerm.toLowerCase()) || profile.phone?.toLowerCase().includes(searchTerm.toLowerCase()) || profile.email?.toLowerCase().includes(searchTerm.toLowerCase()) ); // 检查当前用户是否为管理员 const isAdmin = true; if (!isAdmin) { return (

访问被拒绝

您没有权限访问管理员面板

); } if (loading) { return (
); } return (
{/* 页面标题 */}

系统管理

管理系统用户、配置和监控系统状态

管理员权限
{/* 统计卡片 */}

总用户数

{profiles.length}

管理员

{profiles.filter(p => p.role === 'admin').length}

活跃用户

{profiles.filter(p => p.role === 'member').length}

系统状态

正常

{/* 主要内容 */} 用户管理 系统监控 系统设置 操作日志 {/* 搜索和操作 */}
setSearchTerm(e.target.value)} className="pl-10" />
{/* 用户列表 */} 用户列表 ({filteredProfiles.length})
{filteredProfiles.map((profile) => (
{profile.full_name?.charAt(0) || profile.phone?.charAt(0) || 'U'}

{profile.full_name || '未设置姓名'}

{profile.phone && ( 📱 {profile.phone} )} {profile.email && ( 📧 {profile.email} )}

注册时间:{formatDate(profile.created_at)}

{profile.role === 'admin' ? '管理员' : '普通用户'} {profile.id !== user?.id && ( )}
))}
{/* 系统性能 */} 系统性能
CPU 使用率 15%
内存使用率 32%
磁盘使用率 58%
{/* 数据库状态 */} 数据库状态
连接状态 正常
活跃连接 12
查询响应时间 45ms
存储使用量 2.3GB
{/* 系统日志 */} 系统日志

系统启动成功

2024-01-15 09:00:00

新用户注册

2024-01-15 08:45:00

数据库连接超时

2024-01-15 08:30:00

系统设置

此功能正在开发中

操作日志

此功能正在开发中

); }