feat(permissions,clients,ai,system,server,web,client,shared)!: 权限组 + 客户端设备远控与自动更新 + 大模型助手 + 系统诊断(1.3.0)
功能级准入改为「权限键」,`requireRole` 退成默认模板。 权限组 - 权限目录(39 键:键 / 中文名 / 分类 / 默认角色)收口到 shared,路由挂 requirePermission / requireAnyPermission - 有效权限每请求实时算,改完分组立刻生效:ADMIN 全集且 permission:manage、system:manage 不可剥夺; CLASS_DEVICE 空集(不受分组影响);有分组 = 并集(因此也能用来**收回**权限);无分组 = 角色默认模板 - 新增「权限组」页:组增删改、成员分配、生效权限预览 - 班级维度的科目规则(assertCanManageSubjectContent)故意不可被权限组覆盖 客户端设备(ClassHelper 桌面端) - 设备身份是 deviceKey(首次启动生成的 UUID,saveConfig 拒绝改写、退出登录也保留) - 心跳走「DB 记状态 + 客户端定时拉」,不引入新的长连接:30 秒一次,在线窗口 90 秒 - 远控命令 shutdown / restart / logoff / lock:服务端有效期 10 分钟,客户端弹默认选中「取消」的对话框、 60 秒未确认按取消处理,执行后必须回执(重复回执幂等),同一台机器同一条命令只弹一次 - 新增「客户端设备」页:版本一览、一键推送更新、下发远控 客户端安装包由服务端下载并缓存(教室机常常没有外网,浏览器也受 CSP 限制) - POST /api/update/client/fetch 由服务端下载到 data/client-releases/<版本>/ 并登记 sha256 + size - 自动安装三条护栏:没有 sha256 就拒收、必须等到非上课且主窗口隐藏满 5 分钟、冒烟模式永不安装 大模型助手:只解析、不落库 - POST /api/ai/interpret 返回**待确认**的结构化动作(建作业 / 发通知 / 叫人), 真正落库仍调既有端点 —— 权限断言、上课时段紧急通知保护、ClassIsland 推送全部自动复用 - 模型给的 params 用与手动入口**同一份** zod 再校验(模型输出不可信) - API Key 走 AES-256-GCM(密钥由 JWT_SECRET 经 scrypt 派生)加密存 AppSetting,只进不出 - provider=mock 是离线确定性解析,自动化验收一律用它;每次解析写一条 AiAudit(不含密钥) 系统与运维 - 开发者模式(服务端内存缓存开关,热路径不查库;开启后 500 才附 error.stack)、运行诊断(绝不回传密钥) - 开机自启动运行期可改:Windows 改 HKCU\...\Run、Linux systemctl enable/disable, **非安装形态一律返回 supported:false**,不往开发机的注册表里写自启项 - 服务端侧栏折叠只用 CSS 收拢(不重建 DOM),关怀模式只放大字号与控件、不动任何几何令牌 客户端 - 崩溃自愈:渲染进程挂掉 / 超 10 秒无响应先静默重建主窗口(10 分钟最多 3 次), 未捕获异常只在「没在上课、没人看着」时才重启进程;冒烟模式绝不重启(会杀掉验证实例) - 上线补弹离线期间收到的消息只做一次:起点只在「可达 → 不可达」的边界写,恢复时取最近 5 条按时间升序推 发布内容批量 - POST /notifications/bulk、POST /homeworks/bulk:**单班失败不影响整批**,逐班返回结果 - 作业的科目名跨班**按名匹配**已有课程,找不到就整班记失败,绝不自动建课 (自动建课会把创建者写成任课老师,等于越权改任教关系) - 通知与作业同口径按「所属日期」归档,新增 /notifications/days 与 /notifications/creators BREAKING CHANGE: 能不能做某件事不再看角色名,而是看权限键(GET /api/permissions/me)。 未分组的账号按角色默认模板生效,行为与 1.2.0 一致;分组之后生效集合只由组的并集决定。 服务端首次启动会自动应用 1 个数据库迁移(权限组 3 表 / AppSetting / 客户端设备·命令·安装包 / AiAudit / Notification.assignDate / User.careMode,历史通知按本地日期回填),升级前请先备份。
This commit is contained in:
1 parent
e51879667a
commit
817af02357
131 files changed
+12995
-538
No files matched your search
@@ -13,6 +13,8 @@ import {
|
||||
truncate,
|
||||
type ClassDto,
|
||||
type ClassPeriod,
|
||||
type NotificationCreatorSummary,
|
||||
type NotificationDaySummary,
|
||||
type NotificationDto,
|
||||
type NotificationPriority,
|
||||
type StudentDto,
|
||||
@@ -27,7 +29,38 @@ const route = useRoute();
|
||||
const loading = ref(false);
|
||||
const classes = ref<ClassDto[]>([]);
|
||||
const notifications = ref<NotificationDto[]>([]);
|
||||
const filter = reactive({ classId: '', priority: '', keyword: '' });
|
||||
const filter = reactive({ classId: '', priority: '', keyword: '', date: '', createdBy: '' });
|
||||
|
||||
/**
|
||||
* 按天归档 / 按发布人归档的候选列表(需求:通知按天归档,也可按发布人、类型看)。
|
||||
*
|
||||
* 两者跟着"班级 + 优先级"走:班级一换,日期栏与发布人栏就应该只剩那个班里真实存在的
|
||||
* 日期与人 —— 否则选项里全是别的班级的数据,选中后得到空列表,看着像坏了。
|
||||
* 发布人栏还额外跟着当前选中的日期收敛("这一天都有谁发过通知")。
|
||||
*/
|
||||
const days = ref<NotificationDaySummary[]>([]);
|
||||
const creators = ref<NotificationCreatorSummary[]>([]);
|
||||
|
||||
async function loadArchive(): Promise<void> {
|
||||
const base = {
|
||||
...(filter.classId ? { classId: filter.classId } : {}),
|
||||
...(filter.priority ? { priority: filter.priority } : {}),
|
||||
};
|
||||
const [dayList, creatorList] = await Promise.all([
|
||||
notificationApi.days(base).catch(() => ({ days: [] as NotificationDaySummary[] })),
|
||||
notificationApi
|
||||
.creators({ ...base, ...(filter.date ? { date: filter.date } : {}) })
|
||||
.catch(() => ({ creators: [] as NotificationCreatorSummary[] })),
|
||||
]);
|
||||
days.value = dayList.days;
|
||||
creators.value = creatorList.creators;
|
||||
}
|
||||
|
||||
/** 筛选变化后统一刷新:先更新归档候选,再拉当前筛选下的列表 */
|
||||
async function refreshList(): Promise<void> {
|
||||
await loadArchive();
|
||||
await loadNotifications();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否"单班视图":选中了具体班级时列表只服务一个班。
|
||||
@@ -65,10 +98,18 @@ async function loadClassStudentCounts(): Promise<void> {
|
||||
async function loadNotifications(): Promise<void> {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: { classId?: string; priority?: string; keyword?: string } = {};
|
||||
const params: {
|
||||
classId?: string;
|
||||
priority?: string;
|
||||
keyword?: string;
|
||||
date?: string;
|
||||
createdBy?: string;
|
||||
} = {};
|
||||
if (filter.classId) params.classId = filter.classId;
|
||||
if (filter.priority) params.priority = filter.priority;
|
||||
if (filter.keyword.trim()) params.keyword = filter.keyword.trim();
|
||||
if (filter.date) params.date = filter.date;
|
||||
if (filter.createdBy) params.createdBy = filter.createdBy;
|
||||
notifications.value = await notificationApi.list(params);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
@@ -236,48 +277,34 @@ interface PublishFailure {
|
||||
}
|
||||
|
||||
/**
|
||||
* 真正提交:对每个班级各调一次 `POST /api/notifications`(Promise.allSettled),
|
||||
* confirmDuringClass 为 true 表示教师已在上课警告中确认。
|
||||
* 真正提交:调用服务端的**批量发布**端点(`POST /api/notifications/bulk`)一次提交,
|
||||
* 服务端逐班做权限断言与上课保护,并把每个班的结果回给我们。
|
||||
*
|
||||
* 为什么不再由前端对每个班各发一次请求:N 个班就是 N 次往返,权限/上课保护/ClassIsland 推送
|
||||
* 分散在 N 个响应里,前端还得自己合并;服务端批量端点把这些收敛成一份逐班结果(见 AGENTS.md §5)。
|
||||
* confirmDuringClass 为 true 表示教师已在上课警告里确认。
|
||||
*/
|
||||
async function doPublish(classIds: string[], confirmDuringClass: boolean): Promise<void> {
|
||||
if (classIds.length === 0) return;
|
||||
|
||||
const payload = {
|
||||
const result = await notificationApi.bulkCreate({
|
||||
classIds,
|
||||
title: form.title.trim(),
|
||||
content: form.content,
|
||||
priority: form.priority,
|
||||
...(confirmDuringClass ? { confirmDuringClass: true } : {}),
|
||||
};
|
||||
|
||||
const settled = await Promise.allSettled(
|
||||
classIds.map((classId) => notificationApi.create({ ...payload, classId })),
|
||||
);
|
||||
|
||||
let successCount = 0;
|
||||
const failures: PublishFailure[] = [];
|
||||
|
||||
settled.forEach((result, index) => {
|
||||
if (result.status === 'fulfilled') {
|
||||
successCount += 1;
|
||||
return;
|
||||
}
|
||||
const response = (
|
||||
result.reason as {
|
||||
response?: {
|
||||
status?: number;
|
||||
data?: { code?: string; message?: string; details?: { current?: ClassPeriod | null } };
|
||||
};
|
||||
}
|
||||
).response;
|
||||
failures.push({
|
||||
classId: classIds[index] ?? '',
|
||||
reason:
|
||||
response?.data?.message ?? (result.reason instanceof Error ? result.reason.message : '发布失败'),
|
||||
urgentConflict: response?.status === 409 && response?.data?.code === 'URGENT_DURING_CLASS',
|
||||
period: response?.data?.details?.current ?? null,
|
||||
});
|
||||
});
|
||||
|
||||
const successCount = result.succeeded;
|
||||
const failures: PublishFailure[] = result.results
|
||||
.filter((item) => !item.ok)
|
||||
.map((item) => ({
|
||||
classId: item.classId,
|
||||
reason: item.message ?? '发布失败',
|
||||
urgentConflict: item.code === 'URGENT_DURING_CLASS',
|
||||
period: ((item.details ?? {}) as { current?: ClassPeriod | null }).current ?? null,
|
||||
}));
|
||||
|
||||
// 兜底:并发场景下服务端仍可能拦截(例如刚好上课铃响),对这批班级重新走一次二次确认
|
||||
const conflicted = failures.filter((item) => item.urgentConflict);
|
||||
const pendingConfirm = !confirmDuringClass && conflicted.length > 0;
|
||||
@@ -296,7 +323,7 @@ async function doPublish(classIds: string[], confirmDuringClass: boolean): Promi
|
||||
// 注意这里是 pendingConfirm 而不是 !pendingConfirm —— 写成取反会让弹窗在**发布成功后仍然开着**,
|
||||
// 老师以为没发出去再点一次「立即发布」,同一批班级就重复收到通知(还会重复广播与推 ClassIsland)。
|
||||
formVisible.value = pendingConfirm;
|
||||
await loadNotifications();
|
||||
await refreshList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +390,7 @@ function rowClassName({ row }: { row: NotificationDto }): string {
|
||||
|
||||
onMounted(async () => {
|
||||
await loadClasses();
|
||||
await loadNotifications();
|
||||
await refreshList();
|
||||
realtime.on(SOCKET_EVENTS.notificationNew, onNotificationEvent);
|
||||
// 列表渲染完再滚动,否则表格行还没生成
|
||||
if (highlightedId.value) {
|
||||
@@ -390,7 +417,7 @@ onUnmounted(() => {
|
||||
placeholder="选择班级"
|
||||
clearable
|
||||
style="width: 170px"
|
||||
@change="loadNotifications"
|
||||
@change="refreshList"
|
||||
>
|
||||
<el-option v-for="item in classes" :key="item.id" :label="item.name" :value="item.id" />
|
||||
</el-select>
|
||||
@@ -399,7 +426,7 @@ onUnmounted(() => {
|
||||
placeholder="全部优先级"
|
||||
clearable
|
||||
style="width: 150px"
|
||||
@change="loadNotifications"
|
||||
@change="refreshList"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in NOTIFICATION_PRIORITIES"
|
||||
@@ -408,6 +435,36 @@ onUnmounted(() => {
|
||||
:value="item"
|
||||
/>
|
||||
</el-select>
|
||||
<!-- 按天归档:只列当前班级/优先级下真实存在的日期与条数 -->
|
||||
<el-select
|
||||
v-model="filter.date"
|
||||
placeholder="按天归档"
|
||||
clearable
|
||||
style="width: 170px"
|
||||
@change="refreshList"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in days"
|
||||
:key="item.date"
|
||||
:label="`${item.date}(${item.count})`"
|
||||
:value="item.date"
|
||||
/>
|
||||
</el-select>
|
||||
<!-- 按发布人归档:跟着班级/优先级/日期收敛 -->
|
||||
<el-select
|
||||
v-model="filter.createdBy"
|
||||
placeholder="全部发布人"
|
||||
clearable
|
||||
style="width: 160px"
|
||||
@change="loadNotifications"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in creators"
|
||||
:key="item.id"
|
||||
:label="`${item.name}(${item.count})`"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input
|
||||
v-model="filter.keyword"
|
||||
placeholder="搜索标题/内容"
|
||||
@@ -452,6 +509,12 @@ onUnmounted(() => {
|
||||
<div class="text-muted">{{ relativeTime(row.createdAt) }}</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 所属日期:按天归档用的口径(本地日期),晚间发布不会被算到第二天 -->
|
||||
<el-table-column label="所属日期" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" effect="plain">{{ row.assignDate }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="isSingleClass ? '已读情况' : '已读率'" width="150">
|
||||
<template #default="{ row }">
|
||||
<!--
|
||||
@@ -489,7 +552,7 @@ onUnmounted(() => {
|
||||
filterable
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
placeholder="可多选;发布时逐班提交"
|
||||
placeholder="可多选;一次发布到所有选中班级"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option v-for="item in classes" :key="item.id" :label="item.name" :value="item.id" />
|
||||
|
||||
Reference in new issue
Block a user