"use client"; /** * 课程对练:输入课程标识 → 生成题目 → 查看可对练题目 → 发起对练逐题作答 → 结束生成报告。 */ import { useState } from "react"; import { GraduationCap } from "lucide-react"; import { CredibilityBadge, RawDetails, ScoreBar, StatTile, } from "@/components/display"; import { RadialProgress } from "@/components/charts"; import { EmptyState, ErrorBanner, Loading, PageHeading, } from "@/components/feedback"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { UsageGuide } from "@/components/usage-guide"; import { ApiError } from "@/lib/api"; import { practiceApi } from "@/lib/services"; import type { AnswerResult, PracticeReport } from "@/lib/types"; /* eslint-disable @typescript-eslint/no-explicit-any */ export default function PracticePage() { const [courseId, setCourseId] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [questions, setQuestions] = useState([]); const [session, setSession] = useState(null); const [answer, setAnswer] = useState(""); const [lastResult, setLastResult] = useState(null); const [report, setReport] = useState(null); async function run(fn: () => Promise, after?: (v: T) => void) { setError(null); setBusy(true); try { const v = await fn(); after?.(v); } catch (err) { setError(err instanceof ApiError ? err.message : "操作失败"); } finally { setBusy(false); } } const currentQuestion: any = session?.questions?.[session?.currentIndex ?? 0] ?? session?.currentQuestion ?? null; return (
} title="医学题库" description="基于教学大纲智能出题,在线作答并获得知识薄弱点分析与能力报告。" /> 选择课程
setCourseId(e.target.value)} placeholder="如:内科学101" />
{error && (
)}
{busy && } {questions.length > 0 && ( 题目({questions.length})
    {questions.map((q: any, i: number) => (
  • {i + 1}. {q.stem ?? q.title ?? q.content ?? "(题干)"}

    {q.reviewStatus && ( {q.reviewStatus === "pending" ? "待审核" : q.reviewStatus === "approved" ? "已通过" : q.reviewStatus === "returned" ? "已退回" : q.reviewStatus} )}
    {Array.isArray(q.options) && (
      {q.options.map((o: any, oi: number) => (
    • {o.key ?? String.fromCharCode(65 + oi)}.{" "} {o.text ?? o.label ?? String(o)}
    • ))}
    )}
  • ))}
)} {session && !report && ( 进行对练 {currentQuestion ? (

{currentQuestion.stem ?? currentQuestion.title ?? currentQuestion.content ?? "当前题目"}

{Array.isArray(currentQuestion.options) && (
    {currentQuestion.options.map((o: any, oi: number) => (
  • {o.key ?? String.fromCharCode(65 + oi)}.{" "} {o.text ?? o.label ?? String(o)}
  • ))}
)}