修复了课表周数硬编码

This commit is contained in:
2026-03-17 12:29:04 +08:00
parent 582589d252
commit b50bd9abb3
10 changed files with 605 additions and 43 deletions

View File

@@ -45,22 +45,42 @@ interface SyncScheduleResponse {
error_message?: string;
}
const toCourse = (dto: ScheduleCourseDTO): Course => ({
id: dto.id,
name: dto.name,
teacher: dto.teacher,
location: dto.location,
dayOfWeek: dto.day_of_week,
startSection: dto.start_section,
endSection: dto.end_section,
weeks: dto.weeks ?? [],
color: dto.color,
});
const toCourse = (dto: ScheduleCourseDTO): Course => {
// 调试日志:检查后端返回的 weeks 字段
console.log('[ScheduleService] 转换课程 DTO:', {
id: dto.id,
name: dto.name,
day_of_week: dto.day_of_week,
weeks: dto.weeks,
weeksType: typeof dto.weeks,
weeksLength: dto.weeks?.length,
});
return {
id: dto.id,
name: dto.name,
teacher: dto.teacher,
location: dto.location,
dayOfWeek: dto.day_of_week,
startSection: dto.start_section,
endSection: dto.end_section,
weeks: dto.weeks ?? [],
color: dto.color,
};
};
class ScheduleService {
async getCourses(week?: number): Promise<Course[]> {
const params = week ? { week } : undefined;
console.log('[ScheduleService] 获取课程列表, params:', params);
const response = await api.get<ScheduleCourseListResponse>('/schedule/courses', params);
console.log('[ScheduleService] 课程列表响应, 数量:', response.data.list.length);
// 打印原始响应数据中的 weeks 字段
response.data.list.forEach((item, index) => {
console.log(`[ScheduleService] 课程[${index}] ${item.name}:`, {
day_of_week: item.day_of_week,
weeks: item.weeks,
});
});
return response.data.list.map(toCourse);
}
@@ -79,7 +99,9 @@ class ScheduleService {
}
async syncSchedule(req: SyncScheduleRequest): Promise<SyncScheduleResponse> {
console.log('[ScheduleService] 开始同步教务系统, username:', req.username);
const response = await api.post<SyncScheduleResponse>('/schedule/sync', req);
console.log('[ScheduleService] 同步响应:', response.data);
return response.data;
}
}