MemberPage.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import debug from 'debug';
  2. import React from 'react';
  3. import { UserIcon, PencilIcon } from '@heroicons/react/24/outline';
  4. import { useParams, useNavigate } from 'react-router-dom';
  5. import { useQuery } from '@tanstack/react-query';
  6. import type { InferResponseType } from 'hono/client';
  7. import { userClient } from '@/client/api';
  8. import { useAuth, User } from '@/client/home/hooks/AuthProvider';
  9. const MemberPage: React.FC = () => {
  10. const navigate = useNavigate();
  11. const { user, logout } = useAuth();
  12. if (!user) {
  13. return (
  14. <div className="text-center py-12">
  15. <h2 className="text-2xl font-bold text-gray-900 mb-4">用户不存在</h2>
  16. <button
  17. onClick={() => navigate('/')}
  18. className="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
  19. >
  20. 返回首页
  21. </button>
  22. </div>
  23. );
  24. }
  25. return (
  26. <div className="min-h-screen bg-gray-50">
  27. <div className="container mx-auto px-4 py-8 max-w-4xl">
  28. {/* 用户资料卡片 */}
  29. <div className="bg-white rounded-lg shadow-sm p-6 mb-8">
  30. <div className="flex flex-col items-center">
  31. <div className="w-24 h-24 rounded-full bg-gray-200 flex items-center justify-center mb-4">
  32. {user.avatar ? (
  33. <img src={user.avatar} alt={user.nickname || user.username} className="h-full w-full object-cover rounded-full" />
  34. ) : (
  35. <UserIcon className="h-12 w-12 text-gray-500" />
  36. )}
  37. </div>
  38. <h1 className="text-2xl font-bold text-gray-900 mb-1">{user.nickname || user.username}</h1>
  39. <div className="flex space-x-8 my-4">
  40. <div className="text-center">
  41. <p className="text-2xl font-semibold text-gray-900">0</p>
  42. <p className="text-sm text-gray-500">内容</p>
  43. </div>
  44. <div className="text-center">
  45. <p className="text-2xl font-semibold text-gray-900">0</p>
  46. <p className="text-sm text-gray-500">关注</p>
  47. </div>
  48. <div className="text-center">
  49. <p className="text-2xl font-semibold text-gray-900">0</p>
  50. <p className="text-sm text-gray-500">粉丝</p>
  51. </div>
  52. </div>
  53. <div className="flex">
  54. <button
  55. onClick={() => navigate('/profile/edit')}
  56. className="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 flex items-center"
  57. >
  58. <PencilIcon className="w-4 h-4 mr-2" />
  59. 编辑资料
  60. </button>
  61. <button
  62. onClick={async () => {
  63. await logout();
  64. navigate('/');
  65. }}
  66. className="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 ml-4"
  67. >
  68. 退出登录
  69. </button>
  70. </div>
  71. {(user as any).bio && (
  72. <p className="mt-4 text-center text-gray-600 max-w-lg">
  73. {(user as any).bio}
  74. </p>
  75. )}
  76. <div className="flex items-center mt-4 space-x-4">
  77. {(user as any).location && (
  78. <div className="flex items-center text-gray-600">
  79. <svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
  80. <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
  81. <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
  82. </svg>
  83. <span className="text-sm">{(user as any).location}</span>
  84. </div>
  85. )}
  86. {(user as any).website && (
  87. <a
  88. href={(user as any).website}
  89. target="_blank"
  90. rel="noopener noreferrer"
  91. className="flex items-center text-blue-600 hover:text-blue-800"
  92. >
  93. <svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
  94. <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6v6m0 0v6m0-6h-6" />
  95. </svg>
  96. <span className="text-sm truncate max-w-[150px]">{(user as any).website}</span>
  97. </a>
  98. )}
  99. </div>
  100. </div>
  101. </div>
  102. {/* 用户内容区域 */}
  103. <div className="bg-white rounded-lg shadow-sm p-6">
  104. <h2 className="text-xl font-semibold mb-6">个人资料</h2>
  105. <div className="space-y-4">
  106. <div className="border-b border-gray-100 pb-4">
  107. <h3 className="text-sm font-medium text-gray-500 mb-1">用户名</h3>
  108. <p className="text-gray-900">{user.username}</p>
  109. </div>
  110. <div className="border-b border-gray-100 pb-4">
  111. <h3 className="text-sm font-medium text-gray-500 mb-1">电子邮箱</h3>
  112. <p className="text-gray-900">{user.email || '未设置'}</p>
  113. </div>
  114. <div className="border-b border-gray-100 pb-4">
  115. <h3 className="text-sm font-medium text-gray-500 mb-1">注册时间</h3>
  116. <p className="text-gray-900">{user.createdAt ? new Date(user.createdAt).toLocaleDateString() : '未知'}</p>
  117. </div>
  118. <div className="border-b border-gray-100 pb-4">
  119. <h3 className="text-sm font-medium text-gray-500 mb-1">最后登录</h3>
  120. <p className="text-gray-900">{user.updatedAt ? new Date(user.updatedAt).toLocaleString() : '从未登录'}</p>
  121. </div>
  122. </div>
  123. <div className="mt-8">
  124. <button
  125. onClick={() => navigate('/profile/security')}
  126. className="w-full py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
  127. >
  128. 安全设置
  129. </button>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. );
  135. };
  136. export default MemberPage;