From 9314dc8505f8960d8fc49d2ef83ec692e66e0111 Mon Sep 17 00:00:00 2001 From: Wang Zhuoxuan Date: Tue, 7 Apr 2026 23:16:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E5=8D=A1=E7=BC=96=E8=BE=91=E7=BB=84=E4=BB=B6=EF=BC=88Phase=201?= =?UTF-8?q?b=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新建 KnowledgeCardFields 组件:基础版/深度版编辑、字符计数器、来源参考、预览面板 - 提取 QuestionForm 中内联的知识卡字段为独立组件 - 新增 sourceRef 字段到类型定义和表单 schema --- CLAUDE.md | 4 +- .../question/KnowledgeCardFields.tsx | 178 ++++++++++++++++++ src/components/question/QuestionForm.tsx | 48 ++--- src/types/question.ts | 2 + 4 files changed, 196 insertions(+), 36 deletions(-) create mode 100644 src/components/question/KnowledgeCardFields.tsx diff --git a/CLAUDE.md b/CLAUDE.md index 9919bfb..afbf642 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -5,7 +5,7 @@ ## Current Status -**Phase 1b in progress.** Category CRUD + Question CRUD done. Remaining: 知识卡编辑、题目状态流转 UI 完善、批量导入。 +**Phase 1b in progress.** Category CRUD + Question CRUD + 知识卡编辑 done. Remaining: 题目状态流转 UI 完善、批量导入。 Development follows the phased roadmap in [dev-spec.md](./dev-spec.md) §九. @@ -38,7 +38,7 @@ src/ │ ├── layout/ # Sidebar, Header, AdminLayout │ ├── charts/ # StatsCard, chart wrappers │ ├── category/ # Category CRUD (columns, dialogs) -│ ├── question/ # Question CRUD (columns, form, StatusBadge, DistractorEditor) +│ ├── question/ # Question CRUD (columns, form, StatusBadge, DistractorEditor, KnowledgeCardFields) ├── lib/ │ ├── api-client.ts # HTTP client for /admin/* endpoints │ ├── auth.ts # Admin JWT token management diff --git a/src/components/question/KnowledgeCardFields.tsx b/src/components/question/KnowledgeCardFields.tsx new file mode 100644 index 0000000..6551ae7 --- /dev/null +++ b/src/components/question/KnowledgeCardFields.tsx @@ -0,0 +1,178 @@ +import { useState } from "react" +import type { UseFormRegisterReturn } from "react-hook-form" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import { Textarea } from "@/components/ui/textarea" +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card" +import { Badge } from "@/components/ui/badge" + +const BASIC_MAX = 100 +const DEEP_MAX = 300 + +interface KnowledgeCardFieldsProps { + basicRegister: UseFormRegisterReturn + deepRegister: UseFormRegisterReturn + sourceRefRegister: UseFormRegisterReturn + basicError?: string + deepError?: string + watchBasic: string + watchDeep: string +} + +export function KnowledgeCardFields({ + basicRegister, + deepRegister, + sourceRefRegister, + basicError, + deepError, + watchBasic, + watchDeep, +}: KnowledgeCardFieldsProps) { + const [showPreview, setShowPreview] = useState(false) + const [deepExpanded, setDeepExpanded] = useState(!!watchDeep) + + const basicCount = watchBasic.length + const deepCount = watchDeep.length + const basicOver = basicCount > BASIC_MAX + const deepOver = deepCount > DEEP_MAX + + return ( +
+ {/* 基础版 */} +
+
+ + + 所有用户可见 + +
+

+ 2-3 句趣味解读,让用户答完题后学到新知识 +

+