feat(学生): 添加学生课程管理功能
- 新增我的课程页面及路由 - 实现课程列表和详情查看功能 - 更新导航链接指向新页面 - 添加成绩详情模态框 - 完善相关后端接口和服务
This commit is contained in:
@@ -9,6 +9,7 @@ class StudentManager {
|
||||
|
||||
init() {
|
||||
this.initDashboard();
|
||||
this.initMyCourses();
|
||||
this.updateCurrentTime();
|
||||
setInterval(() => this.updateCurrentTime(), 1000);
|
||||
}
|
||||
@@ -44,6 +45,79 @@ class StudentManager {
|
||||
console.error('Fetch dashboard data failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async initMyCourses() {
|
||||
// 检查是否在我的课程页面
|
||||
const tbody = document.getElementById('coursesTableBody');
|
||||
if (!tbody) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${this.apiBase}/courses`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
this.renderCourses(result.data);
|
||||
} else {
|
||||
if (window.authManager) {
|
||||
window.authManager.showNotification(result.message || '获取课程失败', 'error');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fetch courses data failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
renderCourses(courses) {
|
||||
const tbody = document.getElementById('coursesTableBody');
|
||||
if (!tbody) return;
|
||||
|
||||
if (!courses || courses.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="6" class="text-center py-4 text-muted">暂无课程记录</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = courses.map(course => `
|
||||
<tr>
|
||||
<td>${course.course_code}</td>
|
||||
<td>${course.course_name}</td>
|
||||
<td>${course.credit}</td>
|
||||
<td>${course.teacher_name}</td>
|
||||
<td>${course.semester || '2023-2024 下学期'}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-primary" onclick="studentManager.viewCourseDetails(${course.id})">
|
||||
<i class="fas fa-info-circle"></i> 课程详情
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
async viewCourseDetails(courseId) {
|
||||
try {
|
||||
const response = await fetch(`${this.apiBase}/courses/${courseId}`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const course = result.data;
|
||||
this.updateElement('modalCourseName', course.course_name);
|
||||
this.updateElement('modalCourseCode', course.course_code);
|
||||
this.updateElement('modalCourseCredit', course.credit);
|
||||
this.updateElement('modalTeacherName', course.teacher_name);
|
||||
this.updateElement('modalClassName', course.class_name);
|
||||
this.updateElement('modalSemester', course.semester || '2023-2024 下学期');
|
||||
this.updateElement('modalTeacherEmail', course.teacher_email || '暂无');
|
||||
|
||||
const modal = new bootstrap.Modal(document.getElementById('courseDetailsModal'));
|
||||
modal.show();
|
||||
} else {
|
||||
if (window.authManager) {
|
||||
window.authManager.showNotification(result.message || '获取课程详情失败', 'error');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fetch course details failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
renderDashboard(data) {
|
||||
const { grades, statistics } = data;
|
||||
@@ -107,9 +181,43 @@ class StudentManager {
|
||||
return '不及格';
|
||||
}
|
||||
|
||||
viewDetails(id) {
|
||||
// 实现查看详情逻辑,或者跳转到详情页
|
||||
console.log('View details for score:', id);
|
||||
async viewDetails(id) {
|
||||
try {
|
||||
const response = await fetch(`${this.apiBase}/grades/${id}`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const grade = result.data.grade;
|
||||
this.updateElement('modalGradeCourseName', grade.course_name);
|
||||
this.updateElement('modalGradeCourseCode', grade.course_code);
|
||||
this.updateElement('modalTotalScore', grade.score);
|
||||
this.updateElement('modalUsualScore', grade.usual_score || '-');
|
||||
this.updateElement('modalMidtermScore', grade.midterm_score || '-');
|
||||
this.updateElement('modalFinalScore', grade.final_score || '-');
|
||||
this.updateElement('modalGradeCredit', grade.credit);
|
||||
this.updateElement('modalGradeLevel', grade.grade_level || '-');
|
||||
this.updateElement('modalGradePoint', grade.grade_point || '-');
|
||||
this.updateElement('modalGradeTeacher', grade.teacher_name);
|
||||
this.updateElement('modalGradeTime', new Date(grade.created_at).toLocaleString());
|
||||
|
||||
const remarkContainer = document.getElementById('modalRemarkContainer');
|
||||
if (grade.remark) {
|
||||
remarkContainer.style.display = 'block';
|
||||
this.updateElement('modalRemark', grade.remark);
|
||||
} else {
|
||||
remarkContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
const modal = new bootstrap.Modal(document.getElementById('gradeDetailsModal'));
|
||||
modal.show();
|
||||
} else {
|
||||
if (window.authManager) {
|
||||
window.authManager.showNotification(result.message || '获取成绩详情失败', 'error');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fetch grade details failed:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user