diff --git a/web/src/components/QuestionCard.tsx b/web/src/components/QuestionCard.tsx index 75b4adb..a197065 100644 --- a/web/src/components/QuestionCard.tsx +++ b/web/src/components/QuestionCard.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect } from 'react' import { Space, Tag, Typography, Radio, Checkbox, Input, Button } from 'antd' +import { ReloadOutlined } from '@ant-design/icons' import type { Question, AnswerResult as AnswerResultType } from '../types/question' import AnswerResult from './AnswerResult' import styles from '../pages/Question.module.less' @@ -17,6 +18,8 @@ interface QuestionCardProps { onAnswerChange: (answer: string | string[]) => void onSubmit: () => void onNext: () => void + onRetry?: () => void // 新增:重新答题回调 + mode?: string // 新增:答题模式(用于判断是否是错题练习) } const QuestionCard: React.FC = ({ @@ -29,6 +32,8 @@ const QuestionCard: React.FC = ({ onAnswerChange, onSubmit, onNext, + onRetry, + mode, }) => { const [fillAnswers, setFillAnswers] = useState([]) @@ -187,9 +192,23 @@ const QuestionCard: React.FC = ({ 提交答案 ) : ( - + + {/* 如果是错题练习模式且答案错误,显示重新答题按钮 */} + {mode === 'wrong' && !answerResult?.correct && onRetry && ( + + )} + + )} diff --git a/web/src/pages/Question.tsx b/web/src/pages/Question.tsx index f212984..1570b8b 100644 --- a/web/src/pages/Question.tsx +++ b/web/src/pages/Question.tsx @@ -452,6 +452,23 @@ const QuestionPage: React.FC = () => { loadQuestions(typeParam || undefined); }; + // 重新答题(错题练习模式) + const handleRetryQuestion = () => { + // 重置当前题目的答题状态 + setShowResult(false); + setAnswerResult(null); + + // 重置答案 + if (currentQuestion) { + setSelectedAnswer( + currentQuestion.type === "multiple-selection" ? [] : "" + ); + } + + // 滚动到页面顶部 + window.scrollTo({ top: 0, behavior: 'smooth' }); + }; + return (
{/* 固定顶栏:包含导航和进度 */} @@ -503,6 +520,8 @@ const QuestionPage: React.FC = () => { onAnswerChange={setSelectedAnswer} onSubmit={handleSubmit} onNext={handleNext} + onRetry={handleRetryQuestion} + mode={searchParams.get("mode") || undefined} /> )}