Akane1217 | 65b61a7 | 2025-05-17 13:52:25 +0800 | [diff] [blame] | 1 | import React from 'react';
|
| 2 | import { useNavigate,useLocation, Outlet } from 'react-router-dom';
|
| 3 | import './Personal.css';
|
| 4 | import ActionCard from './ActionCard';
|
| 5 |
|
| 6 | const Personal = () => {
|
| 7 | const navigate = useNavigate();
|
| 8 | const location = useLocation(); // 获取路由信息
|
| 9 |
|
| 10 | // 模拟用户数据
|
| 11 | const userData = {
|
| 12 | username: 'PT爱好者',
|
| 13 | avatar: 'https://via.placeholder.com/150',
|
| 14 | joinDate: '2023-01-15',
|
| 15 | level: '中级会员',
|
| 16 | points: 1250,
|
| 17 | upload: '3.2TB',
|
| 18 | download: '1.5TB',
|
| 19 | ratio: '2.13',
|
| 20 | downloadQuota: {
|
| 21 | total: 10, // 10GB
|
| 22 | used: 3.7, // 已使用3.7GB
|
| 23 | remaining: 6.3 // 剩余6.3GB
|
| 24 | }
|
| 25 | };
|
| 26 |
|
| 27 | const features = [
|
| 28 | {
|
| 29 | title: '我的收藏',
|
| 30 | description: '查看收藏的资源',
|
| 31 | path: '/personal/Favorite' // 相对路径
|
| 32 | },
|
| 33 | {
|
| 34 | title: '上传记录',
|
| 35 | description: '管理上传的资源',
|
| 36 | path: '/personal/Upload'
|
| 37 | },
|
| 38 | {
|
| 39 | title: '消息通知',
|
| 40 | description: '查看系统消息',
|
| 41 | path: '/personal/Notice'
|
| 42 | },
|
| 43 | {
|
| 44 | title: '设置',
|
| 45 | description: '修改个人资料',
|
| 46 | path: '/personal/Setting'
|
| 47 | }
|
| 48 | ];
|
| 49 |
|
| 50 | const handleCardClick = (path) => {
|
| 51 | navigate(path); // 相对导航
|
| 52 | };
|
| 53 |
|
| 54 | const handleBack = () => {
|
| 55 | if (location.state?.fromSubpage) {
|
| 56 | // 如果是从子页面返回,则继续返回到Dashboard
|
| 57 | navigate(`/dashboard/${location.state.dashboardTab || ''}`, {
|
| 58 | replace: true
|
| 59 | });
|
| 60 | } else {
|
| 61 | // 普通返回逻辑
|
| 62 | navigate(-1);
|
| 63 | }
|
| 64 | };
|
| 65 |
|
| 66 | return (
|
| 67 | <div className="personal-container">
|
| 68 | {/* 返回按钮 */}
|
| 69 | <button className="back-button" onClick={handleBack}>
|
| 70 | ← 返回
|
| 71 | </button>
|
| 72 |
|
| 73 | {/* 用户基本信息卡片 */}
|
| 74 | <div className="profile-card">
|
| 75 | <div className="profile-header">
|
| 76 | <img
|
| 77 | src={userData.avatar}
|
| 78 | alt={userData.username}
|
| 79 | className="profile-avatar"
|
| 80 | />
|
| 81 | <div className="profile-info">
|
| 82 | <h2 className="username">{userData.username}</h2>
|
| 83 | <div className="user-meta">
|
| 84 | <span>加入时间: {userData.joinDate}</span>
|
| 85 | <span>等级: {userData.level}</span>
|
| 86 | </div>
|
| 87 | </div>
|
| 88 | </div>
|
| 89 |
|
| 90 | {/* 用户数据统计 */}
|
| 91 | <div className="stats-grid">
|
| 92 | <div className="stat-item">
|
| 93 | <div className="stat-label">积分</div>
|
| 94 | <div className="stat-value">{userData.points}</div>
|
| 95 | </div>
|
| 96 | <div className="stat-item">
|
| 97 | <div className="stat-label">上传量</div>
|
| 98 | <div className="stat-value">{userData.upload}</div>
|
| 99 | </div>
|
| 100 | <div className="stat-item">
|
| 101 | <div className="stat-label">下载量</div>
|
| 102 | <div className="stat-value">{userData.download}</div>
|
| 103 | </div>
|
| 104 | <div className="stat-item">
|
| 105 | <div className="stat-label">分享率</div>
|
| 106 | <div className="stat-value">{userData.ratio}</div>
|
| 107 | </div>
|
| 108 | </div>
|
| 109 | </div>
|
| 110 |
|
| 111 | {/* 下载额度卡片 */}
|
| 112 | <div className="quota-card">
|
| 113 | <h3>下载额度</h3>
|
| 114 | <div className="quota-info">
|
| 115 | <span className="quota-used">{userData.downloadQuota.used}GB 已使用</span>
|
| 116 | <span className="quota-remaining">{userData.downloadQuota.remaining}GB 剩余</span>
|
| 117 | </div>
|
| 118 | <div className="progress-bar">
|
| 119 | <div
|
| 120 | className="progress-fill"
|
| 121 | style={{ width: `${(userData.downloadQuota.used / userData.downloadQuota.total) * 100}%` }}
|
| 122 | ></div>
|
| 123 | </div>
|
| 124 | <div className="quota-total">总额度: {userData.downloadQuota.total}GB</div>
|
| 125 | </div>
|
| 126 |
|
| 127 | {/* 功能卡片区 */}
|
| 128 | <div className="action-cards">
|
| 129 | {features.map((feature) => (
|
| 130 | <div
|
| 131 | key={feature.path}
|
| 132 | className="action-card"
|
| 133 | onClick={() => handleCardClick(feature.path)}
|
| 134 | >
|
| 135 | <h3>{feature.title}</h3>
|
| 136 | <p>{feature.description}</p>
|
| 137 | </div>
|
| 138 | ))}
|
| 139 | </div>
|
| 140 |
|
| 141 | {/* 子路由出口 */}
|
| 142 | <div className="subpage-container">
|
| 143 | <Outlet />
|
| 144 | </div>
|
| 145 | </div>
|
| 146 | );
|
| 147 | };
|
| 148 |
|
| 149 | export default Personal; |