"use client"; import { useState } from "react"; import { Award, BookOpen, CheckCircle2, Target, Timer, } from "lucide-react"; import { ScoreBar } from "@/components/display"; 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 { Select } from "@/components/ui/select"; import { Textarea } from "@/components/ui/textarea"; import { UsageGuide } from "@/components/usage-guide"; import { ApiError } from "@/lib/api"; import { examPrepApi } from "@/lib/services"; const SUBJECTS = [ { value: "internal", label: "内科学" }, { value: "surgery", label: "外科学" }, { value: "pediatrics", label: "儿科学" }, { value: "obgyn", label: "妇产科学" }, { value: "pharmacology", label: "药理学" }, { value: "pathology", label: "病理学" }, { value: "diagnostics", label: "诊断学" }, { value: "ethics", label: "医学伦理" }, ]; export default function ExamPrepPage() { const [subject, setSubject] = useState(""); const [mode, setMode] = useState("auto"); const [question, setQuestion] = useState(null); const [answer, setAnswer] = useState(""); const [result, setResult] = useState(null); const [stats, setStats] = useState(null); const [history, setHistory] = useState([]); const [selectedRecord, setSelectedRecord] = useState(null); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); async function generateQuestion() { setBusy(true); setError(null); setResult(null); setAnswer(""); try { const q = await examPrepApi.generateQuestion({ subject: subject || undefined, mode }); setQuestion(q); } catch (err) { setError(err instanceof ApiError ? err.message : "生成失败"); } finally { setBusy(false); } } async function submitAnswer() { if (!answer.trim() || !question) return; setBusy(true); setError(null); try { const r = await examPrepApi.submitAnswer(question.id ?? "current", { answer }); setResult(r); await loadStats(); } catch (err) { setError(err instanceof ApiError ? err.message : "提交失败"); } finally { setBusy(false); } } async function loadStats() { setBusy(true); setError(null); try { const s = await examPrepApi.getStats(); setStats(s); } catch (err) { setError(err instanceof ApiError ? err.message : "加载失败"); } finally { setBusy(false); } } async function loadHistory() { setBusy(true); setError(null); try { const h = await examPrepApi.listHistory(); setHistory(Array.isArray(h) ? h : []); } catch (err) { setError(err instanceof ApiError ? err.message : "加载失败"); } finally { setBusy(false); } } async function handleDeleteRecord(recordId: string) { setBusy(true); setError(null); try { await examPrepApi.deleteHistory(recordId); await loadHistory(); await loadStats(); } catch (err) { setError(err instanceof ApiError ? err.message : "删除失败"); } finally { setBusy(false); } } async function handleDeleteAll() { if (!confirm("确定要清空所有答题记录吗?此操作不可恢复。")) return; setBusy(true); setError(null); try { await examPrepApi.deleteAllHistory(); await loadHistory(); await loadStats(); } catch (err) { setError(err instanceof ApiError ? err.message : "清空失败"); } finally { setBusy(false); } } return (
} title="执业医师备考" description="针对执业医师考试的专项题库与进度追踪,强化薄弱科目。" />
专项训练
{selectedRecord && ( )}
{error && } {question && (

{question.content ?? question.question ?? JSON.stringify(question)}

{question.options && (
    {question.options.map((opt: string, i: number) => (
  • {String.fromCharCode(65 + i)}. {opt}
  • ))}
)} {question.subject && ( {SUBJECTS.find((s) => s.value === question.subject)?.label ?? question.subject} )}
{!result && (