import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { ChevronRight, Settings, Bell, LogOut, Smartphone, MessageCircle, Database, FolderOpen } from 'lucide-react'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { useAuth } from '@/contexts/AuthContext'; import { useToast } from '@/components/ui/toast'; import Layout from '@/components/Layout'; import BottomNav from '@/components/BottomNav'; import UnifiedHeader from '@/components/UnifiedHeader'; import '@/components/Layout.css'; export default function Profile() { const navigate = useNavigate(); const { user, logout, isAuthenticated } = useAuth(); const { toast } = useToast(); const [showLogoutDialog, setShowLogoutDialog] = useState(false); const [userInfo, setUserInfo] = useState(null); const [stats, setStats] = useState({ devices: 12, wechat: 25, traffic: 8, content: 156, }); // 从localStorage获取用户信息 useEffect(() => { const userInfoStr = localStorage.getItem('userInfo'); if (userInfoStr) { setUserInfo(JSON.parse(userInfoStr)); } }, []); // 用户信息 const currentUserInfo = { name: userInfo?.username || user?.username || "卡若", email: userInfo?.email || "zhangsan@example.com", role: "管理员", joinDate: "2023-01-15", lastLogin: "2024-01-20 14:30", }; // 功能模块数据 const functionModules = [ { id: "devices", title: "设备管理", description: "管理您的设备和微信账号", icon: , count: stats.devices, path: "/devices", bgColor: "bg-blue-50", }, { id: "wechat", title: "微信号管理", description: "管理微信账号和好友", icon: , count: stats.wechat, path: "/wechat-accounts", bgColor: "bg-green-50", }, { id: "traffic", title: "流量池", description: "管理用户流量池和分组", icon: , count: stats.traffic, path: "/traffic-pool", bgColor: "bg-purple-50", }, { id: "content", title: "内容库", description: "管理营销内容和素材", icon: , count: stats.content, path: "/content", bgColor: "bg-orange-50", }, ]; // 加载统计数据 const loadStats = async () => { try { // 这里可以调用实际的API // const [deviceStats, wechatStats, trafficStats, contentStats] = await Promise.allSettled([ // getDeviceStats(), // getWechatStats(), // getTrafficStats(), // getContentStats(), // ]); // 暂时使用模拟数据 setStats({ devices: 12, wechat: 25, traffic: 8, content: 156, }); } catch (error) { console.error("加载统计数据失败:", error); } }; useEffect(() => { loadStats(); }, []); const handleLogout = () => { // 清除本地存储的用户信息 localStorage.removeItem('token'); localStorage.removeItem('token_expired'); localStorage.removeItem('s2_accountId'); localStorage.removeItem('userInfo'); setShowLogoutDialog(false); logout(); navigate('/login'); toast({ title: '退出成功', description: '您已安全退出系统', }); }; const handleFunctionClick = (path: string) => { navigate(path); }; if (!isAuthenticated) { return (
请先登录
); } return ( console.log('Notifications'), }, { type: 'icon', icon: Settings, onClick: () => console.log('Settings'), }, ]} /> } footer={} >
{/* 用户信息卡片 */}
{currentUserInfo.name.charAt(0)}

{currentUserInfo.name}

{currentUserInfo.role}

{currentUserInfo.email}

最近登录: {currentUserInfo.lastLogin}
{/* 我的功能 */}
{functionModules.map((module) => (
handleFunctionClick(module.path)} >
{module.icon}
{module.title}
{module.description}
{module.count}
))}
{/* 退出登录 */}
{/* 退出登录确认对话框 */} 确认退出登录 您确定要退出登录吗?退出后需要重新登录才能使用完整功能。
); }