import React, { useState, useEffect } from 'react' import { Space, Tag, Typography, Radio, Checkbox, Input, Button } from 'antd' import type { Question, AnswerResult as AnswerResultType } from '../types/question' import AnswerResult from './AnswerResult' import styles from '../pages/Question.module.less' const { TextArea } = Input const { Title } = Typography interface QuestionCardProps { question: Question selectedAnswer: string | string[] showResult: boolean answerResult: AnswerResultType | null loading: boolean autoNextLoading: boolean onAnswerChange: (answer: string | string[]) => void onSubmit: () => void onNext: () => void } const QuestionCard: React.FC = ({ question, selectedAnswer, showResult, answerResult, loading, autoNextLoading, onAnswerChange, onSubmit, onNext, }) => { const [fillAnswers, setFillAnswers] = useState([]) // 当题目ID变化时,重置填空题答案 useEffect(() => { if (question.type === 'fill-in-blank') { setFillAnswers([]) } }, [question.id, question.type]) // 渲染填空题内容 const renderFillContent = () => { const content = question.content const parts = content.split('****') if (parts.length === 1) { return
{content}
} if (fillAnswers.length === 0) { setFillAnswers(new Array(parts.length - 1).fill('')) } return (
{parts.map((part, index) => ( {part} {index < parts.length - 1 && ( { const newAnswers = [...fillAnswers] newAnswers[index] = e.target.value setFillAnswers(newAnswers) onAnswerChange(newAnswers) }} disabled={showResult} style={{ display: 'inline-block', width: '120px', margin: '0 8px', }} /> )} ))}
) } // 渲染题目选项 const renderOptions = () => { if (question.type === 'fill-in-blank') { return null } if (question.type === 'short-answer') { return (