feat(teachers,classes,schedules,web): 教师录入(仅管理员)+ 班主任可设置/更改 + 授课科目全校统一 + 登录页去示例
① 支持录入教师(与学生录入对齐),权限只有管理员
- 新增 Web「教师管理」页(`Views/TeachersView.vue`):单个录入(姓名/用户名/初始密码/角色)、
导入名单(xlsx/csv:用户名、姓名、初始密码、角色)、编辑(改名/改角色)、重置密码、删除
- 服务端 `teachers` 模块补齐:GET / POST / PATCH /:id / POST /:id/reset-password / DELETE /:id,
全部 `requireRole('ADMIN')`;表格导入新增 kind=teachers(`IMPORT_FIELDS.teachers`、`commitTeachers`、
教师名单模板),教师调用预览/提交一律 403
- 删除护栏:还是班主任(`Class.teacherId`)或持有课程/班级分配的账号拒绝删除(409,提示先更换班主任)——
教师是数据创建者,级联删除会连带删掉班级数据
- 前端路由加 `meta.roles`:`/classes`、`/students`、`/teachers` 仅 ADMIN,教师直接输网址会被挡回仪表盘
(菜单隐藏只是"看不见",这次补上真正的守卫);新增环境变量 `DEFAULT_TEACHER_PASSWORD`
② 创建班级仅管理员 + 设置 / 更改班主任
- 新建班级时可直接指定班主任(不填则创建者本人),班级详情顶部「更换班主任」下拉随时改:
新增 `PATCH /api/classes/:id/head-teacher`(仅管理员,校验目标账号是教师/管理员,广播 class:updated)
- 原班主任保留在协作教师名单里,避免换人后丢掉历史协作关系
③ 授课科目全校统一(用户澄清:"统一"指的是授课科目固定,不是各班课表相同)
- `SUBJECT_CATALOG` 改为用户给定的 18 科:语文/数学/英语/政治/历史/物理/化学/地理/生物/信息技术/
体育/美术/音乐/班会/早读/晚读/通用技术/听力
- 课表「新增课表」与成绩「单条/批量录入」的科目下拉直接列出统一目录(该班还没有的进
「统一科目(选中后自动建课)」分组),选中后自动为该班建同名课程再落库 —— 不必按班级一个个录科目
- 各班课表仍然各自独立(各班的课表本来就不一样)
④ 登录页去掉所有示例内容
- Web 登录页删除「演示账号(点击填充)」标签列表与"种子数据见 README"提示;客户端班级码占位符
由「例如 G101(由老师在班级管理中提供)」改为「请输入班级码」
- `verify:web` 与 `verify:desktop` 各自断言登录页正文/占位符不含 `演示/示例/admin123/teacher123/G101`
⑤ 验证脚本不再依赖演示数据(并修掉自身残留)
- 清空服务端作业/通知后,联网自检改为**自建**一条作业/通知并在收尾删除(`seedSmokeContent`);
权限用例需要"其它教师的班级/科任班级"时现建临时班级并在收尾删除
- e2e 新增清理:实时推送用例造的通知/作业、上课时段用例造的两条通知、教师名单/临时班级
(此前这几条会留在库里);班级详情相关断言不再依赖种子班级布局
- ui-smoke 新增 7 项:登录页无示例、教师端访问 /teachers 被挡回、统一科目下拉 + 自动建课 + 收尾删除
课表与课程、管理员真人录入教师 → 列表出现 → 删除
- 冒烟里"岛就绪"与"截图留档"改为轮询等待(偶发丢一张留档图会误判"形态尺寸递增")
实测:verify:e2e 163/163(安装实例)、verify:web 27/27、verify:desktop 77/77(离线复跑 69/69)、
verify:packaged 对 release/win-unpacked 与 D:\class\@classhelperdesktop-client 均 77/77 且 packaged=true;
typecheck / lint / format:check 全绿。服务端安装实例与客户端安装目录已就地更新。
This commit is contained in:
1 parent
0ff2dc228b
commit
845fbdd863
27 files changed
+1655
-200
No files matched your search
+110
-3
@@ -123,6 +123,93 @@ export async function layoutNavigationSelfTest(): Promise<SmokeCheckResult> {
|
||||
};
|
||||
}
|
||||
|
||||
/** 自检临时造的作业/通知(收尾必须删掉,避免污染用户的库) */
|
||||
let temporaryContent: { token: string; homeworks: string[]; notifications: string[] } | null = null;
|
||||
|
||||
/**
|
||||
* 服务端业务数据可能被管理员清空(用户明确要求过"删掉所有作业和通知"),
|
||||
* 因此联网自检在列表为空时**自建**一条作业/通知来验证链路,收尾(sessionCleanup)删除。
|
||||
*/
|
||||
async function seedSmokeContent(
|
||||
classId: string | null,
|
||||
need: { homework: boolean; notification: boolean },
|
||||
): Promise<SmokeCheckResult> {
|
||||
if (!classId) return { ok: false, detail: '缺少班级,无法自建数据' };
|
||||
const serverUrl = 'http://127.0.0.1:4000';
|
||||
const stamp = `自检 ${new Date().toLocaleTimeString('zh-CN')}`;
|
||||
|
||||
try {
|
||||
const login = await fetch(`${serverUrl}/api/auth/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ username: 'teacher1', password: 'teacher123' }),
|
||||
}).then((response) => response.json());
|
||||
const token: string | undefined = login?.data?.token;
|
||||
if (!token) return { ok: false, detail: `教师登录失败:${JSON.stringify(login).slice(0, 120)}` };
|
||||
|
||||
const homeworks: string[] = [];
|
||||
const notifications: string[] = [];
|
||||
|
||||
if (need.homework) {
|
||||
const created = await fetch(`${serverUrl}/api/homeworks`, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json', authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({
|
||||
classId,
|
||||
courseId: null,
|
||||
title: `自动化验证作业 ${stamp}`,
|
||||
content: '服务端没有作业数据时由冒烟自检临时创建,验证结束后立即删除,不会留在库里。',
|
||||
}),
|
||||
}).then((response) => response.json());
|
||||
const id: string | undefined = created?.data?.id;
|
||||
if (!id) return { ok: false, detail: `自建作业失败:${JSON.stringify(created).slice(0, 160)}` };
|
||||
homeworks.push(id);
|
||||
}
|
||||
|
||||
if (need.notification) {
|
||||
const created = await fetch(`${serverUrl}/api/notifications`, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json', authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({
|
||||
classId,
|
||||
title: `自动化验证通知 ${stamp}`,
|
||||
content: '服务端没有通知数据时由冒烟自检临时创建,验证结束后立即删除,不会留在库里。',
|
||||
priority: 'NORMAL',
|
||||
}),
|
||||
}).then((response) => response.json());
|
||||
const id: string | undefined = created?.data?.id;
|
||||
if (!id) return { ok: false, detail: `自建通知失败:${JSON.stringify(created).slice(0, 160)}` };
|
||||
notifications.push(id);
|
||||
}
|
||||
|
||||
temporaryContent = { token, homeworks, notifications };
|
||||
return { ok: true, detail: `作业+${homeworks.length} 通知+${notifications.length}` };
|
||||
} catch (error) {
|
||||
return { ok: false, detail: `自建数据异常:${error instanceof Error ? error.message : String(error)}` };
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除自检临时造的作业/通知 */
|
||||
async function cleanupTemporaryContent(): Promise<string> {
|
||||
if (!temporaryContent) return '';
|
||||
const { token, homeworks, notifications } = temporaryContent;
|
||||
temporaryContent = null;
|
||||
const serverUrl = 'http://127.0.0.1:4000';
|
||||
const removals = [
|
||||
...homeworks.map((id) => `/api/homeworks/${id}`),
|
||||
...notifications.map((id) => `/api/notifications/${id}`),
|
||||
];
|
||||
let failed = 0;
|
||||
for (const path of removals) {
|
||||
const response = await fetch(`${serverUrl}${path}`, {
|
||||
method: 'DELETE',
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
}).catch(() => null);
|
||||
if (!response?.ok) failed += 1;
|
||||
}
|
||||
return `自检临时数据已清理 ${removals.length - failed}/${removals.length} 条`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 冒烟自检 4(需后端在线):真实登录 + 拉取四类数据 + Socket.IO 连接。
|
||||
* 覆盖渲染进程里实际使用的 API 封装、JWT 注入、实时通道与缓存写入。
|
||||
@@ -165,12 +252,31 @@ export async function onlineScenario(credentials?: {
|
||||
await appStore.init(serverUrl);
|
||||
detail.push(`reachable=${appStore.serverReachable}`);
|
||||
|
||||
const [classes, homeworks, notifications, grades] = await Promise.all([
|
||||
const [classes, initialHomeworks, initialNotifications, grades] = await Promise.all([
|
||||
api.classApi.list(),
|
||||
api.homeworkApi.list(),
|
||||
api.notificationApi.list(),
|
||||
api.gradeApi.my(),
|
||||
]);
|
||||
|
||||
/**
|
||||
* 自检**不允许依赖演示种子数据**:管理员随时可能清空业务数据
|
||||
* (例如"删掉服务端所有作业和通知"),此时这几条联网断言不能变成"数据被清空就失败"。
|
||||
* 因此列表为空时用教师账号造一条**本次自检专用**的作业/通知,收尾在 sessionCleanup 里删除。
|
||||
*/
|
||||
let homeworks = initialHomeworks;
|
||||
let notifications = initialNotifications;
|
||||
if (homeworks.length === 0 || notifications.length === 0) {
|
||||
const seeded = await seedSmokeContent(auth.classId ?? null, {
|
||||
homework: homeworks.length === 0,
|
||||
notification: notifications.length === 0,
|
||||
});
|
||||
detail.push(`自建数据(${seeded.detail})`);
|
||||
if (seeded.ok) {
|
||||
[homeworks, notifications] = await Promise.all([api.homeworkApi.list(), api.notificationApi.list()]);
|
||||
}
|
||||
}
|
||||
|
||||
const term = await api.dashboardApi.term();
|
||||
const schedules = await api.scheduleApi.list({ week: term.currentWeek });
|
||||
|
||||
@@ -582,16 +688,17 @@ export async function homeworkBoardSelfTest(): Promise<SmokeCheckResult> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 冒烟收尾:断开实时通道并退出登录,保证下次冒烟从登录页开始 */
|
||||
/** 冒烟收尾:删除自检临时数据 → 断开实时通道 → 退出登录,保证下次冒烟从登录页开始 */
|
||||
export async function sessionCleanup(): Promise<SmokeCheckResult> {
|
||||
const [{ useAuthStore }, { useRealtimeStore }] = await Promise.all([
|
||||
import('../stores/auth.js'),
|
||||
import('../stores/realtime.js'),
|
||||
]);
|
||||
try {
|
||||
const cleaned = await cleanupTemporaryContent();
|
||||
useRealtimeStore().disconnect();
|
||||
await useAuthStore().logout();
|
||||
return { ok: true, detail: '已断开实时通道并清理登录态' };
|
||||
return { ok: true, detail: `已断开实时通道并清理登录态${cleaned ? `;${cleaned}` : ''}` };
|
||||
} catch (error) {
|
||||
return { ok: false, detail: error instanceof Error ? error.message : String(error) };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user