fix: 任务开始后显示已开启和学时刷新倒计时
This commit is contained in:
@@ -74,6 +74,8 @@ const studyControl = ref({
|
||||
workers: [] as StudyWorker[],
|
||||
});
|
||||
const studyBusy = ref(false);
|
||||
const hoursRefreshIn = ref(0);
|
||||
const hoursRefreshSeen = ref(0);
|
||||
const studyError = ref("");
|
||||
|
||||
const studyingWorkers = computed(() => (
|
||||
@@ -104,8 +106,7 @@ const studyLabel = computed(() => {
|
||||
if (studyFailed.value) return message || state;
|
||||
if (state === "排队中") return "排队中";
|
||||
if (state === "准备") return "正在连接学习平台";
|
||||
if (studyingWorkers.value.length) return studyControl.value.course || "学习中";
|
||||
if (state === "学习中") return "正在领取课程";
|
||||
if (studyingWorkers.value.length || state === "学习中") return "任务已开启";
|
||||
if (studyControl.value.active || studyControl.value.started) return "正在启动学习任务";
|
||||
if (state === "已停止" || studyControl.value.paused) return "任务已停止";
|
||||
if (state === "已学完") return "课程已学完";
|
||||
@@ -223,6 +224,14 @@ function workerCount(row: StudyWorker) {
|
||||
return "—";
|
||||
}
|
||||
|
||||
const showHoursRefresh = computed(() => studyLabel.value === "任务已开启" && hoursRefreshIn.value > 0);
|
||||
|
||||
function hoursRefreshLeft() {
|
||||
void nowTick.value;
|
||||
const elapsed = (Date.now() - hoursRefreshSeen.value) / 1000;
|
||||
return Math.max(0, Math.ceil(hoursRefreshIn.value - elapsed));
|
||||
}
|
||||
|
||||
function heartbeatLeft(row: StudyWorker) {
|
||||
void nowTick.value;
|
||||
if (row.heartbeat_in > 0) {
|
||||
@@ -564,6 +573,12 @@ function applyStudyControl(payload: Record<string, unknown>) {
|
||||
workers: asWorkers(payload.workers),
|
||||
};
|
||||
const studying = payload.active === true || payload.started === true;
|
||||
if (studying && typeof payload.hours_refresh_in === "number" && payload.hours_refresh_in > 0) {
|
||||
hoursRefreshIn.value = payload.hours_refresh_in;
|
||||
hoursRefreshSeen.value = Date.now();
|
||||
} else if (!studying) {
|
||||
hoursRefreshIn.value = 0;
|
||||
}
|
||||
if (studying && typeof payload.month_hours === "string" && payload.month_hours) {
|
||||
progressHours.value = payload.month_hours;
|
||||
if (summary.value) summary.value = { ...summary.value, month_hours: payload.month_hours };
|
||||
@@ -741,8 +756,8 @@ function onStudyVisible() {
|
||||
if (document.visibilityState === "visible") studyWake();
|
||||
}
|
||||
|
||||
watch(countdownOn, (on) => {
|
||||
if (on) startStudyTick();
|
||||
watch([countdownOn, showHoursRefresh], ([heart, hours]) => {
|
||||
if (heart || hours) startStudyTick();
|
||||
else stopStudyTick();
|
||||
});
|
||||
|
||||
@@ -926,6 +941,7 @@ onUnmounted(() => {
|
||||
}"
|
||||
></span>
|
||||
<span class="study-text" aria-live="polite" :class="{ muted: !studyControl.started && !studyControl.active }">{{ studyLabel }}</span>
|
||||
<span v-if="showHoursRefresh" class="study-text muted">刷新学时 {{ hoursRefreshLeft() }}s</span>
|
||||
</div>
|
||||
<div v-if="targetLoaded" class="study-progress">
|
||||
<div class="study-progress-meta">
|
||||
|
||||
Reference in New Issue
Block a user