import { Avatar } from "@arco-design/web-react"; import { useState, useEffect } from "react"; import { studentAPI } from "@/services/api"; import { mapProfile } from "@/utils/dataMapper"; import "./index.css"; const ProfileCard = () => { const [profile, setProfile] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetchProfile(); }, []); const fetchProfile = async () => { try { setLoading(true); // Get current logged-in student information const studentData = await studentAPI.getCurrentStudent(); if (studentData) { const mappedProfile = mapProfile(studentData); setProfile(mappedProfile); } else { throw new Error("Failed to get current student data"); } } catch (error) { console.error("Failed to fetch profile:", error); // Show error message instead of fake data setProfile({ name: "数据加载失败", studentId: "请检查后端服务", school: error.message || "后端未运行", major: "请确保数据库已初始化", badges: { credits: 0, classRank: 0, mbti: "-" }, courses: [] }); } finally { setLoading(false); } }; if (loading) { return (
加载中...
学号: {profile?.studentId}