blob: fb25c75ca58053c875b3f3651109ae2dd9087541 [file] [log] [blame]
San3yuanff75c542025-06-06 20:30:52 +08001import React, { useEffect, useRef } from "react";
San3yuan4d0e8032025-04-04 17:21:40 +08002import { useAppSelector } from "../../hooks/store";
San3yuan2534d422025-04-08 21:43:18 +08003import style from "./style.module.css"
San3yuana2ee30b2025-06-05 21:20:17 +08004import { useApi } from "@/hooks/request";
5import request from "@/utils/request";
6import { getUserInfo } from "@/api/user";
7import { useAppDispatch } from "@/hooks/store";
San3yuan8166d1b2025-06-05 23:15:53 +08008
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +08009import { useNavigate } from "react-router";
San3yuan4d0e8032025-04-04 17:21:40 +080010
San3yuan8166d1b2025-06-05 23:15:53 +080011
San3yuan6f2ed692025-04-16 20:24:49 +080012interface SelfStatusProps {
13 className?: string;
14}
San3yuan4d0e8032025-04-04 17:21:40 +080015
San3yuan6f2ed692025-04-16 20:24:49 +080016const SelfStatus: React.FC<SelfStatusProps> = () => {
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080017
18 const nav = useNavigate()
San3yuan2534d422025-04-08 21:43:18 +080019 const userName = useAppSelector(state => state.user.userName);
20 const role = useAppSelector(state => state.user.role);
21 const uploadTraffic = useAppSelector(state => state.user.uploadTraffic);
22 const downloadTraffic = useAppSelector(state => state.user.downloadTraffic);
23 const downloadPoints = useAppSelector(state => state.user.downloadPoints);
24 const avatar = useAppSelector(state => state.user.avatar);
San3yuana2ee30b2025-06-05 21:20:17 +080025 const dispatch = useAppDispatch();
26 const { data, refresh } = useApi(() => request.get(getUserInfo), false);
San3yuanff75c542025-06-06 20:30:52 +080027 const dataRef = useRef(data);
San3yuana2ee30b2025-06-05 21:20:17 +080028 useEffect(() => {
San3yuanff75c542025-06-06 20:30:52 +080029 refresh();
San3yuana2ee30b2025-06-05 21:20:17 +080030 if (data) {
31 dispatch({ type: "user/getUserInfo", payload: data });
32 }
San3yuanff75c542025-06-06 20:30:52 +080033 }, [dataRef, dispatch]);
San3yuan2534d422025-04-08 21:43:18 +080034
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080035 function handleAvatarClick(){
36 nav('/homepage')
37 }
38
San3yuan2534d422025-04-08 21:43:18 +080039 return (
40 <div className={style.container}>
41 <div className={style.left}>
San3yuana2ee30b2025-06-05 21:20:17 +080042 {avatar && avatar.length > 0 ? (
43 <img className={style.avatar} src={avatar} alt="User Avatar" />):null}
San3yuan4d0e8032025-04-04 17:21:40 +080044 </div>
San3yuan2534d422025-04-08 21:43:18 +080045 <div className={style.right}>
46 <div className={style.info}>
47 <p className={style.userName}>{userName}</p>
阳菜,放晴!77743f42025-06-06 23:04:08 +080048 <p
49 className={style.role}
50 onClick={() => nav('/homepage')}
51 style={{ cursor: 'pointer', textDecoration: 'underline' }}>
52 用户组: {role && role.trim().length? role:'N/A'}</p>
San3yuan03ab0642025-04-29 18:00:25 +080053 <p className={style.uploadTraffic}>上传量: {uploadTraffic ? uploadTraffic : 0}</p>
54 <p className={style.downloadTraffic}>下载量: {downloadTraffic ? downloadTraffic : 0}</p>
San3yuan6f2ed692025-04-16 20:24:49 +080055
San3yuan2534d422025-04-08 21:43:18 +080056 <p className={style.shareRatio}>
57 分享率: {uploadTraffic && downloadTraffic ? (uploadTraffic / downloadTraffic).toFixed(2) : "N/A"}
58 </p>
San3yuan03ab0642025-04-29 18:00:25 +080059 <p className={style.downloadPoints}>下载积分: {downloadPoints ? downloadPoints : 0}</p>
San3yuan2534d422025-04-08 21:43:18 +080060 </div>
61 <button className={style.signInButton}>签到</button>
San3yuan4d0e8032025-04-04 17:21:40 +080062 </div>
San3yuan2534d422025-04-08 21:43:18 +080063 </div>
64 );
65};
San3yuan4d0e8032025-04-04 17:21:40 +080066
San3yuan2534d422025-04-08 21:43:18 +080067export default SelfStatus;