/** * 学生端功能管理 */ class StudentManager { constructor() { this.apiBase = '/api/student'; this.init(); } init() { this.initDashboard(); this.updateCurrentTime(); setInterval(() => this.updateCurrentTime(), 1000); } updateCurrentTime() { const timeElement = document.getElementById('currentTime'); if (timeElement) { const now = new Date(); const options = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' }; timeElement.textContent = now.toLocaleString('zh-CN', options); } } async initDashboard() { // 检查是否在仪表板页面 if (!document.getElementById('gradesTableBody')) return; try { const response = await fetch(`${this.apiBase}/grades`); const result = await response.json(); if (result.success) { this.renderDashboard(result.data); } else { if (window.authManager) { window.authManager.showNotification(result.message || '获取数据失败', 'error'); } } } catch (error) { console.error('Fetch dashboard data failed:', error); } } renderDashboard(data) { const { grades, statistics } = data; // 渲染统计数据 if (statistics) { this.updateElement('gpaValue', statistics.gpa); this.updateElement('courseCount', statistics.totalCourses); this.updateElement('creditTotal', statistics.totalCredits); // 班级排名如果后端没提供,可以显示为 '-' 或固定值 this.updateElement('classRank', statistics.classRank || '-'); } // 渲染成绩表格 const tbody = document.getElementById('gradesTableBody'); if (tbody) { if (!grades || grades.length === 0) { tbody.innerHTML = '