修复学习流程路由切换与计时展示稳定性
This commit is contained in:
+320
-105
@@ -1,11 +1,15 @@
|
|||||||
<!-- src/views/StudyTimer.vue -->
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from "vue-router";
|
||||||
import {ElMessage, ElMessageBox} from 'element-plus';
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
import { useTimer } from '@/components/composables/useTimer';
|
import { useTimer } from "@/components/composables/useTimer";
|
||||||
import { continueSession, pauseSession, endSession, startOrContinueStudySession } from '@/api/studySessions';
|
import {
|
||||||
import { useStudyFragment } from '@/components/composables/fragment';
|
continueSession,
|
||||||
|
endSession,
|
||||||
|
pauseSession,
|
||||||
|
startOrContinueStudySession,
|
||||||
|
} from "@/api/studySessions";
|
||||||
|
import { useStudyFragment } from "@/components/composables/fragment";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -13,49 +17,138 @@ const {
|
|||||||
fragmentContent,
|
fragmentContent,
|
||||||
openFragmentDialog,
|
openFragmentDialog,
|
||||||
closeFragmentDialog,
|
closeFragmentDialog,
|
||||||
confirmGenerateFragment
|
confirmGenerateFragment,
|
||||||
} = useStudyFragment();
|
} = useStudyFragment();
|
||||||
|
|
||||||
const summaryDialogVisible = ref(false);
|
const summaryDialogVisible = ref(false);
|
||||||
const summaryContent = ref('');
|
const summaryContent = ref("");
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const taskNum = route.params.taskNum as string;
|
const taskNum = route.params.taskNum as string;
|
||||||
|
|
||||||
const taskInfo = ref({
|
const taskInfo = ref({
|
||||||
sessionNum: '',
|
sessionNum: "",
|
||||||
sessionState: '--',
|
sessionState: "--",
|
||||||
taskName: '',
|
taskName: "",
|
||||||
taskNum,
|
taskNum,
|
||||||
startTime: '',
|
startTime: "",
|
||||||
endTime: '',
|
endTime: "",
|
||||||
lastStartTime: '',
|
lastStartTime: "",
|
||||||
actualTime: 0,
|
actualTime: 0,
|
||||||
effectiveTime: 0,
|
effectiveTime: 0,
|
||||||
effectivenessRatio: '--',
|
effectivenessRatio: "--",
|
||||||
pointerPosition: 0,
|
pointerPosition: 0,
|
||||||
systemMessage: '',
|
systemMessage: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
timerMinutes,
|
timerMinutes,
|
||||||
timerSeconds,
|
timerSeconds,
|
||||||
runCountdown,
|
runCountdown,
|
||||||
|
syncDisplay,
|
||||||
clear,
|
clear,
|
||||||
timerRunning,
|
timerRunning,
|
||||||
timerIsOver,
|
timerIsOver,
|
||||||
checkAudioPermission,
|
checkAudioPermission,
|
||||||
requestAudioPermission
|
requestAudioPermission,
|
||||||
} = useTimer();
|
} = useTimer();
|
||||||
|
|
||||||
const progress = computed(() =>
|
const progress = computed(() => ((timerMinutes.value * 60 + timerSeconds.value) / (25 * 60)) * 100);
|
||||||
((timerMinutes.value * 60 + timerSeconds.value) / (25 * 60)) * 100
|
const nowTimestamp = ref(Date.now());
|
||||||
);
|
|
||||||
|
let displayInterval: number | undefined;
|
||||||
|
|
||||||
|
const formatDuration = (value: number | string) => {
|
||||||
|
const totalSeconds = Math.max(0, Math.floor(Number(value) || 0));
|
||||||
|
const hours = Math.floor(totalSeconds / 3600);
|
||||||
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||||
|
const seconds = totalSeconds % 60;
|
||||||
|
|
||||||
|
if (hours > 0) {
|
||||||
|
return `${hours}小时 ${minutes}分 ${seconds.toString().padStart(2, "0")}秒`;
|
||||||
|
}
|
||||||
|
if (minutes > 0) {
|
||||||
|
return `${minutes}分 ${seconds.toString().padStart(2, "0")}秒`;
|
||||||
|
}
|
||||||
|
return `${seconds}秒`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const toDate = (value: unknown): Date | null => {
|
||||||
|
if (value == null || value === "") return null;
|
||||||
|
|
||||||
|
if (value instanceof Date) {
|
||||||
|
return Number.isNaN(value.getTime()) ? null : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === "number") {
|
||||||
|
const date = new Date(value);
|
||||||
|
return Number.isNaN(date.getTime()) ? null : date;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
const [year, month, day, hour = 0, minute = 0, second = 0] = value.map(Number);
|
||||||
|
if (!year || !month || !day) return null;
|
||||||
|
const date = new Date(year, month - 1, day, hour, minute, second);
|
||||||
|
return Number.isNaN(date.getTime()) ? null : date;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === "string") {
|
||||||
|
const normalized = value.includes("T") ? value : value.replace(" ", "T");
|
||||||
|
const date = new Date(normalized);
|
||||||
|
return Number.isNaN(date.getTime()) ? null : date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const toSeconds = (start: Date, endTimestamp: number) => {
|
||||||
|
return Math.max(0, Math.floor((endTimestamp - start.getTime()) / 1000));
|
||||||
|
};
|
||||||
|
|
||||||
|
const actualTimeSeconds = computed(() => {
|
||||||
|
const fallback = Math.max(0, Math.floor(Number(taskInfo.value.actualTime) || 0));
|
||||||
|
const startDate = toDate(taskInfo.value.startTime);
|
||||||
|
if (!startDate) return fallback;
|
||||||
|
|
||||||
|
// 实际用时:开始后持续计时,暂停时也继续累计,结束后冻结。
|
||||||
|
if (taskInfo.value.sessionState === "ENDED") {
|
||||||
|
const endDate = toDate(taskInfo.value.endTime);
|
||||||
|
if (!endDate) return fallback;
|
||||||
|
return toSeconds(startDate, endDate.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
return toSeconds(startDate, nowTimestamp.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const effectiveTimeSeconds = computed(() => {
|
||||||
|
const base = Math.max(0, Math.floor(Number(taskInfo.value.effectiveTime) || 0));
|
||||||
|
if (taskInfo.value.sessionState !== "ONGOING") return base;
|
||||||
|
|
||||||
|
const lastStartDate = toDate(taskInfo.value.lastStartTime);
|
||||||
|
if (!lastStartDate) return base;
|
||||||
|
return base + toSeconds(lastStartDate, nowTimestamp.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const actualTimeText = computed(() => formatDuration(actualTimeSeconds.value));
|
||||||
|
const effectiveTimeText = computed(() => formatDuration(effectiveTimeSeconds.value));
|
||||||
|
|
||||||
|
const statusText = computed(() => {
|
||||||
|
switch (taskInfo.value.sessionState) {
|
||||||
|
case "ONGOING":
|
||||||
|
return "进行中";
|
||||||
|
case "PAUSED":
|
||||||
|
return "已暂停";
|
||||||
|
case "ENDED":
|
||||||
|
return "已结束";
|
||||||
|
default:
|
||||||
|
return "未开始";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const startTimer = async () => {
|
const startTimer = async () => {
|
||||||
if (taskInfo.value.sessionState === "PAUSED") {
|
if (taskInfo.value.sessionState === "PAUSED") {
|
||||||
const res = await continueSession(taskInfo.value.sessionNum);
|
const res = await continueSession(taskInfo.value.sessionNum);
|
||||||
if (res.code === 200) ElMessage.success('任务继续');
|
if (res.code === 200) ElMessage.success("任务继续");
|
||||||
await loadTaskSession();
|
await loadTaskSession();
|
||||||
}
|
}
|
||||||
const duration = taskInfo.value.pointerPosition || 25 * 60 * 1000;
|
const duration = taskInfo.value.pointerPosition || 25 * 60 * 1000;
|
||||||
@@ -64,41 +157,41 @@ const startTimer = async () => {
|
|||||||
|
|
||||||
const stopTimer = async () => {
|
const stopTimer = async () => {
|
||||||
const res = await pauseSession(taskInfo.value.sessionNum);
|
const res = await pauseSession(taskInfo.value.sessionNum);
|
||||||
if (res.code === 200) ElMessage.success('任务暂停');
|
if (res.code === 200) ElMessage.success("任务暂停");
|
||||||
clear();
|
clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
const endTimer = async (content: string) => {
|
const endTimer = async (content: string) => {
|
||||||
if (!content) {
|
if (!content) {
|
||||||
ElMessage.warning('请输入学习总结内容');
|
ElMessage.warning("请输入学习总结内容");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ElMessageBox.confirm('确定要结束吗?', '提示', {
|
try {
|
||||||
confirmButtonText: '确定',
|
await ElMessageBox.confirm("确定要结束本次学习会话吗?", "结束确认", {
|
||||||
cancelButtonText: '取消',
|
confirmButtonText: "确定",
|
||||||
type: 'info',
|
cancelButtonText: "取消",
|
||||||
}).then(async () => {
|
type: "warning",
|
||||||
|
});
|
||||||
|
|
||||||
const res = await endSession(taskInfo.value.sessionNum, content);
|
const res = await endSession(taskInfo.value.sessionNum, content);
|
||||||
if (res.code === 200) ElMessage.success('任务结束');
|
if (res.code === 200) {
|
||||||
router.back();
|
ElMessage.success("任务结束");
|
||||||
|
}
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
})
|
window.location.assign("/study");
|
||||||
|
} catch {
|
||||||
|
// 用户取消结束会话,或接口异常时由请求层统一提示
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const openSummaryDialog = async () => {
|
const openSummaryDialog = () => {
|
||||||
summaryDialogVisible.value = true;
|
summaryDialogVisible.value = true;
|
||||||
}
|
};
|
||||||
|
|
||||||
const closeSummaryDialog = async () => {
|
const closeSummaryDialog = () => {
|
||||||
ElMessageBox.alert('确定取消吗?', '提示', {
|
summaryDialogVisible.value = false;
|
||||||
confirmButtonText: '确定',
|
};
|
||||||
cancelButtonText: '取消',
|
|
||||||
type: 'warning',
|
|
||||||
}).then(() => {
|
|
||||||
summaryDialogVisible.value = false;
|
|
||||||
ElMessage.info('已取消结束操作')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const restTimer = async () => {
|
const restTimer = async () => {
|
||||||
await stopTimer();
|
await stopTimer();
|
||||||
@@ -109,14 +202,13 @@ const loadTaskSession = async () => {
|
|||||||
try {
|
try {
|
||||||
const res = await startOrContinueStudySession(taskNum);
|
const res = await startOrContinueStudySession(taskNum);
|
||||||
Object.assign(taskInfo.value, res.data);
|
Object.assign(taskInfo.value, res.data);
|
||||||
if (taskInfo.value.sessionState === 'ONGOING') {
|
if (taskInfo.value.sessionState === "ONGOING") {
|
||||||
startTimer();
|
startTimer();
|
||||||
}
|
} else {
|
||||||
if (taskInfo.value.systemMessage) {
|
syncDisplay(taskInfo.value.pointerPosition || 25 * 60 * 1000);
|
||||||
ElMessage.warning(taskInfo.value.systemMessage);
|
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
ElMessage.error(err.message || '加载任务失败');
|
ElMessage.error(err.message || "加载任务失败");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,107 +216,230 @@ const initPage = async () => {
|
|||||||
const hasPermission = await checkAudioPermission();
|
const hasPermission = await checkAudioPermission();
|
||||||
if (!hasPermission) {
|
if (!hasPermission) {
|
||||||
const activated = await requestAudioPermission();
|
const activated = await requestAudioPermission();
|
||||||
if (!activated) {
|
if (!activated) return;
|
||||||
console.warn('用户拒绝或未能激活权限');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await loadTaskSession();
|
await loadTaskSession();
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
displayInterval = window.setInterval(() => {
|
||||||
|
nowTimestamp.value = Date.now();
|
||||||
|
}, 1000);
|
||||||
initPage();
|
initPage();
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
if (displayInterval) {
|
||||||
|
clearInterval(displayInterval);
|
||||||
|
}
|
||||||
clear();
|
clear();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="task-container">
|
<section class="start-page">
|
||||||
|
<header class="surface-card top-head">
|
||||||
|
<div>
|
||||||
|
<h1 class="page-title">{{ taskInfo.taskName || "学习会话" }}</h1>
|
||||||
|
<p class="page-subtitle">状态:{{ statusText }}</p>
|
||||||
|
</div>
|
||||||
|
<el-tag type="success" effect="plain">任务编号:{{ taskInfo.taskNum }}</el-tag>
|
||||||
|
</header>
|
||||||
|
|
||||||
<el-alert
|
<el-alert
|
||||||
v-if="taskInfo.systemMessage"
|
v-if="taskInfo.systemMessage"
|
||||||
:title="taskInfo.systemMessage"
|
:title="taskInfo.systemMessage"
|
||||||
type="warning"
|
type="warning"
|
||||||
show-icon
|
show-icon
|
||||||
:closable="false"
|
:closable="false"
|
||||||
class="session-alert"
|
|
||||||
/>
|
/>
|
||||||
<div class="task-info">
|
|
||||||
<p>当前任务【{{ taskInfo.taskName }}】</p>
|
<div class="session-grid">
|
||||||
<p>会话状态:{{ taskInfo.sessionState }}</p>
|
<article class="surface-card timer-card">
|
||||||
<p>实际用时:{{ taskInfo.actualTime }}</p>
|
<p class="timer-title">当前计时</p>
|
||||||
<p>有效学习时长:{{ taskInfo.effectiveTime }}</p>
|
<el-progress type="dashboard" :percentage="progress" :stroke-width="14" :width="250" color="#2f8f68">
|
||||||
<p>有效时间比:{{ taskInfo.effectivenessRatio }}</p>
|
<div class="timer-number">
|
||||||
</div>
|
{{ timerMinutes.toString().padStart(2, "0") }}:{{ timerSeconds.toString().padStart(2, "0") }}
|
||||||
<div class="timer-section">
|
</div>
|
||||||
<el-progress type="circle" :percentage="progress" :width="200">
|
</el-progress>
|
||||||
<div>
|
<p class="timer-tip">番茄钟默认 25 分钟,休息计时 5 分钟</p>
|
||||||
{{ timerMinutes.toString().padStart(2, '0') }} :
|
</article>
|
||||||
{{ timerSeconds.toString().padStart(2, '0') }}
|
|
||||||
|
<article class="surface-card info-card">
|
||||||
|
<h3>会话数据</h3>
|
||||||
|
<div class="info-grid">
|
||||||
|
<div class="metric">
|
||||||
|
<span>实际用时</span>
|
||||||
|
<strong>{{ actualTimeText }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="metric">
|
||||||
|
<span>有效学习时长</span>
|
||||||
|
<strong>{{ effectiveTimeText }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="metric">
|
||||||
|
<span>有效时间比</span>
|
||||||
|
<strong>{{ taskInfo.effectivenessRatio }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="metric">
|
||||||
|
<span>会话状态</span>
|
||||||
|
<strong>{{ statusText }}</strong>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-progress>
|
|
||||||
|
<div class="action-row">
|
||||||
|
<el-button type="success" @click="startTimer" :disabled="timerRunning">开始</el-button>
|
||||||
|
<el-button @click="stopTimer" :disabled="!timerRunning" v-if="!timerIsOver">暂停</el-button>
|
||||||
|
<el-button @click="openFragmentDialog" :disabled="!timerRunning">生成残片</el-button>
|
||||||
|
<el-button v-if="timerIsOver" plain type="success" @click="restTimer">休息</el-button>
|
||||||
|
<el-button type="danger" plain @click="openSummaryDialog">结束会话</el-button>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
</section>
|
||||||
<el-button @click="startTimer" :disabled="timerRunning">开始</el-button>
|
|
||||||
<el-button @click="stopTimer" :disabled="!timerRunning" v-if="!timerIsOver">暂停</el-button>
|
<el-dialog v-model="fragmentsDialogVisible" title="生成学习残片" width="520px">
|
||||||
<el-button @click="openFragmentDialog" :disabled="!timerRunning">生成学习残片</el-button>
|
|
||||||
<el-button @click="restTimer" v-if="timerIsOver">休息</el-button>
|
|
||||||
<el-button @click="openSummaryDialog">结束</el-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<el-dialog v-model="fragmentsDialogVisible" title="生成学习残片" width="500px">
|
|
||||||
<el-input
|
<el-input
|
||||||
type="textarea"
|
type="textarea"
|
||||||
v-model="fragmentContent"
|
v-model="fragmentContent"
|
||||||
placeholder="请输入本次学习的内容"
|
placeholder="请输入本次学习内容"
|
||||||
rows="5"
|
:rows="5"
|
||||||
/>
|
/>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span>
|
<el-button @click="closeFragmentDialog">取消</el-button>
|
||||||
<el-button @click="closeFragmentDialog">取消生成</el-button>
|
<el-button type="success" @click="confirmGenerateFragment(taskInfo.sessionNum)">确定生成</el-button>
|
||||||
<el-button type="primary" @click="confirmGenerateFragment(taskInfo.sessionNum)">确定生成</el-button>
|
|
||||||
</span>
|
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
<el-dialog v-model="summaryDialogVisible" title="本次学习内容总结" width="500px">
|
|
||||||
|
<el-dialog v-model="summaryDialogVisible" title="结束会话总结" width="520px">
|
||||||
<el-input
|
<el-input
|
||||||
type="textarea"
|
type="textarea"
|
||||||
v-model="summaryContent"
|
v-model="summaryContent"
|
||||||
placeholder="请输入本次学习的内容总结"
|
placeholder="请输入本次学习内容总结"
|
||||||
rows="5"
|
:rows="5"
|
||||||
/>
|
/>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span>
|
|
||||||
<el-button @click="closeSummaryDialog">取消</el-button>
|
<el-button @click="closeSummaryDialog">取消</el-button>
|
||||||
<el-button type="primary" @click="endTimer(summaryContent)">确定</el-button>
|
<el-button type="success" @click="endTimer(summaryContent)">确认结束</el-button>
|
||||||
</span>
|
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.task-container {
|
.start-page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-head {
|
||||||
|
padding: 18px 20px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.session-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 380px 1fr;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timer-card {
|
||||||
|
padding: 20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: 20px;
|
|
||||||
}
|
}
|
||||||
.session-alert {
|
|
||||||
margin-bottom: 16px;
|
.timer-title {
|
||||||
max-width: 500px;
|
margin: 0;
|
||||||
|
color: var(--green-900);
|
||||||
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
.task-info {
|
|
||||||
font-size: 18px;
|
.timer-number {
|
||||||
margin-bottom: 30px;
|
font-size: 28px;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
color: var(--green-900);
|
||||||
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
.timer-section {
|
|
||||||
margin: 20px;
|
.timer-tip {
|
||||||
|
margin: 14px 0 0;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
.actions {
|
|
||||||
display: flex;
|
.info-card {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-card h3 {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--green-900);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-grid {
|
||||||
|
margin-top: 14px;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.metric {
|
||||||
|
border: 1px solid var(--border-soft);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
background: #fbfefc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric span {
|
||||||
|
display: block;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric strong {
|
||||||
|
margin-top: 6px;
|
||||||
|
display: block;
|
||||||
|
font-size: 18px;
|
||||||
|
color: var(--green-900);
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-row {
|
||||||
|
margin-top: 14px;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-row .el-button {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1100px) {
|
||||||
|
.session-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.top-head {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-row {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-row .el-button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+252
-123
@@ -1,28 +1,48 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted } from 'vue';
|
import { computed, onMounted, ref } from "vue";
|
||||||
import request from '@/utils/request';
|
import request from "@/utils/request";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
import {ElMessage} from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
|
|
||||||
const tasks = reactive([] as any[]);
|
interface TaskItem {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
materialURL: string;
|
||||||
|
lastLearningStatus: string;
|
||||||
|
priority: number | string;
|
||||||
|
taskNum: string;
|
||||||
|
taskId: number;
|
||||||
|
}
|
||||||
|
|
||||||
const selectedTask = ref<any>(null);
|
const tasks = ref<TaskItem[]>([]);
|
||||||
|
const selectedTaskId = ref<number | null>(null);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
const fetchTasks = () => {
|
const selectedTask = computed(() =>
|
||||||
request.get('/tasks', { pageSize: 100, pageNum: 1 })
|
tasks.value.find((item) => item.taskId === selectedTaskId.value) || null
|
||||||
.then((res) => {
|
);
|
||||||
/* 此处暂时不开发分页模式,数据量应该不会很大,但仍然保留了分页形式的接口 */
|
|
||||||
tasks.splice(0, tasks.length, ...res.data.records.map((record: any) => ({
|
const fetchTasks = async () => {
|
||||||
title: record.taskName,
|
loading.value = true;
|
||||||
description: record.taskDescription || '',
|
try {
|
||||||
materialURL: record.materialURL || record.materialUrl || "",
|
const res = await request.get("/tasks", { pageSize: 100, pageNum: 1 });
|
||||||
lastLearningStatus: record.lastLearningStatus || '未开始',
|
tasks.value = (res?.data?.records || []).map((record: any) => ({
|
||||||
priority: Number.isFinite(record.taskPriority) ? Math.round(record.taskPriority) : "-",
|
title: record.taskName,
|
||||||
taskNum: record.taskNum,
|
description: record.taskDescription || "",
|
||||||
taskId: record.id,
|
materialURL: record.materialURL || record.materialUrl || "",
|
||||||
})));
|
lastLearningStatus: record.lastLearningStatus || "未开始",
|
||||||
selectedTask.value = tasks[0] || null;
|
priority: Number.isFinite(record.taskPriority) ? Math.round(record.taskPriority) : "-",
|
||||||
});
|
taskNum: record.taskNum,
|
||||||
|
taskId: record.id,
|
||||||
|
}));
|
||||||
|
selectedTaskId.value = tasks.value[0]?.taskId ?? null;
|
||||||
|
} catch (error: any) {
|
||||||
|
tasks.value = [];
|
||||||
|
selectedTaskId.value = null;
|
||||||
|
ElMessage.error(error?.message || "任务列表加载失败,请重试");
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const startTask = () => {
|
const startTask = () => {
|
||||||
@@ -30,40 +50,33 @@ const startTask = () => {
|
|||||||
ElMessage.warning("请先选择一个任务");
|
ElMessage.warning("请先选择一个任务");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
router.push({name:'start-task',params:{taskNum:selectedTask.value.taskNum}});
|
window.location.assign(`/start-task/${encodeURIComponent(selectedTask.value.taskNum)}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addTask = () => {
|
const addTask = () => {
|
||||||
router.push({name:"add-task"});
|
router.push({ name: "add-task" });
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeTask = () =>{
|
const changeTask = () => {
|
||||||
if (!selectedTask.value) {
|
if (!selectedTask.value) {
|
||||||
ElMessage.warning("请先选择一个任务");
|
ElMessage.warning("请先选择一个任务");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
router.push({name:"update-task",params:{"taskId":selectedTask.value.taskId}})
|
router.push({ name: "update-task", params: { taskId: selectedTask.value.taskId } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeTask = () => {
|
const removeTask = async () => {
|
||||||
if (!selectedTask.value) {
|
if (!selectedTask.value) {
|
||||||
ElMessage.warning("请先选择一个任务");
|
ElMessage.warning("请先选择一个任务");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
request.del(`/tasks/${selectedTask.value.taskId}`,{}).then(res=>{
|
const target = selectedTask.value;
|
||||||
if (res.code === 200){
|
const res = await request.del(`/tasks/${target.taskId}`, {});
|
||||||
ElMessage.success(`任务${selectedTask.value.title}删除成功`)
|
if (res.code === 200) {
|
||||||
const index = tasks.indexOf(selectedTask.value);
|
ElMessage.success(`任务 ${target.title} 删除成功`);
|
||||||
if (index > -1) {
|
tasks.value = tasks.value.filter((item) => item.taskId !== target.taskId);
|
||||||
tasks.splice(index, 1);
|
selectedTaskId.value = tasks.value[0]?.taskId ?? null;
|
||||||
selectedTask.value = tasks[0] || null;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const selectTask = (task: any) => {
|
|
||||||
selectedTask.value = task;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -72,99 +85,215 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-row :gutter="5" class="task-layout">
|
<section class="study-page">
|
||||||
<el-col :span="6">
|
<header class="surface-card page-head">
|
||||||
<el-card class="task-card" :body-style="{ padding: '0' }">
|
<div>
|
||||||
<div class="task-header">任务列表</div>
|
<h1 class="page-title">学习任务</h1>
|
||||||
<el-scrollbar height="300px">
|
<p class="page-subtitle">先选任务,再确认材料与优先级,然后开始一次学习会话</p>
|
||||||
<el-menu class="task-menu" @select="(key:any) => selectTask(tasks[key])">
|
</div>
|
||||||
<el-menu-item
|
<el-button type="success" plain @click="fetchTasks" :loading="loading">刷新列表</el-button>
|
||||||
v-for="(task, index) in tasks"
|
</header>
|
||||||
:key="index"
|
|
||||||
:index="index.toString()"
|
<div class="layout-grid">
|
||||||
class="task-item"
|
<aside class="surface-card task-list">
|
||||||
>
|
<div class="block-title">任务清单</div>
|
||||||
{{ task.title }}
|
<el-scrollbar height="420px">
|
||||||
</el-menu-item>
|
<div
|
||||||
</el-menu>
|
v-for="item in tasks"
|
||||||
|
:key="item.taskId"
|
||||||
|
class="task-list-item"
|
||||||
|
:class="{ active: selectedTaskId === item.taskId }"
|
||||||
|
@click="selectedTaskId = item.taskId"
|
||||||
|
>
|
||||||
|
<p class="task-name">{{ item.title }}</p>
|
||||||
|
<p class="task-meta">状态:{{ item.lastLearningStatus }}</p>
|
||||||
|
</div>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
</el-card>
|
</aside>
|
||||||
</el-col>
|
|
||||||
|
|
||||||
<el-col :span="13">
|
<main class="content-zone">
|
||||||
<el-card class="task-card">
|
<article class="surface-card detail-card" v-loading="loading">
|
||||||
<div v-if="selectedTask">
|
<template v-if="selectedTask">
|
||||||
<h3>任务描述</h3>
|
<div class="detail-head">
|
||||||
<el-input type="textarea" :model-value="selectedTask.description" :rows="4" readonly />
|
<h3>{{ selectedTask.title }}</h3>
|
||||||
|
<el-tag type="success" effect="plain">优先级 {{ selectedTask.priority }}</el-tag>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h3 class="section-title">学习材料</h3>
|
<div class="detail-block">
|
||||||
<el-link v-if="selectedTask.materialURL" :href="selectedTask.materialURL" type="primary" target="_blank">
|
<p class="label">任务描述</p>
|
||||||
{{ selectedTask.materialURL }}
|
<el-input type="textarea" :model-value="selectedTask.description" :rows="4" readonly />
|
||||||
</el-link>
|
</div>
|
||||||
<span v-else>未填写材料地址</span>
|
|
||||||
|
|
||||||
<h3 class="section-title">任务优先级</h3>
|
<div class="detail-block">
|
||||||
<el-tag type="info">综合优先级:{{ selectedTask.priority }}</el-tag>
|
<p class="label">学习材料</p>
|
||||||
|
<el-link
|
||||||
|
v-if="selectedTask.materialURL"
|
||||||
|
:href="selectedTask.materialURL"
|
||||||
|
target="_blank"
|
||||||
|
type="primary"
|
||||||
|
>
|
||||||
|
{{ selectedTask.materialURL }}
|
||||||
|
</el-link>
|
||||||
|
<p v-else class="empty-text">暂未填写材料地址</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-empty v-else description="暂无任务,请先创建任务" />
|
||||||
|
</article>
|
||||||
|
|
||||||
<h3 class="section-title">上次该任务学习情况</h3>
|
<aside class="surface-card action-card">
|
||||||
<el-descriptions border column="1">
|
<div class="block-title">常用操作</div>
|
||||||
<el-descriptions-item label="有效时间比">0.5</el-descriptions-item>
|
<el-button type="success" size="large" @click="startTask">开始任务</el-button>
|
||||||
<el-descriptions-item label="实际用时">2小时</el-descriptions-item>
|
<el-button size="large" @click="addTask">添加任务</el-button>
|
||||||
<el-descriptions-item label="有效学习时间">1小时</el-descriptions-item>
|
<el-button size="large" @click="changeTask">更新任务</el-button>
|
||||||
<el-descriptions-item label="备注">学习了“动态面板”的基本使用方式</el-descriptions-item>
|
<el-button type="danger" size="large" @click="removeTask">删除任务</el-button>
|
||||||
</el-descriptions>
|
</aside>
|
||||||
</div>
|
</main>
|
||||||
<div v-else>
|
</div>
|
||||||
<p>请选择任务或等待任务加载完成。</p>
|
</section>
|
||||||
</div>
|
|
||||||
</el-card>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="5">
|
|
||||||
<el-space class="action-buttons">
|
|
||||||
<el-button type="primary" @click="startTask">开始任务</el-button>
|
|
||||||
<el-button @click="addTask">添加任务</el-button>
|
|
||||||
<el-button @click="changeTask">更新任务</el-button>
|
|
||||||
<el-button type="danger" @click="removeTask">删除任务</el-button>
|
|
||||||
<el-button type="info" @click="fetchTasks"> 刷新 </el-button>
|
|
||||||
</el-space>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.task-layout {
|
.study-page {
|
||||||
width: 100%;
|
display: flex;
|
||||||
overflow-x: hidden;
|
|
||||||
}
|
|
||||||
.task-card {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
.task-header {
|
|
||||||
padding: 10px;
|
|
||||||
font-size: 16px;
|
|
||||||
font-weight: bold;
|
|
||||||
background-color: #f5f7fa;
|
|
||||||
border-bottom: 1px solid #ebeef5;
|
|
||||||
}
|
|
||||||
.task-menu {
|
|
||||||
width: 100%;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
.task-item {
|
|
||||||
padding: 10px 12px;
|
|
||||||
white-space: normal;
|
|
||||||
word-break: break-word;
|
|
||||||
}
|
|
||||||
.section-title {
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
|
||||||
.action-buttons {
|
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
margin-top: 20px;
|
gap: 14px;
|
||||||
}
|
}
|
||||||
.action-buttons .el-button {
|
|
||||||
width: 8vw;
|
.page-head {
|
||||||
min-width: 70px;
|
padding: 18px 20px;
|
||||||
margin-top: 5px;
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 280px 1fr;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-list {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.block-title {
|
||||||
|
margin: 0 0 12px;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--green-900);
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-list-item {
|
||||||
|
border: 1px solid var(--border-soft);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
background: #fbfefc;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-list-item + .task-list-item {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-list-item:hover {
|
||||||
|
border-color: #b9d9c8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-list-item.active {
|
||||||
|
border-color: var(--green-600);
|
||||||
|
background: var(--green-100);
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(47, 143, 104, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-name {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-meta {
|
||||||
|
margin: 4px 0 0;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-zone {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 220px;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-card {
|
||||||
|
padding: 18px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-head h3 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-block {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-text {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-card {
|
||||||
|
padding: 16px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-card .el-button {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1100px) {
|
||||||
|
.layout-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-zone {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-card {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-card .block-title {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.page-head {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-card {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ export function useTimer(audioUrl: string = '/resource/notification.mp3') {
|
|||||||
timerRunning.value = false;
|
timerRunning.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const syncDisplay = (durationMs: number) => {
|
||||||
|
const safeDuration = Math.max(durationMs, 0);
|
||||||
|
remainingTime.value = safeDuration;
|
||||||
|
timerMinutes.value = Math.floor(safeDuration / 1000 / 60);
|
||||||
|
timerSeconds.value = Math.floor((safeDuration / 1000) % 60);
|
||||||
|
timerIsOver.value = safeDuration === 0;
|
||||||
|
};
|
||||||
|
|
||||||
const handleCountdownComplete = () => {
|
const handleCountdownComplete = () => {
|
||||||
audio.loop = true;
|
audio.loop = true;
|
||||||
audio.play();
|
audio.play();
|
||||||
@@ -91,6 +99,7 @@ export function useTimer(audioUrl: string = '/resource/notification.mp3') {
|
|||||||
timerRunning,
|
timerRunning,
|
||||||
timerIsOver,
|
timerIsOver,
|
||||||
runCountdown,
|
runCountdown,
|
||||||
|
syncDisplay,
|
||||||
clear,
|
clear,
|
||||||
checkAudioPermission,
|
checkAudioPermission,
|
||||||
requestAudioPermission,
|
requestAudioPermission,
|
||||||
|
|||||||
+14
-1
@@ -1,4 +1,5 @@
|
|||||||
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
|
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
|
||||||
|
import StartTask from "@/components/StartTask.vue";
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
const routes: RouteRecordRaw[] = [
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,7 @@ const routes: RouteRecordRaw[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/study",
|
path: "/study",
|
||||||
|
name: "study",
|
||||||
component: () => import("@/components/Study.vue"),
|
component: () => import("@/components/Study.vue"),
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true },
|
||||||
},
|
},
|
||||||
@@ -28,7 +30,7 @@ const routes: RouteRecordRaw[] = [
|
|||||||
{
|
{
|
||||||
path: "/start-task/:taskNum",
|
path: "/start-task/:taskNum",
|
||||||
name: "start-task",
|
name: "start-task",
|
||||||
component: () => import("@/components/StartTask.vue"),
|
component: StartTask,
|
||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -58,6 +60,17 @@ const router = createRouter({
|
|||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.onError((error, to) => {
|
||||||
|
const message = String((error as Error)?.message || "");
|
||||||
|
const isChunkLoadError =
|
||||||
|
message.includes("Failed to fetch dynamically imported module") ||
|
||||||
|
message.includes("Importing a module script failed") ||
|
||||||
|
message.includes("Loading chunk");
|
||||||
|
if (isChunkLoadError && typeof window !== "undefined") {
|
||||||
|
window.location.assign(to.fullPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
router.beforeEach((to) => {
|
router.beforeEach((to) => {
|
||||||
if (to.meta.requiresAuth === false) return true;
|
if (to.meta.requiresAuth === false) return true;
|
||||||
const isLoggedIn = localStorage.getItem("isLoggedIn") === "true";
|
const isLoggedIn = localStorage.getItem("isLoggedIn") === "true";
|
||||||
|
|||||||
Reference in New Issue
Block a user