diff --git a/web/src/api/exam.ts b/web/src/api/exam.ts index 887a5cf..224df15 100644 --- a/web/src/api/exam.ts +++ b/web/src/api/exam.ts @@ -97,7 +97,7 @@ export const submitExam = (examId: number, data: SubmitExamRequest) => { // 获取每日一练排行榜 export const getDailyExamRanking = () => { - return request<{ + return request.get<{ success: boolean data: { exam_id: number diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index bb26ec4..34c4020 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -604,6 +604,52 @@ const Home: React.FC = () => { 快速开始 + {/* 每日一练快捷入口 */} + + { + // 检查今日每日一练是否存在 + if (dailyExamRanking.exam_id) { + try { + // 调用开始考试API,创建考试记录 + const res = await examApi.startExam(dailyExamRanking.exam_id) + if (res.success && res.data) { + // 跳转到考试答题页面(注意路由是 /taking 不是 /take) + navigate(`/exam/${dailyExamRanking.exam_id}/taking/${res.data.record_id}`) + } else { + message.error(res.message || '开始考试失败') + } + } catch (error) { + console.error('开始每日一练失败:', error) + message.error('开始考试失败,请稍后再试') + } + } else { + message.warning('今日每日一练尚未生成,请稍后再试') + } + }} + > + +
+ +
+
+ 每日一练 + + {dailyExamRanking.exam_title ? dailyExamRanking.exam_title : '今日练习,冲刺高分'} + +
+
+
+ +