feat: 新增备课模块并修复全模块 P0/P1/P2 缺陷
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
主要变更: - 新增 lesson-preparation 模块: 备课编辑器、节点编辑、AI 建议、知识点选择、版本历史、作业发布 - 新增 shared 通用组件: charts/question-bank-filters/schedule-list/ui (chip-nav/filter-bar/page-header/stat-card/stat-item) - 新增 student/admin 端 loading.tsx 与 error.tsx, 优化加载与错误态体验 - 新增 teacher/lesson-plans 页面 (列表/新建/编辑) - 新增 drizzle 迁移 0002_tiny_lionheart 及 snapshot - 新增 textbooks/schema.ts 与 exams/utils/normalize-structure.ts - 修复 Tiptap v3 SSR hydration 崩溃 (rich-text-block immediatelyRender: false) - 重构多模块 data-access/actions/组件, 修复权限校验与类型规范 - 同步架构文档 004/005 反映新增模块、导出、依赖关系 - 归档 bugs/* 测试报告与 e2e 测试脚本 (admin/parent/student/teacher web_test)
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useLessonPlanEditor } from "../../hooks/use-lesson-plan-editor";
|
||||
import { QuestionBankPicker } from "../question-bank-picker";
|
||||
import { InlineQuestionEditor } from "../inline-question-editor";
|
||||
import { PublishHomeworkDialog } from "../publish-homework-dialog";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import type {
|
||||
ExerciseBlockData,
|
||||
ExerciseItem,
|
||||
} from "../../types";
|
||||
|
||||
interface Props {
|
||||
blockId: string;
|
||||
data: ExerciseBlockData;
|
||||
classes: { id: string; name: string }[];
|
||||
}
|
||||
|
||||
export function ExerciseBlock({ blockId, data, classes }: Props) {
|
||||
const { updateNode, planId } = useLessonPlanEditor();
|
||||
const [showBank, setShowBank] = useState(false);
|
||||
const [showInline, setShowInline] = useState(false);
|
||||
const [showPublish, setShowPublish] = useState(false);
|
||||
|
||||
function update(patch: Partial<ExerciseBlockData>) {
|
||||
updateNode(blockId, { data: { ...data, ...patch } });
|
||||
}
|
||||
|
||||
function addItems(items: ExerciseItem[]) {
|
||||
const next = [...data.items, ...items];
|
||||
update({
|
||||
items: next.map((it, i) => ({ ...it, order: i })),
|
||||
});
|
||||
}
|
||||
|
||||
function removeItem(idx: number) {
|
||||
update({
|
||||
items: data.items
|
||||
.filter((_, i) => i !== idx)
|
||||
.map((it, i) => ({ ...it, order: i })),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-2">
|
||||
<select
|
||||
value={data.purpose}
|
||||
onChange={(e) =>
|
||||
update({ purpose: e.target.value as never })
|
||||
}
|
||||
className="border rounded px-2 py-1 text-sm"
|
||||
>
|
||||
<option value="class_practice">课堂练习</option>
|
||||
<option value="after_class_homework">课后作业</option>
|
||||
</select>
|
||||
</div>
|
||||
{data.items.length === 0 ? (
|
||||
<p className="text-on-surface-variant text-sm p-4 text-center border border-dashed rounded">
|
||||
暂无题目,点击下方按钮添加
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-1">
|
||||
{data.items.map((item, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="flex items-center gap-2 border rounded p-2"
|
||||
>
|
||||
<span className="text-xs bg-surface-container-highest px-2 py-0.5 rounded">
|
||||
{item.source === "bank" ? "题库" : "新建"}
|
||||
</span>
|
||||
<span className="text-sm flex-1 truncate">
|
||||
{item.source === "bank"
|
||||
? `题目 ${item.questionId.slice(0, 8)}`
|
||||
: "课案内新建题目"}
|
||||
</span>
|
||||
<span className="text-xs">{item.score}分</span>
|
||||
<button onClick={() => removeItem(idx)}>
|
||||
<Trash2 className="w-3 h-3 text-error" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setShowBank(true)}
|
||||
>
|
||||
<Plus className="w-3 h-3 mr-1" />
|
||||
从题库添加
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setShowInline(true)}
|
||||
>
|
||||
<Plus className="w-3 h-3 mr-1" />
|
||||
新建题目
|
||||
</Button>
|
||||
{data.publishedAssignmentId ? (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<span className="bg-tertiary-container/20 text-tertiary px-2 py-1 rounded">
|
||||
已发布为作业
|
||||
</span>
|
||||
<a
|
||||
href="/teacher/homework"
|
||||
className="text-primary underline"
|
||||
>
|
||||
查看
|
||||
</a>
|
||||
</div>
|
||||
) : (
|
||||
data.purpose === "after_class_homework" &&
|
||||
data.items.length > 0 && (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => setShowPublish(true)}
|
||||
>
|
||||
发布为作业
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
{showBank && (
|
||||
<QuestionBankPicker
|
||||
existingIds={data.items.map((i) => i.questionId)}
|
||||
onPick={addItems}
|
||||
onClose={() => setShowBank(false)}
|
||||
/>
|
||||
)}
|
||||
{showInline && (
|
||||
<InlineQuestionEditor
|
||||
onAdd={(item) => {
|
||||
addItems([item]);
|
||||
setShowInline(false);
|
||||
}}
|
||||
onClose={() => setShowInline(false)}
|
||||
/>
|
||||
)}
|
||||
{showPublish && (
|
||||
<PublishHomeworkDialog
|
||||
planId={planId}
|
||||
blockId={blockId}
|
||||
classes={classes}
|
||||
onClose={() => setShowPublish(false)}
|
||||
onPublished={() => window.location.reload()}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { RichTextBlock } from "./rich-text-block";
|
||||
import type { RichTextBlockData } from "../../types";
|
||||
|
||||
interface Props {
|
||||
data: RichTextBlockData;
|
||||
onUpdate: (data: RichTextBlockData) => void;
|
||||
}
|
||||
|
||||
export function ReflectionBlock(props: Props) {
|
||||
// 教学反思在 P1 阶段与普通富文本一致,P3 再扩展学情数据嵌入
|
||||
return <RichTextBlock {...props} hint="课后填写教学反思..." />;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
"use client";
|
||||
|
||||
import { useEditor, EditorContent } from "@tiptap/react";
|
||||
import StarterKit from "@tiptap/starter-kit";
|
||||
import Placeholder from "@tiptap/extension-placeholder";
|
||||
import { useEffect, useState } from "react";
|
||||
import type { RichTextBlockData } from "../../types";
|
||||
import { KnowledgePointPicker } from "../knowledge-point-picker";
|
||||
import { Tag } from "lucide-react";
|
||||
|
||||
interface Props {
|
||||
data: RichTextBlockData;
|
||||
hint?: string;
|
||||
textbookId?: string;
|
||||
chapterId?: string;
|
||||
onUpdate: (data: RichTextBlockData) => void;
|
||||
}
|
||||
|
||||
export function RichTextBlock({
|
||||
data,
|
||||
hint,
|
||||
textbookId,
|
||||
chapterId,
|
||||
onUpdate,
|
||||
}: Props) {
|
||||
const editor = useEditor({
|
||||
extensions: [
|
||||
StarterKit,
|
||||
Placeholder.configure({ placeholder: hint ?? "输入内容..." }),
|
||||
],
|
||||
content: data.html,
|
||||
immediatelyRender: false,
|
||||
onUpdate: ({ editor }) => {
|
||||
onUpdate({ ...data, html: editor.getHTML() });
|
||||
},
|
||||
editorProps: {
|
||||
attributes: {
|
||||
class:
|
||||
"prose prose-sm max-w-none focus:outline-none min-h-[60px] px-3 py-2",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// 外部 content 变化时同步(如版本回退)
|
||||
useEffect(() => {
|
||||
if (editor && !editor.isDestroyed && data.html !== editor.getHTML()) {
|
||||
editor.commands.setContent(data.html);
|
||||
}
|
||||
}, [data.html, editor]);
|
||||
|
||||
const [showKpPicker, setShowKpPicker] = useState(false);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<EditorContent editor={editor} />
|
||||
<div className="flex items-center gap-2 mt-2 px-3 flex-wrap">
|
||||
{data.knowledgePointIds.length > 0 && (
|
||||
<span className="text-xs text-on-surface-variant">
|
||||
已关联 {data.knowledgePointIds.length} 个知识点
|
||||
</span>
|
||||
)}
|
||||
<button
|
||||
onClick={() => setShowKpPicker(true)}
|
||||
className="text-xs text-primary hover:underline inline-flex items-center gap-1"
|
||||
>
|
||||
<Tag className="w-3 h-3" />
|
||||
标注知识点
|
||||
</button>
|
||||
</div>
|
||||
{showKpPicker && (
|
||||
<KnowledgePointPicker
|
||||
textbookId={textbookId}
|
||||
chapterId={chapterId}
|
||||
selectedIds={data.knowledgePointIds}
|
||||
onChange={(ids) => onUpdate({ ...data, knowledgePointIds: ids })}
|
||||
onClose={() => setShowKpPicker(false)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useLessonPlanEditor } from "../../hooks/use-lesson-plan-editor";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
import type {
|
||||
TextStudyBlockData,
|
||||
TextStudyAnnotation,
|
||||
} from "../../types";
|
||||
|
||||
interface Props {
|
||||
blockId: string;
|
||||
data: TextStudyBlockData;
|
||||
}
|
||||
|
||||
export function TextStudyBlock({ blockId, data }: Props) {
|
||||
const { updateNode } = useLessonPlanEditor();
|
||||
const [selection, setSelection] = useState<{
|
||||
start: number;
|
||||
end: number;
|
||||
} | null>(null);
|
||||
|
||||
function update(patch: Partial<TextStudyBlockData>) {
|
||||
updateNode(blockId, { data: { ...data, ...patch } });
|
||||
}
|
||||
|
||||
function handleTextSelect() {
|
||||
const sel = window.getSelection();
|
||||
if (!sel || sel.rangeCount === 0) return;
|
||||
const range = sel.getRangeAt(0);
|
||||
// 简化:用相对 sourceText 的字符偏移
|
||||
const start = range.startOffset;
|
||||
const end = range.endOffset;
|
||||
if (end > start) setSelection({ start, end });
|
||||
}
|
||||
|
||||
function addAnnotation() {
|
||||
if (!selection) {
|
||||
alert("请先在课文中选中一段文本");
|
||||
return;
|
||||
}
|
||||
const ann: TextStudyAnnotation = {
|
||||
id: createId(),
|
||||
anchor: selection,
|
||||
nodeType: "language_feature",
|
||||
title: "教学节点",
|
||||
note: "",
|
||||
color: "yellow",
|
||||
};
|
||||
update({ annotations: [...data.annotations, ann] });
|
||||
setSelection(null);
|
||||
}
|
||||
|
||||
function removeAnnotation(id: string) {
|
||||
update({
|
||||
annotations: data.annotations.filter((a) => a.id !== id),
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="text-sm font-medium">课文原文</label>
|
||||
<textarea
|
||||
value={data.sourceText}
|
||||
onChange={(e) => update({ sourceText: e.target.value })}
|
||||
onMouseUp={handleTextSelect}
|
||||
className="w-full border rounded p-2 mt-1 min-h-[120px] font-serif leading-loose"
|
||||
placeholder="粘贴课文原文,选中文本后可添加教学节点"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={addAnnotation}
|
||||
disabled={!selection}
|
||||
>
|
||||
<Plus className="w-3 h-3 mr-1" />
|
||||
为选中文本添加节点
|
||||
</Button>
|
||||
{data.annotations.length > 0 && (
|
||||
<div className="space-y-2">
|
||||
{data.annotations.map((ann) => (
|
||||
<div
|
||||
key={ann.id}
|
||||
className="border-l-4 border-secondary-container pl-3 py-1"
|
||||
>
|
||||
<div className="flex justify-between items-center">
|
||||
<input
|
||||
value={ann.title}
|
||||
onChange={(e) =>
|
||||
update({
|
||||
annotations: data.annotations.map((a) =>
|
||||
a.id === ann.id
|
||||
? { ...a, title: e.target.value }
|
||||
: a,
|
||||
),
|
||||
})
|
||||
}
|
||||
className="font-medium text-sm bg-transparent flex-1"
|
||||
/>
|
||||
<button onClick={() => removeAnnotation(ann.id)}>
|
||||
<Trash2 className="w-3 h-3 text-error" />
|
||||
</button>
|
||||
</div>
|
||||
<textarea
|
||||
value={ann.note}
|
||||
onChange={(e) =>
|
||||
update({
|
||||
annotations: data.annotations.map((a) =>
|
||||
a.id === ann.id
|
||||
? { ...a, note: e.target.value }
|
||||
: a,
|
||||
),
|
||||
})
|
||||
}
|
||||
className="w-full text-sm border rounded p-1 mt-1 min-h-[40px]"
|
||||
placeholder="教学说明..."
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user