feat(teacher-portal): 添加考试作业成绩查询页面
新增 3 个页面位于 (app) 路由组: /exams - 按班级查询考试列表 /homework - 按班级查询作业列表 /grades - 按考试查询成绩列表 通过 BFF 聚合端点获取 core-edu 数据 遵循纸面设计风格: serif 标题/mono ID/设计令牌
This commit is contained in:
186
apps/teacher-portal/src/app/(app)/exams/page.tsx
Normal file
186
apps/teacher-portal/src/app/(app)/exams/page.tsx
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
import { getToken } from "@/lib/auth";
|
||||||
|
|
||||||
|
interface ExamItem {
|
||||||
|
id: string;
|
||||||
|
classId: string;
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
examDate: string;
|
||||||
|
duration: string;
|
||||||
|
totalScore: string;
|
||||||
|
status: string;
|
||||||
|
createdBy: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiResponse<T> {
|
||||||
|
success: boolean;
|
||||||
|
data?: T;
|
||||||
|
error?: { code: string; message: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ExamsPage() {
|
||||||
|
const [exams, setExams] = useState<ExamItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [classId, setClassId] = useState(
|
||||||
|
"00000000-0000-0000-0000-000000000001",
|
||||||
|
);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const authHeaders = (): Record<string, string> => {
|
||||||
|
const token = getToken();
|
||||||
|
return token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchExams = useCallback(async () => {
|
||||||
|
if (!classId.trim()) return;
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const res = await fetch(
|
||||||
|
`/api/v1/teacher/classes/${encodeURIComponent(classId)}/exams`,
|
||||||
|
{ headers: authHeaders() },
|
||||||
|
);
|
||||||
|
const json: ApiResponse<ExamItem[]> = await res.json();
|
||||||
|
if (json.success && json.data) {
|
||||||
|
setExams(json.data);
|
||||||
|
} else {
|
||||||
|
setError(json.error?.message || "Failed to load");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setError(e instanceof Error ? e.message : "Network error");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [classId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchExams();
|
||||||
|
}, [fetchExams]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="px-10 py-10">
|
||||||
|
<header className="mb-8">
|
||||||
|
<h1
|
||||||
|
className="text-3xl"
|
||||||
|
style={{
|
||||||
|
fontFamily: "var(--font-serif)",
|
||||||
|
color: "var(--color-ink)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
考试管理
|
||||||
|
</h1>
|
||||||
|
<p className="mt-1 text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||||
|
core-edu 域 · BFF 聚合查询
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="rule-thin mb-8" />
|
||||||
|
|
||||||
|
<div className="mb-6 flex items-baseline gap-3">
|
||||||
|
<label
|
||||||
|
className="text-xs uppercase tracking-wide"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
班级 ID
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={classId}
|
||||||
|
onChange={(e) => setClassId(e.target.value)}
|
||||||
|
className="flex-1 max-w-md px-3 py-2 bg-transparent border-b text-sm font-mono"
|
||||||
|
style={{ borderColor: "var(--color-rule)" }}
|
||||||
|
placeholder="输入班级 UUID"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={fetchExams}
|
||||||
|
className="text-xs uppercase tracking-wide hover:opacity-70"
|
||||||
|
style={{ color: "var(--color-accent)" }}
|
||||||
|
>
|
||||||
|
查询
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div
|
||||||
|
className="mark-left mb-4 py-2"
|
||||||
|
style={{ borderColor: "var(--color-accent)" }}
|
||||||
|
>
|
||||||
|
<p className="text-sm px-3" style={{ color: "var(--color-accent)" }}>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<p className="text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||||
|
加载中...
|
||||||
|
</p>
|
||||||
|
) : exams.length === 0 ? (
|
||||||
|
<p
|
||||||
|
className="text-sm italic"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
该班级下暂无考试
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<ul className="space-y-0">
|
||||||
|
{exams.map((exam) => (
|
||||||
|
<li
|
||||||
|
key={exam.id}
|
||||||
|
className="py-4 grid grid-cols-12 gap-4 items-baseline"
|
||||||
|
style={{ borderBottom: "1px solid var(--color-rule)" }}
|
||||||
|
>
|
||||||
|
<div className="col-span-7">
|
||||||
|
<h3
|
||||||
|
className="text-lg"
|
||||||
|
style={{
|
||||||
|
fontFamily: "var(--font-serif)",
|
||||||
|
color: "var(--color-ink)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{exam.title}
|
||||||
|
</h3>
|
||||||
|
{exam.description && (
|
||||||
|
<p
|
||||||
|
className="mt-1 text-sm"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
{exam.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<p
|
||||||
|
className="mt-1 text-xs"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
考试时间: {new Date(exam.examDate).toLocaleString("zh-CN")}
|
||||||
|
{" · "}
|
||||||
|
时长 {exam.duration} 分钟
|
||||||
|
{" · "}
|
||||||
|
满分 {exam.totalScore}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="col-span-3 text-xs"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
状态: {exam.status}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="col-span-2 text-right text-xs font-mono"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
{exam.id.slice(0, 8)}...
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
181
apps/teacher-portal/src/app/(app)/grades/page.tsx
Normal file
181
apps/teacher-portal/src/app/(app)/grades/page.tsx
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
import { getToken } from "@/lib/auth";
|
||||||
|
|
||||||
|
interface GradeItem {
|
||||||
|
id: string;
|
||||||
|
studentId: string;
|
||||||
|
examId: string | null;
|
||||||
|
homeworkId: string | null;
|
||||||
|
score: string;
|
||||||
|
feedback?: string;
|
||||||
|
gradedBy: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiResponse<T> {
|
||||||
|
success: boolean;
|
||||||
|
data?: T;
|
||||||
|
error?: { code: string; message: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function GradesPage() {
|
||||||
|
const [items, setItems] = useState<GradeItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [examId, setExamId] = useState("");
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const authHeaders = (): Record<string, string> => {
|
||||||
|
const token = getToken();
|
||||||
|
return token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchGrades = useCallback(async () => {
|
||||||
|
if (!examId.trim()) return;
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const res = await fetch(
|
||||||
|
`/api/v1/teacher/exams/${encodeURIComponent(examId)}/grades`,
|
||||||
|
{ headers: authHeaders() },
|
||||||
|
);
|
||||||
|
const json: ApiResponse<GradeItem[]> = await res.json();
|
||||||
|
if (json.success && json.data) {
|
||||||
|
setItems(json.data);
|
||||||
|
} else {
|
||||||
|
setError(json.error?.message || "Failed to load");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setError(e instanceof Error ? e.message : "Network error");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [examId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchGrades();
|
||||||
|
}, [fetchGrades]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="px-10 py-10">
|
||||||
|
<header className="mb-8">
|
||||||
|
<h1
|
||||||
|
className="text-3xl"
|
||||||
|
style={{
|
||||||
|
fontFamily: "var(--font-serif)",
|
||||||
|
color: "var(--color-ink)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
成绩查询
|
||||||
|
</h1>
|
||||||
|
<p className="mt-1 text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||||
|
core-edu 域 · BFF 聚合查询
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="rule-thin mb-8" />
|
||||||
|
|
||||||
|
<div className="mb-6 flex items-baseline gap-3">
|
||||||
|
<label
|
||||||
|
className="text-xs uppercase tracking-wide"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
考试 ID
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={examId}
|
||||||
|
onChange={(e) => setExamId(e.target.value)}
|
||||||
|
className="flex-1 max-w-md px-3 py-2 bg-transparent border-b text-sm font-mono"
|
||||||
|
style={{ borderColor: "var(--color-rule)" }}
|
||||||
|
placeholder="输入考试 UUID"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={fetchGrades}
|
||||||
|
className="text-xs uppercase tracking-wide hover:opacity-70"
|
||||||
|
style={{ color: "var(--color-accent)" }}
|
||||||
|
>
|
||||||
|
查询
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div
|
||||||
|
className="mark-left mb-4 py-2"
|
||||||
|
style={{ borderColor: "var(--color-accent)" }}
|
||||||
|
>
|
||||||
|
<p className="text-sm px-3" style={{ color: "var(--color-accent)" }}>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<p className="text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||||
|
加载中...
|
||||||
|
</p>
|
||||||
|
) : items.length === 0 ? (
|
||||||
|
<p
|
||||||
|
className="text-sm italic"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
{examId.trim() ? "该考试下暂无成绩" : "请输入考试 ID 查询成绩"}
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<ul className="space-y-0">
|
||||||
|
{items.map((g) => (
|
||||||
|
<li
|
||||||
|
key={g.id}
|
||||||
|
className="py-4 grid grid-cols-12 gap-4 items-baseline"
|
||||||
|
style={{ borderBottom: "1px solid var(--color-rule)" }}
|
||||||
|
>
|
||||||
|
<div className="col-span-6">
|
||||||
|
<h3
|
||||||
|
className="text-lg"
|
||||||
|
style={{
|
||||||
|
fontFamily: "var(--font-serif)",
|
||||||
|
color: "var(--color-ink)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
学生: {g.studentId}
|
||||||
|
</h3>
|
||||||
|
{g.feedback && (
|
||||||
|
<p
|
||||||
|
className="mt-1 text-sm"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
反馈: {g.feedback}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="col-span-2 text-2xl"
|
||||||
|
style={{
|
||||||
|
fontFamily: "var(--font-serif)",
|
||||||
|
color: "var(--color-accent)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{g.score}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="col-span-2 text-xs"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
评分人: {g.gradedBy}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="col-span-2 text-right text-xs font-mono"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
{g.id.slice(0, 8)}...
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
180
apps/teacher-portal/src/app/(app)/homework/page.tsx
Normal file
180
apps/teacher-portal/src/app/(app)/homework/page.tsx
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useEffect, useCallback } from "react";
|
||||||
|
import { getToken } from "@/lib/auth";
|
||||||
|
|
||||||
|
interface HomeworkItem {
|
||||||
|
id: string;
|
||||||
|
classId: string;
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
dueDate: string;
|
||||||
|
status: string;
|
||||||
|
createdBy: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiResponse<T> {
|
||||||
|
success: boolean;
|
||||||
|
data?: T;
|
||||||
|
error?: { code: string; message: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function HomeworkPage() {
|
||||||
|
const [items, setItems] = useState<HomeworkItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [classId, setClassId] = useState(
|
||||||
|
"00000000-0000-0000-0000-000000000001",
|
||||||
|
);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const authHeaders = (): Record<string, string> => {
|
||||||
|
const token = getToken();
|
||||||
|
return token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchHomework = useCallback(async () => {
|
||||||
|
if (!classId.trim()) return;
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const res = await fetch(
|
||||||
|
`/api/v1/teacher/classes/${encodeURIComponent(classId)}/homework`,
|
||||||
|
{ headers: authHeaders() },
|
||||||
|
);
|
||||||
|
const json: ApiResponse<HomeworkItem[]> = await res.json();
|
||||||
|
if (json.success && json.data) {
|
||||||
|
setItems(json.data);
|
||||||
|
} else {
|
||||||
|
setError(json.error?.message || "Failed to load");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setError(e instanceof Error ? e.message : "Network error");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [classId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchHomework();
|
||||||
|
}, [fetchHomework]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="px-10 py-10">
|
||||||
|
<header className="mb-8">
|
||||||
|
<h1
|
||||||
|
className="text-3xl"
|
||||||
|
style={{
|
||||||
|
fontFamily: "var(--font-serif)",
|
||||||
|
color: "var(--color-ink)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
作业管理
|
||||||
|
</h1>
|
||||||
|
<p className="mt-1 text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||||
|
core-edu 域 · BFF 聚合查询
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="rule-thin mb-8" />
|
||||||
|
|
||||||
|
<div className="mb-6 flex items-baseline gap-3">
|
||||||
|
<label
|
||||||
|
className="text-xs uppercase tracking-wide"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
班级 ID
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={classId}
|
||||||
|
onChange={(e) => setClassId(e.target.value)}
|
||||||
|
className="flex-1 max-w-md px-3 py-2 bg-transparent border-b text-sm font-mono"
|
||||||
|
style={{ borderColor: "var(--color-rule)" }}
|
||||||
|
placeholder="输入班级 UUID"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
onClick={fetchHomework}
|
||||||
|
className="text-xs uppercase tracking-wide hover:opacity-70"
|
||||||
|
style={{ color: "var(--color-accent)" }}
|
||||||
|
>
|
||||||
|
查询
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div
|
||||||
|
className="mark-left mb-4 py-2"
|
||||||
|
style={{ borderColor: "var(--color-accent)" }}
|
||||||
|
>
|
||||||
|
<p className="text-sm px-3" style={{ color: "var(--color-accent)" }}>
|
||||||
|
{error}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<p className="text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||||
|
加载中...
|
||||||
|
</p>
|
||||||
|
) : items.length === 0 ? (
|
||||||
|
<p
|
||||||
|
className="text-sm italic"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
该班级下暂无作业
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<ul className="space-y-0">
|
||||||
|
{items.map((hw) => (
|
||||||
|
<li
|
||||||
|
key={hw.id}
|
||||||
|
className="py-4 grid grid-cols-12 gap-4 items-baseline"
|
||||||
|
style={{ borderBottom: "1px solid var(--color-rule)" }}
|
||||||
|
>
|
||||||
|
<div className="col-span-7">
|
||||||
|
<h3
|
||||||
|
className="text-lg"
|
||||||
|
style={{
|
||||||
|
fontFamily: "var(--font-serif)",
|
||||||
|
color: "var(--color-ink)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{hw.title}
|
||||||
|
</h3>
|
||||||
|
{hw.description && (
|
||||||
|
<p
|
||||||
|
className="mt-1 text-sm"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
{hw.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<p
|
||||||
|
className="mt-1 text-xs"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
截止: {new Date(hw.dueDate).toLocaleString("zh-CN")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="col-span-3 text-xs"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
状态: {hw.status}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="col-span-2 text-right text-xs font-mono"
|
||||||
|
style={{ color: "var(--color-ink-muted)" }}
|
||||||
|
>
|
||||||
|
{hw.id.slice(0, 8)}...
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user