import React, { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import { Card, NavBar, List, Button, Dialog, Toast } from "antd-mobile"; import { LogoutOutlined, PhoneOutlined, MessageOutlined, DatabaseOutlined, FolderOpenOutlined, BellOutlined, SettingOutlined, } from "@ant-design/icons"; import MeauMobile from "@/components/MeauMobile/MeauMoible"; import Layout from "@/components/Layout/Layout"; import style from "./index.module.scss"; import { useUserStore } from "@/store/module/user"; import { getDashboard } from "./api"; const Mine: React.FC = () => { const navigate = useNavigate(); const { user } = useUserStore(); const [stats, setStats] = useState({ devices: 12, wechat: 25, traffic: 8, content: 156, balance: 0, }); const [showLogoutDialog, setShowLogoutDialog] = useState(false); // 用户信息 const currentUserInfo = { name: user?.username || "-", email: user?.account || "-", role: user?.isAdmin === 1 ? "管理员" : "普通用户", lastLogin: user?.lastLoginTime ? new Date(user.lastLoginTime * 1000).toLocaleString() : "-", avatar: user?.avatar || "", }; // 功能模块数据 const functionModules = [ { id: "devices", title: "设备管理", description: "管理您的设备和微信账号", icon: , count: stats.devices, path: "/devices", bgColor: "#e6f7ff", iconColor: "#1890ff", }, { id: "wechat", title: "微信号管理", description: "管理微信账号和好友", icon: , count: stats.wechat, path: "/wechat-accounts", bgColor: "#f6ffed", iconColor: "#52c41a", }, { id: "traffic", title: "流量池", description: "管理用户流量池和分组", icon: , count: stats.traffic, path: "/traffic-pool", bgColor: "#f9f0ff", iconColor: "#722ed1", }, { id: "content", title: "内容库", description: "管理营销内容和素材", icon: , count: stats.content, path: "/content", bgColor: "#fff7e6", iconColor: "#fa8c16", }, ]; // 加载统计数据 const loadStats = async () => { try { const res = await getDashboard(); setStats({ devices: res.deviceNum, wechat: res.wechatNum, traffic: 999, content: 999, balance: res.balance || 0, }); } 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); navigate("/login"); Toast.show({ content: "退出成功", position: "top", }); }; const handleFunctionClick = (path: string) => { navigate(path); }; // 渲染用户头像 const renderUserAvatar = () => { if (currentUserInfo.avatar) { return 头像; } return (
); }; // 渲染功能模块图标 const renderModuleIcon = (module: any) => (
{module.icon}
); return (
我的
} footer={} >
{/* 用户信息卡片(严格按图片风格) */}
{/* 头像 */}
{currentUserInfo.avatar ? ( ) : (
)}
{/* 右侧内容 */}
{currentUserInfo.name} {currentUserInfo.role}
余额: ¥{Number(stats.balance || 0).toFixed(2)}
最近登录:{currentUserInfo.lastLogin}
navigate("/settings")} />
{/* 我的功能 */} {functionModules.map((module) => ( {module.count} } arrow onClick={() => handleFunctionClick(module.path)} /> ))} {/* 退出登录按钮 */}
{/* 退出登录确认对话框 */} setShowLogoutDialog(false)} />
); }; export default Mine;