blob: 1fa812aebd06e1e60f6cf16ece21176f492e5cb9 [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";
San3yuan292794c2025-06-08 20:02:46 +08008import type { MenuProps } from 'antd';
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +08009import { useNavigate } from "react-router";
San3yuan292794c2025-06-08 20:02:46 +080010import { Dropdown } from "antd";
San3yuan4d0e8032025-04-04 17:21:40 +080011
San3yuan8166d1b2025-06-05 23:15:53 +080012
San3yuan6f2ed692025-04-16 20:24:49 +080013interface SelfStatusProps {
14 className?: string;
15}
San3yuan4d0e8032025-04-04 17:21:40 +080016
San3yuan6f2ed692025-04-16 20:24:49 +080017const SelfStatus: React.FC<SelfStatusProps> = () => {
阳菜,放晴!7e1e3a52025-06-05 23:00:51 +080018
19 const nav = useNavigate()
San3yuan2534d422025-04-08 21:43:18 +080020 const userName = useAppSelector(state => state.user.userName);
21 const role = useAppSelector(state => state.user.role);
22 const uploadTraffic = useAppSelector(state => state.user.uploadTraffic);
23 const downloadTraffic = useAppSelector(state => state.user.downloadTraffic);
24 const downloadPoints = useAppSelector(state => state.user.downloadPoints);
San3yuan30e245f2025-06-07 20:04:23 +080025 const avatar = useAppSelector(state => state.user.avatar) || 'https://pic.baike.soso.com/ugc/baikepic2/6664/20220301143956-1127285627_png_800_800_370852.jpg/0';
San3yuana2ee30b2025-06-05 21:20:17 +080026 const dispatch = useAppDispatch();
阳菜,放晴!2f987042025-06-08 14:54:50 +080027 const { refresh } = useApi(() => request.get(getUserInfo), false);
28 const fenchData = async () => {
29 const data = await refresh();
30 console.log(data)
31
San3yuana2ee30b2025-06-05 21:20:17 +080032 if (data) {
阳菜,放晴!2f987042025-06-08 14:54:50 +080033 dispatch({ type: "user/getUserInfo", payload: data.userInfo });
San3yuana2ee30b2025-06-05 21:20:17 +080034 }
阳菜,放晴!2f987042025-06-08 14:54:50 +080035 }
San3yuan292794c2025-06-08 20:02:46 +080036
37 const logOut = () =>{
38 dispatch({type:"user/logout"})
39 nav('/')
40 }
41
42 const menu: MenuProps['items'] =[
43 {
44 key:'1',
45 label:(<span onClick={logOut}>登出</span>)
46 }
47]
阳菜,放晴!2f987042025-06-08 14:54:50 +080048 useEffect(() => {
49 fenchData();
50
51 }, [ dispatch]);
San3yuan2534d422025-04-08 21:43:18 +080052
53 return (
54 <div className={style.container}>
San3yuan292794c2025-06-08 20:02:46 +080055 <div className={style.left}
56
57 >
San3yuana2ee30b2025-06-05 21:20:17 +080058 {avatar && avatar.length > 0 ? (
San3yuan292794c2025-06-08 20:02:46 +080059 <img className={style.avatar} onClick={() => nav('/homepage')} style={{ cursor: 'pointer'}} src={avatar} alt="User Avatar" />):null}
San3yuan4d0e8032025-04-04 17:21:40 +080060 </div>
San3yuan2534d422025-04-08 21:43:18 +080061 <div className={style.right}>
62 <div className={style.info}>
San3yuan292794c2025-06-08 20:02:46 +080063 <Dropdown menu={{ items: menu }}>
64 <p className={style.userName}>{userName}</p>
65 </Dropdown>
66 <p className={style.role}>用户组: {role && role.trim().length? role:'N/A'}</p>
San3yuan03ab0642025-04-29 18:00:25 +080067 <p className={style.uploadTraffic}>上传量: {uploadTraffic ? uploadTraffic : 0}</p>
68 <p className={style.downloadTraffic}>下载量: {downloadTraffic ? downloadTraffic : 0}</p>
San3yuan6f2ed692025-04-16 20:24:49 +080069
San3yuan2534d422025-04-08 21:43:18 +080070 <p className={style.shareRatio}>
71 分享率: {uploadTraffic && downloadTraffic ? (uploadTraffic / downloadTraffic).toFixed(2) : "N/A"}
72 </p>
San3yuan03ab0642025-04-29 18:00:25 +080073 <p className={style.downloadPoints}>下载积分: {downloadPoints ? downloadPoints : 0}</p>
San3yuan2534d422025-04-08 21:43:18 +080074 </div>
75 <button className={style.signInButton}>签到</button>
San3yuan4d0e8032025-04-04 17:21:40 +080076 </div>
San3yuan2534d422025-04-08 21:43:18 +080077 </div>
78 );
79};
San3yuan4d0e8032025-04-04 17:21:40 +080080
San3yuan2534d422025-04-08 21:43:18 +080081export default SelfStatus;