feat(会话):跨页面自动恢复 + 阻止多任务同时进行
后端: - StudySessionsServiceImpl.getActiveSession(excludeTaskNum): 查询 ONGOING/PAUSED 状态的活跃会话,可排除指定任务 - Controller 新增 GET /study-sessions/active?excludeTaskNum= 前端: - router beforeEach 守卫:读取 localStorage 中 activeSession, 非 start-task 页面时自动重定向恢复 - Study.vue 开始任务按钮:调用 getActiveSession() 检测是否 有其他任务正在进行,提示用户前往继续 - StartTask.vue loadTaskSession 成功后将活跃会话写入 localStorage(taskNum/sessionNum/taskName) - endSession 成功时清除 localStorage 中的 activeSession - 路由参数 ?resume=true 时页面顶部显示恢复提示已恢复上次
This commit is contained in:
@@ -89,6 +89,18 @@ router.beforeEach((to) => {
|
||||
if (!isLoggedIn) {
|
||||
return "/login";
|
||||
}
|
||||
// 如果有活跃会话且未处于 start-task 页面,自动恢复
|
||||
if (!to.path.startsWith("/start-task")) {
|
||||
const stored = localStorage.getItem("activeSession");
|
||||
if (stored) {
|
||||
try {
|
||||
const { taskNum } = JSON.parse(stored);
|
||||
if (taskNum) {
|
||||
return `/start-task/${encodeURIComponent(taskNum)}?resume=true`;
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user