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:
@@ -150,6 +150,9 @@ const BREAK_END_KEY = computed(() => `breakEnd_${taskNum}`);
|
||||
const isBreak = ref(false);
|
||||
const breakAudio = new Audio('/resource/notification.mp3');
|
||||
|
||||
// 恢复提示
|
||||
const showResumeHint = ref(route.query.resume === "true");
|
||||
|
||||
const progress = computed(() => {
|
||||
const total = isBreak.value ? 5 * 60 : 25 * 60;
|
||||
const remaining = timerMinutes.value * 60 + timerSeconds.value;
|
||||
@@ -303,6 +306,7 @@ const endTimer = async (content: string) => {
|
||||
}
|
||||
clear();
|
||||
clearBreakState();
|
||||
localStorage.removeItem("activeSession");
|
||||
await router.push("/study");
|
||||
} catch {
|
||||
ElMessage.error("结束会话失败,请重试");
|
||||
@@ -389,6 +393,13 @@ const loadTaskSession = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 持久化活跃会话(用于跨页面恢复 + 阻止多任务)
|
||||
localStorage.setItem("activeSession", JSON.stringify({
|
||||
taskNum: taskInfo.value.taskNum,
|
||||
sessionNum: taskInfo.value.sessionNum,
|
||||
taskName: taskInfo.value.taskName,
|
||||
}));
|
||||
|
||||
if (taskInfo.value.sessionState === "ONGOING") {
|
||||
startTimer();
|
||||
} else {
|
||||
@@ -516,6 +527,14 @@ onUnmounted(() => {
|
||||
<template>
|
||||
<div>
|
||||
<section class="start-page">
|
||||
<el-alert
|
||||
v-if="showResumeHint"
|
||||
title="已恢复上次的学习会话,继续学习吧"
|
||||
type="success"
|
||||
show-icon
|
||||
:closable="true"
|
||||
@close="showResumeHint = false"
|
||||
/>
|
||||
<div class="task-info-bar">
|
||||
<el-tag type="success" effect="plain">任务编号:{{ taskInfo.taskNum }}</el-tag>
|
||||
<span class="status-text">状态:{{ statusText }}</span>
|
||||
|
||||
Reference in New Issue
Block a user