① 支持录入教师(与学生录入对齐),权限只有管理员
- 新增 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 全绿。服务端安装实例与客户端安装目录已就地更新。
431 lines
14 KiB
Vue
431 lines
14 KiB
Vue
<script setup lang="ts">
|
||
import { computed, reactive, ref, watch } from 'vue';
|
||
import { useRoute, useRouter } from 'vue-router';
|
||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus';
|
||
import { authApi } from '@/api';
|
||
import { useAuthStore } from '@/stores/auth';
|
||
import { useRealtimeStore } from '@/stores/realtime';
|
||
import { useResponsive } from '@/composables/useResponsive';
|
||
import { APP_TITLE } from '@/config';
|
||
|
||
const route = useRoute();
|
||
const router = useRouter();
|
||
const auth = useAuthStore();
|
||
const realtime = useRealtimeStore();
|
||
const { isMobile } = useResponsive();
|
||
|
||
/**
|
||
* 菜单项与可见角色(与后端 `@classhelper/shared/permissions` 矩阵保持一致):
|
||
* - 班级管理 / 学生管理 / 教师管理:仅管理员(班主任与科任老师都没有班级增删改与人员分配权限)
|
||
* - 课表管理:管理员 + 班主任(页面内再按"是否本班班主任"控制增删改按钮)
|
||
* - 成绩录入:管理员 + 教师;页面内只对"管理员或所选班级的班主任"显示写入/导入按钮
|
||
* (需求 6:成绩与表格导入老师端可用且不越权;科任老师只能看,写入会被后端 403)
|
||
* - 作业 / 通知:所有教师
|
||
*/
|
||
const menuItems = [
|
||
{ path: '/dashboard', title: '仪表盘', icon: 'Odometer', roles: ['ADMIN', 'TEACHER'] },
|
||
{ path: '/classes', title: '班级管理', icon: 'School', roles: ['ADMIN'] },
|
||
{ path: '/students', title: '学生管理', icon: 'User', roles: ['ADMIN'] },
|
||
{ path: '/teachers', title: '教师管理', icon: 'UserFilled', roles: ['ADMIN'] },
|
||
{ path: '/schedules', title: '课表管理', icon: 'Calendar', roles: ['ADMIN', 'TEACHER'] },
|
||
{ path: '/homeworks', title: '作业发布', icon: 'Notebook', roles: ['ADMIN', 'TEACHER'] },
|
||
{ path: '/notifications', title: '通知发布', icon: 'Bell', roles: ['ADMIN', 'TEACHER'] },
|
||
{ path: '/grades', title: '成绩录入', icon: 'Trophy', roles: ['ADMIN', 'TEACHER'] },
|
||
];
|
||
|
||
/** 当前账号可见的菜单(班级/学生管理仅管理员可见) */
|
||
const visibleMenuItems = computed(() =>
|
||
menuItems.filter((item) => (auth.role ? item.roles.includes(auth.role) : false)),
|
||
);
|
||
|
||
/** 高亮当前菜单:直接比较路由路径,避免依赖路由名 */
|
||
const activeMenu = computed(() => route.path);
|
||
|
||
/** 顶栏显示的当前页面标题(小屏下替代侧边栏的"我在哪"提示,1Panel 同款做法) */
|
||
const currentTitle = computed(() => menuItems.find((item) => item.path === route.path)?.title ?? APP_TITLE);
|
||
|
||
/** 小屏:侧边栏收进抽屉,由顶栏汉堡按钮唤出 */
|
||
const drawerVisible = ref(false);
|
||
|
||
watch(
|
||
() => route.path,
|
||
() => {
|
||
drawerVisible.value = false;
|
||
},
|
||
);
|
||
|
||
watch(isMobile, (mobile) => {
|
||
if (!mobile) drawerVisible.value = false;
|
||
});
|
||
|
||
/**
|
||
* 菜单点击回调。
|
||
* 注意:el-menu 的 @select 抛出的是 el-menu-item 的 index(这里即路由路径),
|
||
* 不能当作路由名使用(router.push({ name }) 会因找不到同名路由而静默失败)。
|
||
*/
|
||
function handleMenuSelect(index: string): void {
|
||
void router.push(index);
|
||
drawerVisible.value = false;
|
||
}
|
||
|
||
/** 开发期自检:菜单路径必须存在于路由表中,防止再次出现"点了没反应" */
|
||
if (import.meta.env.DEV) {
|
||
const knownPaths = new Set(router.getRoutes().map((item) => item.path));
|
||
for (const item of menuItems) {
|
||
if (!knownPaths.has(item.path)) {
|
||
console.error(`[AdminLayout] 菜单项未注册对应路由:${item.path}`);
|
||
}
|
||
}
|
||
}
|
||
|
||
const connectionText = computed(() => {
|
||
if (realtime.connected) return '实时通道已连接';
|
||
if (realtime.connecting) return '实时通道连接中';
|
||
return '实时通道已断开';
|
||
});
|
||
|
||
const connectionType = computed(() =>
|
||
realtime.connected ? 'success' : realtime.connecting ? 'warning' : 'danger',
|
||
);
|
||
|
||
/**
|
||
* 小屏顶栏的实时通道提示:
|
||
* 连接正常时 **什么都不显示**(旧版只显示一个绿色圆点,看起来像坏掉的元素);
|
||
* 只有"连接中 / 已断开"这种异常态才显示带文字的紧凑标签。
|
||
*/
|
||
const mobileConnectionText = computed(() => (realtime.connecting ? '重连中…' : '已断开'));
|
||
|
||
async function handleLogout(): Promise<void> {
|
||
await ElMessageBox.confirm('确认退出当前账号?', '退出登录', { type: 'warning' });
|
||
await auth.logout();
|
||
ElMessage.success('已退出登录');
|
||
void router.push({ name: 'login' });
|
||
}
|
||
|
||
/* ------------------------------------------------------------ 修改密码 */
|
||
const passwordVisible = ref(false);
|
||
const passwordFormRef = ref<FormInstance>();
|
||
const passwordForm = reactive({ currentPassword: '', newPassword: '', confirmPassword: '' });
|
||
const passwordRules: FormRules = {
|
||
currentPassword: [{ required: true, message: '请输入当前密码', trigger: 'blur' }],
|
||
newPassword: [
|
||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||
{ min: 6, message: '新密码至少 6 位', trigger: 'blur' },
|
||
],
|
||
confirmPassword: [
|
||
{
|
||
validator: (_rule, value: string, callback: (error?: Error) => void) => {
|
||
if (!value) callback(new Error('请再次输入新密码'));
|
||
else if (value !== passwordForm.newPassword) callback(new Error('两次输入的密码不一致'));
|
||
else callback();
|
||
},
|
||
trigger: 'blur',
|
||
},
|
||
],
|
||
};
|
||
|
||
async function submitPassword(): Promise<void> {
|
||
const valid = await passwordFormRef.value?.validate().catch(() => false);
|
||
if (!valid) return;
|
||
await authApi.changePassword({
|
||
currentPassword: passwordForm.currentPassword,
|
||
newPassword: passwordForm.newPassword,
|
||
});
|
||
passwordVisible.value = false;
|
||
passwordForm.currentPassword = '';
|
||
passwordForm.newPassword = '';
|
||
passwordForm.confirmPassword = '';
|
||
ElMessage.success('密码修改成功,请重新登录');
|
||
await auth.logout();
|
||
void router.push({ name: 'login' });
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<el-container class="layout">
|
||
<!-- 桌面/平板:常驻深色侧边栏 -->
|
||
<el-aside v-if="!isMobile" width="210px" class="layout-aside ch-sidebar">
|
||
<div class="brand">
|
||
<el-icon :size="22"><School /></el-icon>
|
||
<span class="brand-text">班级小助手</span>
|
||
</div>
|
||
<el-menu :default-active="activeMenu" class="layout-menu" @select="handleMenuSelect">
|
||
<el-menu-item v-for="item in visibleMenuItems" :key="item.path" :index="item.path">
|
||
<el-icon><component :is="item.icon" /></el-icon>
|
||
<span>{{ item.title }}</span>
|
||
</el-menu-item>
|
||
</el-menu>
|
||
</el-aside>
|
||
|
||
<el-container class="layout-body">
|
||
<el-header class="layout-header">
|
||
<div class="header-left">
|
||
<!-- 小屏:汉堡按钮唤出抽屉菜单 -->
|
||
<button
|
||
v-if="isMobile"
|
||
type="button"
|
||
class="nav-toggle"
|
||
aria-label="打开菜单"
|
||
:aria-expanded="drawerVisible ? 'true' : 'false'"
|
||
@click="drawerVisible = true"
|
||
>
|
||
<el-icon :size="20"><Menu /></el-icon>
|
||
</button>
|
||
<span class="header-title">{{ isMobile ? currentTitle : APP_TITLE }}</span>
|
||
<el-tag v-if="!isMobile" :type="connectionType" size="small" effect="light">
|
||
<span class="header-conn">{{ connectionText }}</span>
|
||
</el-tag>
|
||
<!-- 小屏:连接正常时不显示任何圆点/标签,只在异常态显示带文字的紧凑标签 -->
|
||
<el-tag
|
||
v-else-if="!realtime.connected"
|
||
:type="connectionType"
|
||
size="small"
|
||
effect="light"
|
||
class="header-conn-mobile"
|
||
>
|
||
{{ mobileConnectionText }}
|
||
</el-tag>
|
||
<el-tag v-if="realtime.eventCount > 0 && !isMobile" size="small" type="info" effect="plain">
|
||
已接收 {{ realtime.eventCount }} 条实时事件
|
||
</el-tag>
|
||
</div>
|
||
|
||
<div class="header-right">
|
||
<el-dropdown trigger="click">
|
||
<span class="user-chip">
|
||
<el-icon><UserFilled /></el-icon>
|
||
<template v-if="!isMobile">
|
||
{{ auth.displayName }}
|
||
<el-tag size="small" type="info" effect="plain">{{ auth.roleLabel }}</el-tag>
|
||
</template>
|
||
<el-icon><ArrowDown /></el-icon>
|
||
</span>
|
||
<template #dropdown>
|
||
<el-dropdown-menu>
|
||
<el-dropdown-item disabled>{{ auth.displayName }} · {{ auth.roleLabel }}</el-dropdown-item>
|
||
<el-dropdown-item divided @click="passwordVisible = true">
|
||
<el-icon><Lock /></el-icon>
|
||
修改密码
|
||
</el-dropdown-item>
|
||
<el-dropdown-item divided @click="handleLogout">
|
||
<el-icon><SwitchButton /></el-icon>
|
||
退出登录
|
||
</el-dropdown-item>
|
||
</el-dropdown-menu>
|
||
</template>
|
||
</el-dropdown>
|
||
</div>
|
||
</el-header>
|
||
|
||
<el-main class="layout-main">
|
||
<router-view v-slot="{ Component }">
|
||
<component :is="Component" />
|
||
</router-view>
|
||
</el-main>
|
||
</el-container>
|
||
|
||
<!-- 小屏抽屉菜单(1Panel 风格:深色侧栏内容与桌面端完全一致) -->
|
||
<el-drawer
|
||
v-model="drawerVisible"
|
||
direction="ltr"
|
||
size="240px"
|
||
:with-header="false"
|
||
class="ch-nav-drawer"
|
||
>
|
||
<div class="ch-sidebar ch-sidebar-drawer">
|
||
<div class="brand">
|
||
<el-icon :size="22"><School /></el-icon>
|
||
<span class="brand-text">班级小助手</span>
|
||
</div>
|
||
<el-menu :default-active="activeMenu" class="layout-menu" @select="handleMenuSelect">
|
||
<el-menu-item v-for="item in visibleMenuItems" :key="item.path" :index="item.path">
|
||
<el-icon><component :is="item.icon" /></el-icon>
|
||
<span>{{ item.title }}</span>
|
||
</el-menu-item>
|
||
</el-menu>
|
||
</div>
|
||
</el-drawer>
|
||
|
||
<el-dialog v-model="passwordVisible" title="修改密码" width="420px">
|
||
<el-form ref="passwordFormRef" :model="passwordForm" :rules="passwordRules" label-width="90px">
|
||
<el-form-item label="当前密码" prop="currentPassword">
|
||
<el-input v-model="passwordForm.currentPassword" type="password" show-password />
|
||
</el-form-item>
|
||
<el-form-item label="新密码" prop="newPassword">
|
||
<el-input v-model="passwordForm.newPassword" type="password" show-password />
|
||
</el-form-item>
|
||
<el-form-item label="确认密码" prop="confirmPassword">
|
||
<el-input v-model="passwordForm.confirmPassword" type="password" show-password />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="passwordVisible = false">取消</el-button>
|
||
<el-button type="primary" @click="submitPassword">确认修改</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</el-container>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.layout {
|
||
height: 100vh;
|
||
height: 100dvh;
|
||
}
|
||
|
||
.layout-body {
|
||
min-width: 0;
|
||
}
|
||
|
||
.layout-aside {
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.brand {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
height: 56px;
|
||
padding: 0 16px;
|
||
color: #fff;
|
||
font-weight: 600;
|
||
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||
}
|
||
|
||
.brand-text {
|
||
font-size: 16px;
|
||
}
|
||
|
||
.layout-menu {
|
||
border-right: none;
|
||
background: transparent;
|
||
flex: 1;
|
||
--el-menu-text-color: #cbd5e1;
|
||
--el-menu-hover-bg-color: rgba(255, 255, 255, 0.08);
|
||
--el-menu-active-color: #ffffff;
|
||
}
|
||
|
||
.layout-menu :deep(.el-menu-item.is-active) {
|
||
background: #409eff;
|
||
border-radius: var(--ch-radius-sm);
|
||
margin: 0 8px;
|
||
}
|
||
|
||
.layout-menu :deep(.el-menu-item) {
|
||
margin: 2px 8px;
|
||
border-radius: var(--ch-radius-sm);
|
||
}
|
||
|
||
.layout-header {
|
||
/* 顶栏跟随圆角设计:底部圆角 + 轻投影,与内容区一体化 */
|
||
border-radius: 0 0 var(--ch-radius-lg) var(--ch-radius-lg);
|
||
box-shadow: var(--ch-shadow-sm);
|
||
background: #fff;
|
||
border-bottom: 1px solid var(--ch-border);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
padding: 0 16px;
|
||
}
|
||
|
||
.nav-toggle {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 32px;
|
||
height: 32px;
|
||
margin-right: 2px;
|
||
border: none;
|
||
border-radius: var(--ch-radius-sm);
|
||
background: #f2f3f5;
|
||
color: #303133;
|
||
cursor: pointer;
|
||
transition: background 0.18s ease;
|
||
}
|
||
|
||
.nav-toggle:hover {
|
||
background: #e6e8eb;
|
||
}
|
||
|
||
.header-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
min-width: 0;
|
||
}
|
||
|
||
.header-title {
|
||
font-weight: 600;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
|
||
.header-conn {
|
||
margin-left: 4px;
|
||
}
|
||
|
||
.header-right {
|
||
display: flex;
|
||
align-items: center;
|
||
flex: 0 0 auto;
|
||
}
|
||
|
||
.user-chip {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
cursor: pointer;
|
||
outline: none;
|
||
}
|
||
|
||
.layout-main {
|
||
background: var(--ch-bg);
|
||
padding: 0;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
/* 小屏:顶栏更紧凑,正文留出安全区 */
|
||
@media (max-width: 768px) {
|
||
.layout-header {
|
||
height: var(--ch-header-height);
|
||
padding: 0 10px;
|
||
gap: 8px;
|
||
}
|
||
|
||
.header-title {
|
||
font-size: 15px;
|
||
}
|
||
|
||
/* 异常态才出现的实时通道标签:紧凑、不挤占标题 */
|
||
.header-conn-mobile {
|
||
flex: 0 0 auto;
|
||
font-size: 11px;
|
||
}
|
||
}
|
||
</style>
|
||
|
||
<style>
|
||
/* 侧边栏配色放在全局:桌面 asider 与移动端抽屉复用同一套样式(抽屉内容在 teleport 中,scoped 样式不生效) */
|
||
.ch-sidebar {
|
||
/* 圆角设计:深色侧栏右侧做圆角,与内容区形成"卡片浮起"观感 */
|
||
border-radius: 0 var(--ch-radius-xl) var(--ch-radius-xl) 0;
|
||
overflow: hidden;
|
||
background: #1f2d3d;
|
||
color: #fff;
|
||
}
|
||
|
||
.ch-sidebar-drawer {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
/* 小屏抽屉:去掉 Element Plus 默认内边距,让深色侧栏铺满 */
|
||
.ch-nav-drawer .el-drawer__body {
|
||
padding: 0;
|
||
overflow: hidden;
|
||
}
|
||
</style>
|