feat: 重做灵动岛编辑器与课表档案时间表编辑
灵动岛 - 重构自定义方案编辑器:组件库常驻、拖拽添加与排序、方案切换/新建/复制/删除、编辑模式预览与缩放,容器在编辑时展开全部子组件。 - 新增天气简报组件:主进程固定请求 Open-Meteo,只接受数值经纬度,失败退避并保留本次运行缓存;冒烟模式不访问外网。 - 倒计时支持目标名称与日期;课程表组件新增「今日时间点」,按时间点类型折叠/展开,课中不再常驻倒计时。 - preload 暴露 getIslandWeather 与时间点订阅,契约同步 desktop.d.ts。 课表档案 - 时间点默认课程:布局返回 defaultCourse,日课表没有条目时回退;新增 apply-default 覆盖所有引用课表;全校时间表不携带默认课程。 - 新增 ClassIsland 式时间表编辑器(列表/时间轴视图、拖动把柄、按类型添加、默认时长与缩放)与「课表信息」表单。 - 课表页默认进入单表编辑,底部保留列表/周/月视图;时间表支持新路由删除。 - 「课间」统一改称「课间休息」。 验证 - pnpm typecheck、pnpm lint 通过。 - verify:e2e 隔离验收 248/248 项通过(含默认课程回退、覆盖写入与时间表删除)。 - ui-smoke 覆盖单表编辑、课表信息与时间轴视图,并更新回归截图。
This commit is contained in:
1 parent
938285bb9c
commit
682818dd4a
41 files changed
+4349
-1095
No files matched your search
@@ -79,6 +79,13 @@ layouts.post(
|
||||
);
|
||||
},
|
||||
);
|
||||
layouts.post(
|
||||
'/:id/points/:pointId/apply-default',
|
||||
requirePermission('timetable:manage'),
|
||||
validate({ params: z.object({ id: z.string().min(1), pointId: z.string().min(1) }) }),
|
||||
async (req, res) =>
|
||||
sendOk(res, await service.applyDefaultCourse(String(req.params.id), String(req.params.pointId))),
|
||||
);
|
||||
layouts.delete(
|
||||
'/:id',
|
||||
requirePermission('timetable:manage'),
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getMaxTermWeeks } from '../../lib/term.js';
|
||||
import { ApiError } from '../../lib/http.js';
|
||||
import type { TokenPayload } from '../../lib/jwt.js';
|
||||
import { emitToClass } from '../../realtime/bus.js';
|
||||
import { planInclude } from '../../lib/class-plan.js';
|
||||
import { decorateLayout, planInclude } from '../../lib/class-plan.js';
|
||||
import type { z } from 'zod';
|
||||
import type {
|
||||
planSchema,
|
||||
@@ -26,14 +26,31 @@ export async function notifyScheduleChanged(classId?: string | null) {
|
||||
export async function listLayouts(user: TokenPayload, classId?: string) {
|
||||
if (classId) await assertClassAccess(user, classId);
|
||||
const ids = classId ? [classId] : await getAccessibleClassIds(user);
|
||||
return prisma.timeLayout.findMany({
|
||||
const rows = await prisma.timeLayout.findMany({
|
||||
where: { OR: [{ classId: null }, { classId: { in: ids } }] },
|
||||
include: { points: { orderBy: { position: 'asc' } } },
|
||||
});
|
||||
return Promise.all(rows.map((row) => decorateLayout(row)));
|
||||
}
|
||||
export async function saveLayout(input: z.infer<typeof layoutSchema>, id?: string) {
|
||||
if (id && !(await prisma.timeLayout.findUnique({ where: { id } }))) throw ApiError.notFound('时间表不存在');
|
||||
const pointIds = input.points.flatMap((p) => (p.id ? [p.id] : []));
|
||||
const existing = id
|
||||
? await prisma.timeLayout.findUnique({ where: { id }, select: { classId: true } })
|
||||
: null;
|
||||
if (id && !existing) throw ApiError.notFound('时间表不存在');
|
||||
const layoutClassId = existing ? existing.classId : (input.classId ?? null);
|
||||
// 默认课程属于具体班级:全校时间表不保留默认课程,非上课时间点也不保留。
|
||||
const points = input.points.map((point) => ({
|
||||
...point,
|
||||
defaultClassId: point.timeType === 'LESSON' && layoutClassId ? (point.defaultClassId ?? null) : null,
|
||||
}));
|
||||
const defaultIds = [...new Set(points.flatMap((p) => (p.defaultClassId ? [p.defaultClassId] : [])))];
|
||||
if (defaultIds.length && layoutClassId) {
|
||||
const count = await prisma.course.count({
|
||||
where: { id: { in: defaultIds }, classId: layoutClassId },
|
||||
});
|
||||
if (count !== defaultIds.length) throw ApiError.badRequest('默认课程不属于该班级');
|
||||
}
|
||||
const pointIds = points.flatMap((p) => (p.id ? [p.id] : []));
|
||||
if (new Set(pointIds).size !== pointIds.length) throw ApiError.badRequest('时间点不能重复');
|
||||
const result = await prisma.$transaction(async (tx) => {
|
||||
const layout = id
|
||||
@@ -48,7 +65,7 @@ export async function saveLayout(input: z.infer<typeof layoutSchema>, id?: strin
|
||||
if (pointIds.some((p) => !owned.some((o) => o.id === p)))
|
||||
throw ApiError.badRequest('时间点不属于这份时间表');
|
||||
await tx.timeLayoutItem.deleteMany({ where: { timeLayoutId: layout.id, id: { notIn: pointIds } } });
|
||||
for (const [position, point] of input.points.entries()) {
|
||||
for (const [position, point] of points.entries()) {
|
||||
const { id: pointId, ...data } = point;
|
||||
if (pointId) await tx.timeLayoutItem.update({ where: { id: pointId }, data: { ...data, position } });
|
||||
else await tx.timeLayoutItem.create({ data: { ...data, position, timeLayoutId: layout.id } });
|
||||
@@ -59,7 +76,49 @@ export async function saveLayout(input: z.infer<typeof layoutSchema>, id?: strin
|
||||
});
|
||||
});
|
||||
await notifyScheduleChanged();
|
||||
return result;
|
||||
return decorateLayout(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把时间点的默认课程写入所有引用该时间表的日课表(ClassIsland 的「覆盖现有课程」)。
|
||||
* 只处理班级时间表:全校时间表的默认课程没有归属班级。
|
||||
*/
|
||||
export async function applyDefaultCourse(layoutId: string, pointId: string) {
|
||||
const layout = await prisma.timeLayout.findUnique({
|
||||
where: { id: layoutId },
|
||||
include: { points: true },
|
||||
});
|
||||
if (!layout) throw ApiError.notFound('时间表不存在');
|
||||
if (!layout.classId) throw ApiError.badRequest('全校时间表不能覆盖默认课程');
|
||||
const point = layout.points.find((p) => p.id === pointId);
|
||||
if (!point || point.timeType !== 'LESSON') throw ApiError.badRequest('时间点不是上课时间点');
|
||||
if (!point.defaultClassId) throw ApiError.badRequest('请先设置默认课程');
|
||||
const course = await prisma.course.findFirst({
|
||||
where: { id: point.defaultClassId, classId: layout.classId },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!course) throw ApiError.badRequest('默认课程不属于该班级');
|
||||
const plans = await prisma.classPlan.findMany({
|
||||
where: { timeLayoutId: layout.id, classId: layout.classId },
|
||||
select: { id: true },
|
||||
});
|
||||
const courseId = point.defaultClassId;
|
||||
await prisma.$transaction(
|
||||
plans.map((plan) =>
|
||||
prisma.classPlanEntry.upsert({
|
||||
where: { classPlanId_timeLayoutItemId: { classPlanId: plan.id, timeLayoutItemId: point.id } },
|
||||
create: {
|
||||
classPlanId: plan.id,
|
||||
timeLayoutItemId: point.id,
|
||||
courseId,
|
||||
isEnabled: true,
|
||||
},
|
||||
update: { courseId, isEnabled: true },
|
||||
}),
|
||||
),
|
||||
);
|
||||
await notifyScheduleChanged(layout.classId);
|
||||
return { plans: plans.length };
|
||||
}
|
||||
export async function listPlans(user: TokenPayload, classId?: string, week?: number) {
|
||||
if (classId) await assertClassAccess(user, classId);
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
requireClassDeviceClassId,
|
||||
} from '../../lib/access.js';
|
||||
import {
|
||||
loadDefaultCourseMap,
|
||||
loadPlans,
|
||||
planInclude,
|
||||
projectPlan,
|
||||
@@ -52,9 +53,11 @@ export async function listSchedules(
|
||||
result.push(...(await resolveActiveClassPlan(classId, date)).schedules);
|
||||
}
|
||||
} else {
|
||||
for (const plan of await loadPlans(classId))
|
||||
const plans = await loadPlans(classId);
|
||||
const defaults = await loadDefaultCourseMap(plans.flatMap((plan) => plan.layout.points));
|
||||
for (const plan of plans)
|
||||
if (!plan.isOverlay && (!options.dayOfWeek || plan.weekday === options.dayOfWeek))
|
||||
result.push(...projectPlan(plan));
|
||||
result.push(...projectPlan(plan, defaults));
|
||||
}
|
||||
}
|
||||
const byId = new Map<string, ScheduleDto>();
|
||||
|
||||
Reference in new issue
Block a user