'use client' import Image from 'next/image' import { Session } from 'next-auth' import { signOut } from 'next-auth/react' import { LogOut, User, Pickaxe, ShieldCheck } from "lucide-react"; // 导入图标 import { Button } from '@/components/ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu' import { sync } from 'framer-motion' import { getService } from '@/lib/http/service' import React from 'react' import toast from 'react-hot-toast' import { useRouter } from 'next/navigation' function getUserInitials(name: string) { const [firstName, lastName] = name.split(' ') return lastName ? `${firstName[0]}${lastName[0]}` : firstName.slice(0, firstName.length) } export interface UserData { auth_token: string; id: number; login_ip: string; login_time: number; role: string; user_name: string; version: string; image?: string; } export function UserMenu({ user }: { user: UserData }) { const [isLoading, setIsLoading] = React.useState(false); const router = useRouter() const getRandomColor = (name: string | undefined): string => { if (!name) return "#999"; // 默认颜色 const colors = ["#FF5733", "#33FF57", "#3357FF", "#FF33A8", "#FFC300", "#FF5733", "#57FF33", "#A833FF"]; const index = name.charCodeAt(0) % colors.length; // 根据名字的首字母选择颜色 return colors[index]; }; return (
{/* 新增 "Mining" 选项 */} { router.push("/mine"); // 修改跳转路径到 "/mine" }} className="flex items-center text-xs" > {/* 这里换成挖矿相关的图标 */} Mining {/* 新增 "Security" 选项 */} { router.push("/security"); // 跳转到安全页面 "/security" }} className="flex items-center text-xs" > {/* 安全图标 (ShieldCheck) */} Security {/* 新增 "Profile" 选项 */} { router.push('/profile'); // 假设用户的个人资料页面是 "/profile" }} className="text-xs" > {/* 添加 Profile 图标 */} Profile {/* 分隔线(可选) */}
{/* "Log Out" 选项 */} { console.log('logout') if (isLoading) return setIsLoading(true); const service = await getService(); await service.post('/api/v1/customer/logout', { }, { headers: { 'Authorization': user.auth_token } }).then(function (result: any) { setIsLoading(false); console.log("result:", result) if (result && result.header.code != 0) { toast.error(result.header.message) return } localStorage.removeItem("UserData"); window.location.href = `/` }).catch((err) => { setIsLoading(false); localStorage.removeItem("UserData"); window.location.href = `/` console.log(err); }); } } className="text-xs" > {/* 添加 Log Out 图标 */} Log Out
) }