feat(teacher-portal): 完整实现 teacher-portal 微前端
包含 settings/students/api、graphql、mocks、ui-tokens 设计令牌等
This commit is contained in:
@@ -1,293 +1,97 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { getToken } from "@/lib/auth";
|
||||
/**
|
||||
* Classes 页面 - 班级管理(只读列表)
|
||||
*
|
||||
* 数据来源(ARB-001 §1.2):GraphQL ClassesQuery
|
||||
* - 返回当前教师 dataScope 范围内的班级列表
|
||||
* - P2 阶段为只读展示(Mutation 在 P3 启用)
|
||||
*
|
||||
* 维护者:ai13(teacher-portal)
|
||||
*/
|
||||
|
||||
interface ClassItem {
|
||||
id: string;
|
||||
name: string;
|
||||
gradeId: string;
|
||||
description?: string;
|
||||
createdAt: number;
|
||||
updatedAt: number;
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: { code: string; message: string };
|
||||
}
|
||||
import { useQuery } from "urql";
|
||||
import Link from "next/link";
|
||||
import { Loading, Empty } from "@edu/ui-components";
|
||||
import { ClassesQuery } from "@/lib/graphql";
|
||||
import type { Class } from "@/lib/graphql";
|
||||
|
||||
export default function ClassesPage() {
|
||||
const [classes, setClasses] = useState<ClassItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [gradeId, setGradeId] = useState(
|
||||
"550e8400-e29b-41d4-a716-446655440000",
|
||||
);
|
||||
const [description, setDescription] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const authHeaders = (): Record<string, string> => {
|
||||
const token = getToken();
|
||||
return token ? { Authorization: `Bearer ${token}` } : {};
|
||||
};
|
||||
|
||||
const fetchClasses = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await fetch("/api/v1/classes", {
|
||||
headers: authHeaders(),
|
||||
});
|
||||
const json: ApiResponse<ClassItem[]> = await res.json();
|
||||
if (json.success && json.data) {
|
||||
setClasses(json.data);
|
||||
} else {
|
||||
setError(json.error?.message || "Failed to load");
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Network error");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchClasses();
|
||||
}, [fetchClasses]);
|
||||
|
||||
const handleCreate = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!name.trim()) return;
|
||||
try {
|
||||
const res = await fetch("/api/v1/classes", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...authHeaders(),
|
||||
},
|
||||
body: JSON.stringify({ name, gradeId, description }),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.success) {
|
||||
setError(json.error?.message || "Create failed");
|
||||
return;
|
||||
}
|
||||
setName("");
|
||||
setDescription("");
|
||||
await fetchClasses();
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Network error");
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
try {
|
||||
const res = await fetch(`/api/v1/classes/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: authHeaders(),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.success) {
|
||||
setError(json.error?.message || "Delete failed");
|
||||
return;
|
||||
}
|
||||
await fetchClasses();
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Network error");
|
||||
}
|
||||
};
|
||||
const [result] = useQuery({ query: ClassesQuery });
|
||||
|
||||
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)" }}>
|
||||
classes 域 CRUD · JWT 鉴权
|
||||
<h1 className="text-3xl font-serif text-ink">班级管理</h1>
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
GraphQL ClassesQuery · 按教师 dataScope 过滤
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div className="rule-thin mb-8" />
|
||||
|
||||
<div className="grid grid-cols-12 gap-8">
|
||||
<aside className="col-span-4">
|
||||
<h2
|
||||
className="text-xl mb-4"
|
||||
style={{ fontFamily: "var(--font-serif)" }}
|
||||
>
|
||||
新建班级
|
||||
<section>
|
||||
<div className="flex items-baseline justify-between mb-4">
|
||||
<h2 className="text-xl font-serif text-ink">
|
||||
班级列表
|
||||
<span className="ml-2 text-sm font-sans text-ink-muted">
|
||||
{result.data?.classes.length ?? 0} 个
|
||||
</span>
|
||||
</h2>
|
||||
<div className="rule-thin mb-4" />
|
||||
<form onSubmit={handleCreate} className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
className="block text-xs uppercase tracking-wide mb-1"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
班级名称
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className="w-full px-3 py-2 bg-transparent border-b focus:outline-none focus:border-b-2"
|
||||
style={{
|
||||
borderColor: "var(--color-rule)",
|
||||
borderRadius: "6px 6px 0 0",
|
||||
}}
|
||||
placeholder="如:高三(1)班"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
className="block text-xs uppercase tracking-wide mb-1"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
年级 ID
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={gradeId}
|
||||
onChange={(e) => setGradeId(e.target.value)}
|
||||
className="w-full px-3 py-2 bg-transparent border-b text-sm font-mono"
|
||||
style={{
|
||||
borderColor: "var(--color-rule)",
|
||||
borderRadius: "6px 6px 0 0",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
className="block text-xs uppercase tracking-wide mb-1"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
描述(可选)
|
||||
</label>
|
||||
<textarea
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
className="w-full px-3 py-2 bg-transparent border-b resize-none"
|
||||
style={{
|
||||
borderColor: "var(--color-rule)",
|
||||
borderRadius: "6px 6px 0 0",
|
||||
}}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
className="px-4 py-2 text-white text-sm tracking-wide transition-opacity hover:opacity-90"
|
||||
style={{ background: "var(--color-accent)", borderRadius: "6px" }}
|
||||
>
|
||||
创建班级
|
||||
</button>
|
||||
</form>
|
||||
</aside>
|
||||
</div>
|
||||
<div className="rule-thin mb-6" />
|
||||
|
||||
<section className="col-span-8">
|
||||
<div className="flex items-baseline justify-between mb-4">
|
||||
<h2 className="text-xl" style={{ fontFamily: "var(--font-serif)" }}>
|
||||
班级列表
|
||||
<span
|
||||
className="ml-2 text-sm font-sans"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
{classes.length} 个
|
||||
</span>
|
||||
</h2>
|
||||
<button
|
||||
onClick={fetchClasses}
|
||||
className="text-xs uppercase tracking-wide hover:opacity-70"
|
||||
style={{ color: "var(--color-accent)" }}
|
||||
>
|
||||
刷新
|
||||
</button>
|
||||
{result.fetching ? (
|
||||
<Loading lines={4} />
|
||||
) : result.error ? (
|
||||
<div className="mark-left mb-4 py-2 border-l-2 border-danger pl-md">
|
||||
<p className="text-sm px-3 text-danger">
|
||||
加载失败:{result.error.message}
|
||||
</p>
|
||||
</div>
|
||||
<div className="rule-thin mb-6" />
|
||||
|
||||
{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)" }}
|
||||
) : !result.data?.classes || result.data.classes.length === 0 ? (
|
||||
<Empty title="暂无班级" description="请联系管理员分配班级" />
|
||||
) : (
|
||||
<ul className="space-y-0">
|
||||
{(result.data.classes as Class[]).map((cls) => (
|
||||
<li
|
||||
key={cls.id}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-baseline border-b border-rule"
|
||||
>
|
||||
{error}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{loading ? (
|
||||
<p className="text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||
加载中...
|
||||
</p>
|
||||
) : classes.length === 0 ? (
|
||||
<p
|
||||
className="text-sm italic"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
暂无班级,从左侧创建第一个
|
||||
</p>
|
||||
) : (
|
||||
<ul className="space-y-0">
|
||||
{classes.map((cls) => (
|
||||
<li
|
||||
key={cls.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)",
|
||||
}}
|
||||
>
|
||||
{cls.name}
|
||||
</h3>
|
||||
{cls.description && (
|
||||
<p
|
||||
className="mt-1 text-sm"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
{cls.description}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className="col-span-3 text-xs font-mono"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
<div className="col-span-7">
|
||||
<h3 className="text-lg font-serif text-ink">{cls.name}</h3>
|
||||
<p className="mt-1 text-tiny text-ink-muted">
|
||||
年级:{cls.gradeId}
|
||||
</p>
|
||||
</div>
|
||||
<div className="col-span-2 text-sm text-ink-muted">
|
||||
{cls.studentCount} 名学生
|
||||
</div>
|
||||
<div className="col-span-3 text-right flex justify-end gap-4">
|
||||
<Link
|
||||
href={`/students?classId=${cls.id}`}
|
||||
className="text-tiny uppercase tracking-wide text-accent hover:opacity-70"
|
||||
>
|
||||
{cls.id.slice(0, 8)}...
|
||||
</div>
|
||||
<div className="col-span-2 text-right">
|
||||
<button
|
||||
onClick={() => handleDelete(cls.id)}
|
||||
className="text-xs uppercase tracking-wide hover:opacity-70"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
查看学生
|
||||
</Link>
|
||||
<Link
|
||||
href={`/exams?classId=${cls.id}`}
|
||||
className="text-tiny uppercase tracking-wide text-ink-muted hover:opacity-70"
|
||||
>
|
||||
考试
|
||||
</Link>
|
||||
<Link
|
||||
href={`/homework?classId=${cls.id}`}
|
||||
className="text-tiny uppercase tracking-wide text-ink-muted hover:opacity-70"
|
||||
>
|
||||
作业
|
||||
</Link>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,139 +1,146 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { getToken, getUser, type UserInfo } from "@/lib/auth";
|
||||
/**
|
||||
* Dashboard 页面 - 教师仪表盘
|
||||
*
|
||||
* 数据来源(ARB-001 §1.2):GraphQL DashboardQuery
|
||||
* - 并行聚合:iam.me + iam.viewports + iam.permissions + classes.byTeacher
|
||||
* - 返回:user + classes + viewports + stats
|
||||
*
|
||||
* 维护者:ai13(teacher-portal)
|
||||
*/
|
||||
|
||||
interface DashboardData {
|
||||
user: { success: boolean; data?: { user: UserInfo } };
|
||||
classes: { success: boolean; data?: unknown[] };
|
||||
}
|
||||
import { useQuery } from "urql";
|
||||
import Link from "next/link";
|
||||
import { Loading, Empty } from "@edu/ui-components";
|
||||
import { DashboardQuery } from "@/lib/graphql";
|
||||
import type { Class } from "@/lib/graphql";
|
||||
|
||||
export default function DashboardPage() {
|
||||
const [data, setData] = useState<DashboardData | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const user = getUser();
|
||||
const [result] = useQuery({ query: DashboardQuery });
|
||||
|
||||
useEffect(() => {
|
||||
const token = getToken();
|
||||
if (!token) return;
|
||||
(async () => {
|
||||
try {
|
||||
const res = await fetch("/api/v1/teacher/dashboard", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.success) {
|
||||
setData(json.data);
|
||||
} else {
|
||||
setError(json.error?.message || "加载失败");
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "网络错误");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
if (result.fetching) {
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<Loading lines={5} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const classesCount = Array.isArray(data?.classes?.data)
|
||||
? data!.classes.data.length
|
||||
: 0;
|
||||
if (result.error) {
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<header className="mb-8">
|
||||
<h1 className="text-3xl font-serif text-ink">欢迎</h1>
|
||||
</header>
|
||||
<div className="rule-thin mb-8" />
|
||||
<div className="mark-left py-2 mb-4 border-l-2 border-danger pl-md">
|
||||
<p className="text-sm px-3 text-danger">
|
||||
仪表盘加载失败:{result.error.message}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const data = result.data?.dashboard;
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<Empty title="暂无数据" description="仪表盘数据尚未就绪" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { user, classes, stats } = data;
|
||||
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<header className="mb-8">
|
||||
<h1
|
||||
className="text-3xl"
|
||||
style={{ fontFamily: "var(--font-serif)", color: "var(--color-ink)" }}
|
||||
>
|
||||
欢迎,{user?.name || "老师"}
|
||||
</h1>
|
||||
<p className="mt-1 text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||
{user?.email} · 角色:{user?.roles.join(", ") || "无"} · 数据范围:
|
||||
{user?.dataScope || "-"}
|
||||
<h1 className="text-3xl font-serif text-ink">欢迎,{user.name}</h1>
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
{user.email} · 角色:{user.roles.join(", ") || "无"} · 数据范围:
|
||||
{user.dataScope}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div className="rule-thin mb-8" />
|
||||
|
||||
{loading ? (
|
||||
<p className="text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||
加载中...
|
||||
</p>
|
||||
) : error ? (
|
||||
<div
|
||||
className="mark-left py-2 mb-4"
|
||||
style={{ borderColor: "var(--color-accent)" }}
|
||||
>
|
||||
<p className="text-sm px-3" style={{ color: "var(--color-accent)" }}>
|
||||
{error}
|
||||
{/* 统计卡片 */}
|
||||
<section className="grid grid-cols-3 gap-6 mb-10">
|
||||
<div className="p-6 border border-rule rounded-card">
|
||||
<p className="text-tiny uppercase tracking-wide text-ink-muted">
|
||||
班级总数
|
||||
</p>
|
||||
<p className="mt-3 text-4xl font-serif text-ink">{classes.length}</p>
|
||||
</div>
|
||||
<div className="p-6 border border-rule rounded-card">
|
||||
<p className="text-tiny uppercase tracking-wide text-ink-muted">
|
||||
考试总数
|
||||
</p>
|
||||
<p className="mt-3 text-4xl font-serif text-ink">
|
||||
{stats.totalExams}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<section className="grid grid-cols-3 gap-6">
|
||||
<div
|
||||
className="p-6 border"
|
||||
style={{ borderColor: "var(--color-rule)" }}
|
||||
<div className="p-6 border border-rule rounded-card">
|
||||
<p className="text-tiny uppercase tracking-wide text-ink-muted">
|
||||
待批改
|
||||
</p>
|
||||
<p className="mt-3 text-4xl font-serif text-accent">
|
||||
{stats.pendingGrading}
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 班级快览 */}
|
||||
<section>
|
||||
<div className="flex items-baseline justify-between mb-4">
|
||||
<h2 className="text-xl font-serif text-ink">
|
||||
我的班级
|
||||
<span className="ml-2 text-sm font-sans text-ink-muted">
|
||||
{classes.length} 个
|
||||
</span>
|
||||
</h2>
|
||||
<Link
|
||||
href="/classes"
|
||||
className="text-tiny uppercase tracking-wide text-accent hover:opacity-70"
|
||||
>
|
||||
<p
|
||||
className="text-xs uppercase tracking-wide"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
班级总数
|
||||
</p>
|
||||
<p
|
||||
className="mt-3 text-4xl"
|
||||
style={{
|
||||
fontFamily: "var(--font-serif)",
|
||||
color: "var(--color-ink)",
|
||||
}}
|
||||
>
|
||||
{classesCount}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
className="p-6 border"
|
||||
style={{ borderColor: "var(--color-rule)" }}
|
||||
>
|
||||
<p
|
||||
className="text-xs uppercase tracking-wide"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
权限点
|
||||
</p>
|
||||
<p
|
||||
className="mt-3 text-4xl"
|
||||
style={{
|
||||
fontFamily: "var(--font-serif)",
|
||||
color: "var(--color-ink)",
|
||||
}}
|
||||
>
|
||||
{user?.permissions.length ?? 0}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
className="p-6 border"
|
||||
style={{ borderColor: "var(--color-rule)" }}
|
||||
>
|
||||
<p
|
||||
className="text-xs uppercase tracking-wide"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
数据范围
|
||||
</p>
|
||||
<p
|
||||
className="mt-3 text-2xl"
|
||||
style={{
|
||||
fontFamily: "var(--font-serif)",
|
||||
color: "var(--color-ink)",
|
||||
}}
|
||||
>
|
||||
{user?.dataScope || "-"}
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
查看全部
|
||||
</Link>
|
||||
</div>
|
||||
<div className="rule-thin mb-6" />
|
||||
|
||||
{classes.length === 0 ? (
|
||||
<Empty title="暂无班级" description="请联系管理员分配班级" />
|
||||
) : (
|
||||
<ul className="space-y-0">
|
||||
{(classes as Class[]).slice(0, 5).map((cls) => (
|
||||
<li
|
||||
key={cls.id}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-baseline border-b border-rule"
|
||||
>
|
||||
<div className="col-span-8">
|
||||
<h3 className="text-lg font-serif text-ink">{cls.name}</h3>
|
||||
<p className="mt-1 text-tiny text-ink-muted">
|
||||
年级:{cls.gradeId}
|
||||
</p>
|
||||
</div>
|
||||
<div className="col-span-2 text-sm text-ink-muted">
|
||||
{cls.studentCount} 名学生
|
||||
</div>
|
||||
<div className="col-span-2 text-right">
|
||||
<Link
|
||||
href={`/students?classId=${cls.id}`}
|
||||
className="text-tiny uppercase tracking-wide text-accent hover:opacity-70"
|
||||
>
|
||||
查看学生
|
||||
</Link>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,179 +1,96 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { getToken } from "@/lib/auth";
|
||||
/**
|
||||
* Exams 页面 - 考试管理
|
||||
*
|
||||
* 数据来源(contract.md §2.4):GraphQL ClassExamsQuery(P3 扩展,MSW mock)
|
||||
* - 通过 URL ?classId=xxx 指定班级
|
||||
* - P2 阶段用 MSW mock 数据,待 teacher-bff P3 启用 core-edu 聚合
|
||||
*
|
||||
* 维护者:ai13(teacher-portal)
|
||||
*/
|
||||
|
||||
interface ExamItem {
|
||||
id: string;
|
||||
classId: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
examDate: string;
|
||||
duration: string;
|
||||
totalScore: string;
|
||||
status: string;
|
||||
createdBy: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
import { useQuery } from "urql";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { Suspense } from "react";
|
||||
import { Loading, Empty } from "@edu/ui-components";
|
||||
import { ClassExamsQuery, ClassQuery } from "@/lib/graphql";
|
||||
import type { ExamItem } from "@/lib/graphql";
|
||||
|
||||
interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: { code: string; message: string };
|
||||
}
|
||||
function ExamsContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const classId = searchParams.get("classId") ?? "";
|
||||
|
||||
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 [classResult] = useQuery({
|
||||
query: ClassQuery,
|
||||
variables: { id: classId },
|
||||
pause: !classId,
|
||||
});
|
||||
|
||||
const authHeaders = (): Record<string, string> => {
|
||||
const token = getToken();
|
||||
return token ? { Authorization: `Bearer ${token}` } : {};
|
||||
};
|
||||
const [examsResult] = useQuery({
|
||||
query: ClassExamsQuery,
|
||||
variables: { classId },
|
||||
pause: !classId,
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}, [classId]);
|
||||
if (!classId) {
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<Empty title="未指定班级" description="请从班级列表进入查看考试" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchExams();
|
||||
}, [fetchExams]);
|
||||
const cls = classResult.data?.class;
|
||||
const exams = examsResult.data?.classExams ?? [];
|
||||
|
||||
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 className="text-3xl font-serif text-ink">
|
||||
{cls ? `${cls.name} - 考试管理` : "考试管理"}
|
||||
</h1>
|
||||
<p className="mt-1 text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||
core-edu 域 · BFF 聚合查询
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
GraphQL ClassExamsQuery · core-edu 域(P3 扩展,MSW mock)
|
||||
</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}
|
||||
{examsResult.fetching ? (
|
||||
<Loading lines={4} />
|
||||
) : examsResult.error ? (
|
||||
<div className="mark-left mb-4 py-2 border-l-2 border-danger pl-md">
|
||||
<p className="text-sm px-3 text-danger">
|
||||
加载失败:{examsResult.error.message}
|
||||
</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>
|
||||
<Empty title="暂无考试" description="该班级尚未创建考试" />
|
||||
) : (
|
||||
<ul className="space-y-0">
|
||||
{exams.map((exam) => (
|
||||
{(exams as ExamItem[]).map((exam) => (
|
||||
<li
|
||||
key={exam.id}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-baseline"
|
||||
style={{ borderBottom: "1px solid var(--color-rule)" }}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-baseline border-b border-rule"
|
||||
>
|
||||
<div className="col-span-7">
|
||||
<h3
|
||||
className="text-lg"
|
||||
style={{
|
||||
fontFamily: "var(--font-serif)",
|
||||
color: "var(--color-ink)",
|
||||
}}
|
||||
>
|
||||
{exam.title}
|
||||
</h3>
|
||||
<h3 className="text-lg font-serif text-ink">{exam.title}</h3>
|
||||
{exam.description && (
|
||||
<p
|
||||
className="mt-1 text-sm"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
{exam.description}
|
||||
</p>
|
||||
)}
|
||||
<p
|
||||
className="mt-1 text-xs"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<p className="mt-1 text-tiny text-ink-muted">
|
||||
考试时间: {new Date(exam.examDate).toLocaleString("zh-CN")}
|
||||
{" · "}
|
||||
时长 {exam.duration} 分钟
|
||||
{" · "}
|
||||
满分 {exam.totalScore}
|
||||
{" · "}时长 {exam.duration} 分钟
|
||||
{" · "}满分 {exam.totalScore}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
className="col-span-3 text-xs"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<div className="col-span-3 text-tiny text-ink-muted">
|
||||
状态: {exam.status}
|
||||
</div>
|
||||
<div
|
||||
className="col-span-2 text-right text-xs font-mono"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<div className="col-span-2 text-right text-tiny font-mono text-ink-muted">
|
||||
{exam.id.slice(0, 8)}...
|
||||
</div>
|
||||
</li>
|
||||
@@ -183,3 +100,17 @@ export default function ExamsPage() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ExamsPage() {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="px-10 py-10">
|
||||
<Loading lines={3} />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<ExamsContent />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,174 +1,96 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { getToken } from "@/lib/auth";
|
||||
/**
|
||||
* Grades 页面 - 成绩查询
|
||||
*
|
||||
* 数据来源(contract.md §2.4):GraphQL ExamGradesQuery(P3 扩展,MSW mock)
|
||||
* - 通过 URL ?examId=xxx 指定考试
|
||||
* - P2 阶段用 MSW mock 数据,待 teacher-bff P3 启用 core-edu 聚合
|
||||
*
|
||||
* 维护者:ai13(teacher-portal)
|
||||
*/
|
||||
|
||||
interface GradeItem {
|
||||
id: string;
|
||||
studentId: string;
|
||||
examId: string | null;
|
||||
homeworkId: string | null;
|
||||
score: string;
|
||||
feedback?: string;
|
||||
gradedBy: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
import { useState, Suspense } from "react";
|
||||
import { useQuery } from "urql";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { Loading, Empty } from "@edu/ui-components";
|
||||
import { ExamGradesQuery } from "@/lib/graphql";
|
||||
import type { GradeItem } from "@/lib/graphql";
|
||||
|
||||
interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: { code: string; message: string };
|
||||
}
|
||||
function GradesContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const initialExamId = searchParams.get("examId") ?? "";
|
||||
const [examId, setExamId] = useState(initialExamId);
|
||||
|
||||
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 [gradesResult] = useQuery({
|
||||
query: ExamGradesQuery,
|
||||
variables: { examId },
|
||||
pause: !examId,
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}, [examId]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchGrades();
|
||||
}, [fetchGrades]);
|
||||
const grades = gradesResult.data?.examGrades ?? [];
|
||||
|
||||
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 聚合查询
|
||||
<h1 className="text-3xl font-serif text-ink">成绩查询</h1>
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
GraphQL ExamGradesQuery · core-edu 域(P3 扩展,MSW mock)
|
||||
</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)" }}
|
||||
>
|
||||
<label className="text-tiny uppercase tracking-wide text-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)" }}
|
||||
className="flex-1 max-w-md px-3 py-2 bg-transparent border-b border-rule text-sm font-mono"
|
||||
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}
|
||||
{gradesResult.fetching ? (
|
||||
<Loading lines={4} />
|
||||
) : gradesResult.error ? (
|
||||
<div className="mark-left mb-4 py-2 border-l-2 border-danger pl-md">
|
||||
<p className="text-sm px-3 text-danger">
|
||||
加载失败:{gradesResult.error.message}
|
||||
</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>
|
||||
) : !examId ? (
|
||||
<Empty title="请输入考试 ID" description="输入考试 UUID 后查询成绩" />
|
||||
) : grades.length === 0 ? (
|
||||
<Empty title="暂无成绩" description="该考试尚未录入成绩" />
|
||||
) : (
|
||||
<ul className="space-y-0">
|
||||
{items.map((g) => (
|
||||
{(grades as GradeItem[]).map((g) => (
|
||||
<li
|
||||
key={g.id}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-baseline"
|
||||
style={{ borderBottom: "1px solid var(--color-rule)" }}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-baseline border-b border-rule"
|
||||
>
|
||||
<div className="col-span-6">
|
||||
<h3
|
||||
className="text-lg"
|
||||
style={{
|
||||
fontFamily: "var(--font-serif)",
|
||||
color: "var(--color-ink)",
|
||||
}}
|
||||
>
|
||||
学生: {g.studentId}
|
||||
</h3>
|
||||
<h3 className="text-lg font-serif text-ink">{g.studentName}</h3>
|
||||
<p className="mt-1 text-tiny text-ink-muted">
|
||||
学生 ID: {g.studentId}
|
||||
</p>
|
||||
{g.feedback && (
|
||||
<p
|
||||
className="mt-1 text-sm"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
反馈: {g.feedback}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className="col-span-2 text-2xl"
|
||||
style={{
|
||||
fontFamily: "var(--font-serif)",
|
||||
color: "var(--color-accent)",
|
||||
}}
|
||||
>
|
||||
<div className="col-span-2 text-2xl font-serif text-accent">
|
||||
{g.score}
|
||||
</div>
|
||||
<div
|
||||
className="col-span-2 text-xs"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
评分人: {g.gradedBy}
|
||||
<div className="col-span-2 text-tiny text-ink-muted">
|
||||
{g.examId ? `考试: ${g.examId.slice(0, 8)}...` : "作业成绩"}
|
||||
</div>
|
||||
<div
|
||||
className="col-span-2 text-right text-xs font-mono"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<div className="col-span-2 text-right text-tiny font-mono text-ink-muted">
|
||||
{g.id.slice(0, 8)}...
|
||||
</div>
|
||||
</li>
|
||||
@@ -178,3 +100,17 @@ export default function GradesPage() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function GradesPage() {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="px-10 py-10">
|
||||
<Loading lines={3} />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<GradesContent />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,173 +1,94 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { getToken } from "@/lib/auth";
|
||||
/**
|
||||
* Homework 页面 - 作业管理
|
||||
*
|
||||
* 数据来源(contract.md §2.4):GraphQL ClassHomeworkQuery(P3 扩展,MSW mock)
|
||||
* - 通过 URL ?classId=xxx 指定班级
|
||||
* - P2 阶段用 MSW mock 数据,待 teacher-bff P3 启用 core-edu 聚合
|
||||
*
|
||||
* 维护者:ai13(teacher-portal)
|
||||
*/
|
||||
|
||||
interface HomeworkItem {
|
||||
id: string;
|
||||
classId: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
dueDate: string;
|
||||
status: string;
|
||||
createdBy: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
import { useQuery } from "urql";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { Suspense } from "react";
|
||||
import { Loading, Empty } from "@edu/ui-components";
|
||||
import { ClassHomeworkQuery, ClassQuery } from "@/lib/graphql";
|
||||
import type { HomeworkItem } from "@/lib/graphql";
|
||||
|
||||
interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: { code: string; message: string };
|
||||
}
|
||||
function HomeworkContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const classId = searchParams.get("classId") ?? "";
|
||||
|
||||
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 [classResult] = useQuery({
|
||||
query: ClassQuery,
|
||||
variables: { id: classId },
|
||||
pause: !classId,
|
||||
});
|
||||
|
||||
const authHeaders = (): Record<string, string> => {
|
||||
const token = getToken();
|
||||
return token ? { Authorization: `Bearer ${token}` } : {};
|
||||
};
|
||||
const [homeworkResult] = useQuery({
|
||||
query: ClassHomeworkQuery,
|
||||
variables: { classId },
|
||||
pause: !classId,
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}, [classId]);
|
||||
if (!classId) {
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<Empty title="未指定班级" description="请从班级列表进入查看作业" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchHomework();
|
||||
}, [fetchHomework]);
|
||||
const cls = classResult.data?.class;
|
||||
const items = homeworkResult.data?.classHomework ?? [];
|
||||
|
||||
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 className="text-3xl font-serif text-ink">
|
||||
{cls ? `${cls.name} - 作业管理` : "作业管理"}
|
||||
</h1>
|
||||
<p className="mt-1 text-sm" style={{ color: "var(--color-ink-muted)" }}>
|
||||
core-edu 域 · BFF 聚合查询
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
GraphQL ClassHomeworkQuery · core-edu 域(P3 扩展,MSW mock)
|
||||
</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}
|
||||
{homeworkResult.fetching ? (
|
||||
<Loading lines={4} />
|
||||
) : homeworkResult.error ? (
|
||||
<div className="mark-left mb-4 py-2 border-l-2 border-danger pl-md">
|
||||
<p className="text-sm px-3 text-danger">
|
||||
加载失败:{homeworkResult.error.message}
|
||||
</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>
|
||||
<Empty title="暂无作业" description="该班级尚未布置作业" />
|
||||
) : (
|
||||
<ul className="space-y-0">
|
||||
{items.map((hw) => (
|
||||
{(items as HomeworkItem[]).map((hw) => (
|
||||
<li
|
||||
key={hw.id}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-baseline"
|
||||
style={{ borderBottom: "1px solid var(--color-rule)" }}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-baseline border-b border-rule"
|
||||
>
|
||||
<div className="col-span-7">
|
||||
<h3
|
||||
className="text-lg"
|
||||
style={{
|
||||
fontFamily: "var(--font-serif)",
|
||||
color: "var(--color-ink)",
|
||||
}}
|
||||
>
|
||||
{hw.title}
|
||||
</h3>
|
||||
<h3 className="text-lg font-serif text-ink">{hw.title}</h3>
|
||||
{hw.description && (
|
||||
<p
|
||||
className="mt-1 text-sm"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
{hw.description}
|
||||
</p>
|
||||
)}
|
||||
<p
|
||||
className="mt-1 text-xs"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<p className="mt-1 text-tiny text-ink-muted">
|
||||
截止: {new Date(hw.dueDate).toLocaleString("zh-CN")}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
className="col-span-3 text-xs"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<div className="col-span-3 text-tiny text-ink-muted">
|
||||
状态: {hw.status}
|
||||
</div>
|
||||
<div
|
||||
className="col-span-2 text-right text-xs font-mono"
|
||||
style={{ color: "var(--color-ink-muted)" }}
|
||||
>
|
||||
<div className="col-span-2 text-right text-tiny font-mono text-ink-muted">
|
||||
{hw.id.slice(0, 8)}...
|
||||
</div>
|
||||
</li>
|
||||
@@ -177,3 +98,17 @@ export default function HomeworkPage() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function HomeworkPage() {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="px-10 py-10">
|
||||
<Loading lines={3} />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<HomeworkContent />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
99
apps/teacher-portal/src/app/(app)/settings/page.tsx
Normal file
99
apps/teacher-portal/src/app/(app)/settings/page.tsx
Normal file
@@ -0,0 +1,99 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Settings 页面 - 个人设置
|
||||
*
|
||||
* 数据来源(ARB-001 §1.2):GraphQL MeQuery(只读展示)
|
||||
* - P2 阶段仅展示当前用户信息(P2 纯读,无 Mutation)
|
||||
* - P3+ 启用 UpdateUserMutation 后开启编辑功能
|
||||
*
|
||||
* 维护者:ai13(teacher-portal)
|
||||
*/
|
||||
|
||||
import { useQuery } from "urql";
|
||||
import { Loading } from "@edu/ui-components";
|
||||
import { MeQuery } from "@/lib/graphql";
|
||||
|
||||
export default function SettingsPage() {
|
||||
const [result] = useQuery({ query: MeQuery });
|
||||
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<header className="mb-8">
|
||||
<h1 className="text-3xl font-serif text-ink">个人设置</h1>
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
GraphQL MeQuery · P2 只读展示(P3 启用编辑)
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div className="rule-thin mb-8" />
|
||||
|
||||
{result.fetching ? (
|
||||
<Loading lines={4} />
|
||||
) : result.error ? (
|
||||
<div className="mark-left mb-4 py-2 border-l-2 border-danger pl-md">
|
||||
<p className="text-sm px-3 text-danger">
|
||||
加载失败:{result.error.message}
|
||||
</p>
|
||||
</div>
|
||||
) : !result.data?.me ? (
|
||||
<p className="text-sm italic text-ink-muted">暂无用户信息</p>
|
||||
) : (
|
||||
<section className="max-w-2xl">
|
||||
<div className="mb-6">
|
||||
<h2 className="text-xl font-serif text-ink mb-2">基本信息</h2>
|
||||
<div className="rule-thin mb-4" />
|
||||
<dl className="space-y-4">
|
||||
<div className="grid grid-cols-3 gap-4 items-baseline">
|
||||
<dt className="text-tiny uppercase tracking-wide text-ink-muted">
|
||||
用户 ID
|
||||
</dt>
|
||||
<dd className="col-span-2 text-sm font-mono text-ink">
|
||||
{result.data.me.id}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4 items-baseline">
|
||||
<dt className="text-tiny uppercase tracking-wide text-ink-muted">
|
||||
姓名
|
||||
</dt>
|
||||
<dd className="col-span-2 text-sm text-ink">
|
||||
{result.data.me.name}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4 items-baseline">
|
||||
<dt className="text-tiny uppercase tracking-wide text-ink-muted">
|
||||
邮箱
|
||||
</dt>
|
||||
<dd className="col-span-2 text-sm text-ink">
|
||||
{result.data.me.email}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4 items-baseline">
|
||||
<dt className="text-tiny uppercase tracking-wide text-ink-muted">
|
||||
角色
|
||||
</dt>
|
||||
<dd className="col-span-2 text-sm text-ink">
|
||||
{result.data.me.roles.join(", ") || "无角色"}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4 items-baseline">
|
||||
<dt className="text-tiny uppercase tracking-wide text-ink-muted">
|
||||
数据范围
|
||||
</dt>
|
||||
<dd className="col-span-2 text-sm text-ink">
|
||||
{result.data.me.dataScope}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div className="mt-8 p-4 border border-rule rounded-card bg-subtle">
|
||||
<p className="text-sm text-ink-muted">
|
||||
P2 阶段为只读模式,编辑功能(updateUser Mutation)将在 P3 启用。
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
109
apps/teacher-portal/src/app/(app)/students/page.tsx
Normal file
109
apps/teacher-portal/src/app/(app)/students/page.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Students 页面 - 班级学生名单
|
||||
*
|
||||
* 数据来源(contract.md §2.4):GraphQL ClassStudentsQuery(P3 扩展,MSW mock)
|
||||
* - 通过 URL ?classId=xxx 指定班级
|
||||
* - P2 阶段用 MSW mock 数据,待 teacher-bff P3 启用 iam 聚合
|
||||
*
|
||||
* 维护者:ai13(teacher-portal)
|
||||
*/
|
||||
|
||||
import { useQuery } from "urql";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { Suspense } from "react";
|
||||
import { Loading, Empty } from "@edu/ui-components";
|
||||
import { ClassStudentsQuery, ClassQuery } from "@/lib/graphql";
|
||||
import type { Student } from "@/lib/graphql";
|
||||
|
||||
function StudentsContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const classId = searchParams.get("classId") ?? "";
|
||||
|
||||
// 班级详情(用于显示班级名称)
|
||||
const [classResult] = useQuery({
|
||||
query: ClassQuery,
|
||||
variables: { id: classId },
|
||||
pause: !classId,
|
||||
});
|
||||
|
||||
// 学生名单
|
||||
const [studentsResult] = useQuery({
|
||||
query: ClassStudentsQuery,
|
||||
variables: { classId },
|
||||
pause: !classId,
|
||||
});
|
||||
|
||||
if (!classId) {
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<Empty title="未指定班级" description="请从班级列表进入查看学生名单" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const cls = classResult.data?.class;
|
||||
const students = studentsResult.data?.classStudents ?? [];
|
||||
|
||||
return (
|
||||
<div className="px-10 py-10">
|
||||
<header className="mb-8">
|
||||
<h1 className="text-3xl font-serif text-ink">
|
||||
{cls ? `${cls.name} - 学生名单` : "学生名单"}
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-ink-muted">
|
||||
GraphQL ClassStudentsQuery · iam 数据聚合(P3 扩展,MSW mock)
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div className="rule-thin mb-8" />
|
||||
|
||||
{studentsResult.fetching ? (
|
||||
<Loading lines={6} />
|
||||
) : studentsResult.error ? (
|
||||
<div className="mark-left mb-4 py-2 border-l-2 border-danger pl-md">
|
||||
<p className="text-sm px-3 text-danger">
|
||||
加载失败:{studentsResult.error.message}
|
||||
</p>
|
||||
</div>
|
||||
) : students.length === 0 ? (
|
||||
<Empty title="暂无学生" description="该班级尚未录入学生信息" />
|
||||
) : (
|
||||
<ul className="space-y-0">
|
||||
{(students as Student[]).map((s) => (
|
||||
<li
|
||||
key={s.id}
|
||||
className="py-4 grid grid-cols-12 gap-4 items-center border-b border-rule"
|
||||
>
|
||||
<div className="col-span-5">
|
||||
<h3 className="text-lg font-serif text-ink">{s.name}</h3>
|
||||
<p className="mt-1 text-tiny text-ink-muted">{s.email}</p>
|
||||
</div>
|
||||
<div className="col-span-5 text-sm text-ink-muted">
|
||||
ID: {s.id}
|
||||
</div>
|
||||
<div className="col-span-2 text-right text-tiny font-mono text-ink-muted">
|
||||
{s.id.slice(0, 8)}...
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function StudentsPage() {
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="px-10 py-10">
|
||||
<Loading lines={3} />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<StudentsContent />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user