修复了课程表和发帖按钮

This commit is contained in:
2026-03-18 00:25:46 +08:00
parent b50bd9abb3
commit 71b4f8a679
6 changed files with 130 additions and 68 deletions

View File

@@ -45,42 +45,22 @@ interface SyncScheduleResponse {
error_message?: string;
}
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,
};
};
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,
});
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);
}
@@ -99,9 +79,7 @@ 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;
}
}