DashboardHeader.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use client";
  2. import { getAvatarUrl, getAvatarColor, getAvatarInitial } from "@/utils/avatar";
  3. interface DashboardHeaderProps {
  4. username: string;
  5. role: string;
  6. avatarUrl?: string | null;
  7. onLogout: () => void;
  8. onProfileClick: () => void;
  9. }
  10. export function DashboardHeader({
  11. username,
  12. role,
  13. avatarUrl,
  14. onLogout,
  15. onProfileClick,
  16. }: DashboardHeaderProps) {
  17. // 根据用户名生成头像颜色(如果没有上传头像)
  18. const avatarColor = getAvatarColor(username);
  19. const displayInitial = getAvatarInitial(username);
  20. const fullAvatarUrl = getAvatarUrl(avatarUrl);
  21. return (
  22. <div className="h-16 flex items-center justify-between px-6 border-b border-gray-200 bg-white flex-shrink-0">
  23. <div className="flex items-center gap-3">
  24. {/* 头像 */}
  25. <button
  26. onClick={onProfileClick}
  27. className="flex-shrink-0 hover:opacity-80 transition-opacity"
  28. title="点击查看个人资料"
  29. >
  30. {fullAvatarUrl ? (
  31. <img
  32. src={fullAvatarUrl}
  33. alt={username}
  34. className="w-10 h-10 rounded-full object-cover border-2 border-gray-200"
  35. />
  36. ) : (
  37. <div
  38. className="w-10 h-10 rounded-full flex items-center justify-center text-white text-sm font-semibold border-2 border-gray-200"
  39. style={{ backgroundColor: avatarColor }}
  40. >
  41. {displayInitial}
  42. </div>
  43. )}
  44. </button>
  45. <div>
  46. <div className="text-sm text-gray-500">当前账号</div>
  47. <div className="text-base font-semibold text-gray-800">
  48. {username || "客服"}
  49. {role ? `(${role})` : ""}
  50. </div>
  51. </div>
  52. </div>
  53. <div className="flex items-center gap-2">
  54. <button
  55. onClick={onProfileClick}
  56. className="px-3 py-1.5 text-sm rounded-lg bg-blue-100 text-blue-700 hover:bg-blue-200 transition-colors"
  57. title="个人资料"
  58. >
  59. 设置
  60. </button>
  61. <button
  62. onClick={onLogout}
  63. className="px-3 py-1.5 text-sm rounded-lg bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors"
  64. >
  65. 退出登录
  66. </button>
  67. </div>
  68. </div>
  69. );
  70. }