/** * 学生端功能管理 */ class StudentManager { constructor() { this.apiBase = '/api/student'; this.init(); } init() { this.initDashboard(); this.initMyCourses(); this.initGradeAnalysis(); this.updateCurrentTime(); setInterval(() => this.updateCurrentTime(), 1000); // 绑定刷新按钮 const refreshBtn = document.getElementById('refreshCourses'); if (refreshBtn) { refreshBtn.addEventListener('click', () => this.initMyCourses()); } const refreshTrendBtn = document.getElementById('refreshTrend'); if (refreshTrendBtn) { refreshTrendBtn.addEventListener('click', () => this.initGradeAnalysis()); } } 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); } } async initMyCourses() { // 检查是否在我的课程页面 const tbody = document.getElementById('coursesTableBody'); if (!tbody) return; // 显示加载状态 tbody.innerHTML = `