San3yuan | ff75c54 | 2025-06-06 20:30:52 +0800 | [diff] [blame] | 1 | import React, { useEffect, useRef } from "react"; |
San3yuan | 4d0e803 | 2025-04-04 17:21:40 +0800 | [diff] [blame] | 2 | import { useAppSelector } from "../../hooks/store"; |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 3 | import style from "./style.module.css" |
San3yuan | a2ee30b | 2025-06-05 21:20:17 +0800 | [diff] [blame] | 4 | import { useApi } from "@/hooks/request"; |
| 5 | import request from "@/utils/request"; |
| 6 | import { getUserInfo } from "@/api/user"; |
| 7 | import { useAppDispatch } from "@/hooks/store"; |
San3yuan | 8166d1b | 2025-06-05 23:15:53 +0800 | [diff] [blame] | 8 | |
阳菜,放晴! | 7e1e3a5 | 2025-06-05 23:00:51 +0800 | [diff] [blame] | 9 | import { useNavigate } from "react-router"; |
San3yuan | 4d0e803 | 2025-04-04 17:21:40 +0800 | [diff] [blame] | 10 | |
San3yuan | 8166d1b | 2025-06-05 23:15:53 +0800 | [diff] [blame] | 11 | |
San3yuan | 6f2ed69 | 2025-04-16 20:24:49 +0800 | [diff] [blame] | 12 | interface SelfStatusProps { |
| 13 | className?: string; |
| 14 | } |
San3yuan | 4d0e803 | 2025-04-04 17:21:40 +0800 | [diff] [blame] | 15 | |
San3yuan | 6f2ed69 | 2025-04-16 20:24:49 +0800 | [diff] [blame] | 16 | const SelfStatus: React.FC<SelfStatusProps> = () => { |
阳菜,放晴! | 7e1e3a5 | 2025-06-05 23:00:51 +0800 | [diff] [blame] | 17 | |
| 18 | const nav = useNavigate() |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 19 | 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); |
San3yuan | 30e245f | 2025-06-07 20:04:23 +0800 | [diff] [blame] | 24 | const avatar = useAppSelector(state => state.user.avatar) || 'https://pic.baike.soso.com/ugc/baikepic2/6664/20220301143956-1127285627_png_800_800_370852.jpg/0'; |
San3yuan | a2ee30b | 2025-06-05 21:20:17 +0800 | [diff] [blame] | 25 | const dispatch = useAppDispatch(); |
阳菜,放晴! | 2f98704 | 2025-06-08 14:54:50 +0800 | [diff] [blame] | 26 | const { refresh } = useApi(() => request.get(getUserInfo), false); |
| 27 | const fenchData = async () => { |
| 28 | const data = await refresh(); |
| 29 | console.log(data) |
| 30 | |
San3yuan | a2ee30b | 2025-06-05 21:20:17 +0800 | [diff] [blame] | 31 | if (data) { |
阳菜,放晴! | 2f98704 | 2025-06-08 14:54:50 +0800 | [diff] [blame] | 32 | dispatch({ type: "user/getUserInfo", payload: data.userInfo }); |
San3yuan | a2ee30b | 2025-06-05 21:20:17 +0800 | [diff] [blame] | 33 | } |
阳菜,放晴! | 2f98704 | 2025-06-08 14:54:50 +0800 | [diff] [blame] | 34 | } |
| 35 | useEffect(() => { |
| 36 | fenchData(); |
| 37 | |
| 38 | }, [ dispatch]); |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 39 | |
阳菜,放晴! | 7e1e3a5 | 2025-06-05 23:00:51 +0800 | [diff] [blame] | 40 | function handleAvatarClick(){ |
| 41 | nav('/homepage') |
| 42 | } |
| 43 | |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 44 | return ( |
| 45 | <div className={style.container}> |
| 46 | <div className={style.left}> |
San3yuan | a2ee30b | 2025-06-05 21:20:17 +0800 | [diff] [blame] | 47 | {avatar && avatar.length > 0 ? ( |
| 48 | <img className={style.avatar} src={avatar} alt="User Avatar" />):null} |
San3yuan | 4d0e803 | 2025-04-04 17:21:40 +0800 | [diff] [blame] | 49 | </div> |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 50 | <div className={style.right}> |
| 51 | <div className={style.info}> |
| 52 | <p className={style.userName}>{userName}</p> |
阳菜,放晴! | 77743f4 | 2025-06-06 23:04:08 +0800 | [diff] [blame] | 53 | <p |
| 54 | className={style.role} |
| 55 | onClick={() => nav('/homepage')} |
| 56 | style={{ cursor: 'pointer', textDecoration: 'underline' }}> |
| 57 | 用户组: {role && role.trim().length? role:'N/A'}</p> |
San3yuan | 03ab064 | 2025-04-29 18:00:25 +0800 | [diff] [blame] | 58 | <p className={style.uploadTraffic}>上传量: {uploadTraffic ? uploadTraffic : 0}</p> |
| 59 | <p className={style.downloadTraffic}>下载量: {downloadTraffic ? downloadTraffic : 0}</p> |
San3yuan | 6f2ed69 | 2025-04-16 20:24:49 +0800 | [diff] [blame] | 60 | |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 61 | <p className={style.shareRatio}> |
| 62 | 分享率: {uploadTraffic && downloadTraffic ? (uploadTraffic / downloadTraffic).toFixed(2) : "N/A"} |
| 63 | </p> |
San3yuan | 03ab064 | 2025-04-29 18:00:25 +0800 | [diff] [blame] | 64 | <p className={style.downloadPoints}>下载积分: {downloadPoints ? downloadPoints : 0}</p> |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 65 | </div> |
| 66 | <button className={style.signInButton}>签到</button> |
San3yuan | 4d0e803 | 2025-04-04 17:21:40 +0800 | [diff] [blame] | 67 | </div> |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 68 | </div> |
| 69 | ); |
| 70 | }; |
San3yuan | 4d0e803 | 2025-04-04 17:21:40 +0800 | [diff] [blame] | 71 | |
San3yuan | 2534d42 | 2025-04-08 21:43:18 +0800 | [diff] [blame] | 72 | export default SelfStatus; |