feat: 按账号调度自动学习并让首页实时跟上状态
This commit is contained in:
+379
-162
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NProgress, NSelect, NTimePicker, NTooltip } from "naive-ui";
|
||||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NProgress, NSelect, NSwitch, NTimePicker, NTooltip } from "naive-ui";
|
||||
import { GlobeOutline, HelpCircleOutline, PlayOutline, RefreshOutline, StopOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerHint, workerOptions } from "../../shared/studyFields";
|
||||
|
||||
@@ -23,6 +23,8 @@ interface StudyWorker {
|
||||
progress: number;
|
||||
interval: number;
|
||||
heartbeat_at: number;
|
||||
sent: number;
|
||||
total: number;
|
||||
ok: boolean;
|
||||
}
|
||||
|
||||
@@ -35,18 +37,27 @@ const summaryError = ref("");
|
||||
const refreshing = ref(false);
|
||||
let refreshRunning = false;
|
||||
let busy = false;
|
||||
let studyPoll = 0;
|
||||
let studyTick = 0;
|
||||
let studySocket: WebSocket | null = null;
|
||||
let studyReconnect = 0;
|
||||
let studyPing = 0;
|
||||
let studyFallback = 0;
|
||||
let studyBackoff = 1000;
|
||||
let studyClosed = false;
|
||||
const nowTick = ref(Date.now());
|
||||
|
||||
const monthlyTarget = ref<number | null>(null);
|
||||
const targetLoaded = ref(false);
|
||||
let targetSaveTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
const scheduleSaving = ref(false);
|
||||
const scheduleError = ref("");
|
||||
|
||||
const studyControl = ref({
|
||||
started: false,
|
||||
paused: false,
|
||||
ignore_window: false,
|
||||
window_open: false,
|
||||
hours_met: false,
|
||||
schedule_enabled: true,
|
||||
active: false,
|
||||
state: "",
|
||||
course: "",
|
||||
@@ -56,19 +67,52 @@ const studyControl = ref({
|
||||
const studyBusy = ref(false);
|
||||
const studyError = ref("");
|
||||
|
||||
const studyingWorkers = computed(() => (
|
||||
studyControl.value.workers.filter((row) => row.course.trim() && workerPercent(row) < 100)
|
||||
));
|
||||
|
||||
const countdownOn = computed(() => (
|
||||
studyingWorkers.value.some((row) => row.interval > 0 && row.heartbeat_at > 0)
|
||||
));
|
||||
|
||||
const studyFailed = computed(() => {
|
||||
const state = studyControl.value.state;
|
||||
return state === "会话失效" || state === "学习失败";
|
||||
});
|
||||
|
||||
const monthProgress = computed(() => {
|
||||
const match = String(summary.value?.month_hours ?? "").match(/(\d+)/);
|
||||
const current = match ? Number(match[1]) : 0;
|
||||
const target = monthlyTarget.value ?? 0;
|
||||
const pct = target > 0 ? Math.min(100, Math.round((current * 100) / target)) : 0;
|
||||
return { current, target, pct };
|
||||
});
|
||||
|
||||
const studyLabel = computed(() => {
|
||||
const state = studyControl.value.state;
|
||||
const course = studyControl.value.course;
|
||||
if (state === "已达标") return "本月目标已达到";
|
||||
const message = studyControl.value.message.trim();
|
||||
if (studyControl.value.hours_met || state === "已达标") return "本月目标已达到";
|
||||
if (state === "已停止" || studyControl.value.paused) return "任务已停止";
|
||||
if (studyControl.value.active) {
|
||||
return `正在学习:${course || state || "准备中"}`;
|
||||
}
|
||||
if (studyControl.value.started) return "任务已开始,等待执行";
|
||||
if (studyControl.value.message) return studyControl.value.message;
|
||||
if (state === "已学完") return "课程已学完";
|
||||
if (studyFailed.value) return message || state;
|
||||
if (state === "准备") return "正在连接学习平台";
|
||||
if (studyingWorkers.value.length) return studyControl.value.course || "学习中";
|
||||
if (state === "学习中") return "正在领取课程";
|
||||
if (studyControl.value.active || studyControl.value.started) return "正在启动学习任务";
|
||||
if (!studyControl.value.schedule_enabled) return "未开启定时自动学习";
|
||||
if (message && !message.startsWith("下一次") && !message.startsWith("运行中")) return message;
|
||||
return "未到开始时间";
|
||||
});
|
||||
|
||||
const studyHint = computed(() => {
|
||||
if (studyingWorkers.value.length) return "";
|
||||
if (studyControl.value.hours_met) return "达到本月目标后不能再开始。改大目标并保存后才会再启动。";
|
||||
if (studyFailed.value) return "点立即开始或保存定时配置会再启动。";
|
||||
if (studyControl.value.started || studyControl.value.active) return "开始后会列出正在学的课。";
|
||||
if (!studyControl.value.schedule_enabled) return "关闭定时后,只能点立即开始。";
|
||||
return "到点后会自动开始。保存定时配置时,若已过点且未达标也会立刻启动。";
|
||||
});
|
||||
|
||||
function amount(value: string | number | null | undefined) {
|
||||
if (value === null || value === undefined || value === "") return "—";
|
||||
const numeric = Number(value);
|
||||
@@ -109,6 +153,8 @@ function asWorkers(value: unknown): StudyWorker[] {
|
||||
progress: typeof row.progress === "number" ? row.progress : 0,
|
||||
interval: typeof row.interval === "number" ? row.interval : 0,
|
||||
heartbeat_at: typeof row.heartbeat_at === "number" ? row.heartbeat_at : 0,
|
||||
sent: typeof row.sent === "number" ? row.sent : 0,
|
||||
total: typeof row.total === "number" ? row.total : 0,
|
||||
ok: row.ok !== false,
|
||||
});
|
||||
}
|
||||
@@ -125,11 +171,25 @@ function workerTitle(row: StudyWorker) {
|
||||
return "准备";
|
||||
}
|
||||
|
||||
function showHeartbeat(row: StudyWorker) {
|
||||
return row.interval > 0 && row.heartbeat_at > 0;
|
||||
}
|
||||
|
||||
function workerCount(row: StudyWorker) {
|
||||
if (row.total > 0) return `${row.sent}/${row.total}`;
|
||||
if (row.sent > 0) return `${row.sent}/—`;
|
||||
return "—";
|
||||
}
|
||||
|
||||
function heartbeatLeft(row: StudyWorker) {
|
||||
void nowTick.value;
|
||||
if (!row.heartbeat_at) return "—";
|
||||
const left = Math.max(0, Math.ceil(row.heartbeat_at - Date.now() / 1000));
|
||||
return `${left}s`;
|
||||
const now = Date.now() / 1000;
|
||||
const cycle = Math.max(0, row.interval);
|
||||
let left = row.heartbeat_at - now;
|
||||
if (left < 0 && cycle > 0) {
|
||||
left = cycle - ((now - row.heartbeat_at) % cycle);
|
||||
}
|
||||
return `${Math.max(0, Math.ceil(left))}s`;
|
||||
}
|
||||
|
||||
async function loadSummary() {
|
||||
@@ -181,28 +241,12 @@ async function loadTarget() {
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
function saveTarget(value: number | null) {
|
||||
if (value == null || !Number.isInteger(value) || value < 0 || value > 9999) return;
|
||||
clearTimeout(targetSaveTimer);
|
||||
targetSaveTimer = setTimeout(async () => {
|
||||
try {
|
||||
await fetch("/api/settings/monthly-target", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ monthly_target: value }),
|
||||
});
|
||||
} catch { /* 静默 */ }
|
||||
}, 600);
|
||||
}
|
||||
|
||||
watch(monthlyTarget, (v) => { if (targetLoaded.value) saveTarget(v); });
|
||||
|
||||
const startLoaded = ref(false);
|
||||
const scheduleEnabled = ref(true);
|
||||
const startDay = ref<number | null>(1);
|
||||
const startHour = ref<number | null>(0);
|
||||
const startMinute = ref<number | null>(0);
|
||||
const startSecond = ref<number | null>(0);
|
||||
let startSaveTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const startTime = computed({
|
||||
get() {
|
||||
@@ -227,37 +271,15 @@ async function loadStart() {
|
||||
startHour.value = typeof data.hour === "number" ? data.hour : 0;
|
||||
startMinute.value = typeof data.minute === "number" ? data.minute : 0;
|
||||
startSecond.value = typeof data.second === "number" ? data.second : 0;
|
||||
scheduleEnabled.value = data.enabled !== false;
|
||||
startLoaded.value = true;
|
||||
}
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
function saveStart() {
|
||||
const day = startDay.value;
|
||||
const hour = startHour.value;
|
||||
const minute = startMinute.value;
|
||||
const second = startSecond.value;
|
||||
if (
|
||||
day == null || hour == null || minute == null || second == null
|
||||
|| !Number.isInteger(day) || !Number.isInteger(hour) || !Number.isInteger(minute) || !Number.isInteger(second)
|
||||
) return;
|
||||
clearTimeout(startSaveTimer);
|
||||
startSaveTimer = setTimeout(async () => {
|
||||
try {
|
||||
await fetch("/api/settings/study-start", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ day, hour, minute, second }),
|
||||
});
|
||||
} catch { /* 静默 */ }
|
||||
}, 600);
|
||||
}
|
||||
|
||||
watch([startDay, startHour, startMinute, startSecond], () => { if (startLoaded.value) saveStart(); });
|
||||
|
||||
const workersLoaded = ref(false);
|
||||
const courseWorkers = ref<number | null>(1);
|
||||
let workersSaveTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
const scheduleReady = computed(() => targetLoaded.value && startLoaded.value && workersLoaded.value);
|
||||
|
||||
async function loadWorkers() {
|
||||
try {
|
||||
@@ -270,21 +292,52 @@ async function loadWorkers() {
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
function saveWorkers(value: number | null) {
|
||||
if (value == null || !Number.isInteger(value) || value < 1 || value > 8) return;
|
||||
clearTimeout(workersSaveTimer);
|
||||
workersSaveTimer = setTimeout(async () => {
|
||||
try {
|
||||
await fetch("/api/settings/course-workers", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ workers: value }),
|
||||
});
|
||||
} catch { /* 静默 */ }
|
||||
}, 600);
|
||||
async function putJson(url: string, body: Record<string, unknown>, fallback: string) {
|
||||
const res = await fetch(url, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(failureText(data, fallback));
|
||||
}
|
||||
|
||||
watch(courseWorkers, (v) => { if (workersLoaded.value) saveWorkers(v); });
|
||||
async function saveSchedule() {
|
||||
if (scheduleSaving.value || !scheduleReady.value) return;
|
||||
const target = monthlyTarget.value;
|
||||
const day = startDay.value;
|
||||
const hour = startHour.value;
|
||||
const minute = startMinute.value;
|
||||
const second = startSecond.value;
|
||||
const workers = courseWorkers.value;
|
||||
if (target == null || !Number.isInteger(target) || target < 0 || target > 9999) {
|
||||
scheduleError.value = "每月学时目标须为 0 到 9999 的整数";
|
||||
return;
|
||||
}
|
||||
if (
|
||||
day == null || hour == null || minute == null || second == null
|
||||
|| !Number.isInteger(day) || !Number.isInteger(hour) || !Number.isInteger(minute) || !Number.isInteger(second)
|
||||
) {
|
||||
scheduleError.value = "请填写完整的定时启动时间";
|
||||
return;
|
||||
}
|
||||
if (workers == null || !Number.isInteger(workers) || workers < 1 || workers > 8) {
|
||||
scheduleError.value = "线程数量须为 1 到 8";
|
||||
return;
|
||||
}
|
||||
scheduleSaving.value = true;
|
||||
scheduleError.value = "";
|
||||
try {
|
||||
await putJson("/api/settings/monthly-target", { monthly_target: target }, "没有保存每月目标。");
|
||||
await putJson("/api/settings/study-start", { day, hour, minute, second, enabled: scheduleEnabled.value }, "没有保存定时启动。");
|
||||
await putJson("/api/settings/course-workers", { workers }, "没有保存线程数量。");
|
||||
await loadStudyControl();
|
||||
} catch (exc) {
|
||||
scheduleError.value = exc instanceof Error ? exc.message : "没有保存。";
|
||||
} finally {
|
||||
scheduleSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const proxyOpen = ref(false);
|
||||
const proxyLoaded = ref(false);
|
||||
@@ -411,12 +464,17 @@ function applyStudyControl(payload: Record<string, unknown>) {
|
||||
paused: payload.paused === true,
|
||||
ignore_window: payload.ignore_window === true,
|
||||
window_open: payload.window_open === true,
|
||||
hours_met: payload.hours_met === true,
|
||||
schedule_enabled: payload.schedule_enabled !== false,
|
||||
active: payload.active === true,
|
||||
state: typeof payload.state === "string" ? payload.state : "",
|
||||
course: typeof payload.course === "string" ? payload.course : "",
|
||||
message: typeof payload.message === "string" ? payload.message : "",
|
||||
workers: asWorkers(payload.workers),
|
||||
};
|
||||
if (typeof payload.month_hours === "string" && summary.value) {
|
||||
summary.value = { ...summary.value, month_hours: payload.month_hours };
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStudyControl() {
|
||||
@@ -427,32 +485,148 @@ async function loadStudyControl() {
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
function startStudyPoll() {
|
||||
if (studyPoll) return;
|
||||
studyPoll = window.setInterval(() => {
|
||||
nowTick.value = Date.now();
|
||||
void loadStudyControl();
|
||||
}, 1000);
|
||||
function studySocketUrl() {
|
||||
const proto = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||||
return `${proto}//${window.location.host}/api/settings/study-control/ws`;
|
||||
}
|
||||
|
||||
function stopStudyPoll() {
|
||||
if (studyPoll) {
|
||||
window.clearInterval(studyPoll);
|
||||
studyPoll = 0;
|
||||
function stopStudyFallback() {
|
||||
if (studyFallback) {
|
||||
window.clearTimeout(studyFallback);
|
||||
studyFallback = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function startStudyFallback() {
|
||||
if (studyClosed) return;
|
||||
if (studyFallback) return;
|
||||
const tick = async () => {
|
||||
studyFallback = 0;
|
||||
await loadStudyControl();
|
||||
if (!studyClosed && (!studySocket || studySocket.readyState !== WebSocket.OPEN)) {
|
||||
studyFallback = window.setTimeout(tick, 3000);
|
||||
}
|
||||
};
|
||||
void tick();
|
||||
}
|
||||
|
||||
function stopStudySocket() {
|
||||
studyClosed = true;
|
||||
if (studyReconnect) {
|
||||
window.clearTimeout(studyReconnect);
|
||||
studyReconnect = 0;
|
||||
}
|
||||
if (studyPing) {
|
||||
window.clearInterval(studyPing);
|
||||
studyPing = 0;
|
||||
}
|
||||
stopStudyFallback();
|
||||
const ws = studySocket;
|
||||
studySocket = null;
|
||||
if (ws) {
|
||||
ws.onclose = null;
|
||||
ws.onerror = null;
|
||||
ws.onmessage = null;
|
||||
ws.close();
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleStudyReconnect() {
|
||||
if (studyClosed || studyReconnect) return;
|
||||
const delay = studyBackoff;
|
||||
studyBackoff = Math.min(10000, delay * 2);
|
||||
studyReconnect = window.setTimeout(() => {
|
||||
studyReconnect = 0;
|
||||
connectStudySocket();
|
||||
}, delay);
|
||||
}
|
||||
|
||||
function connectStudySocket() {
|
||||
if (studyClosed) return;
|
||||
if (studySocket && (studySocket.readyState === WebSocket.OPEN || studySocket.readyState === WebSocket.CONNECTING)) {
|
||||
return;
|
||||
}
|
||||
let ws: WebSocket;
|
||||
try {
|
||||
ws = new WebSocket(studySocketUrl());
|
||||
} catch {
|
||||
startStudyFallback();
|
||||
scheduleStudyReconnect();
|
||||
return;
|
||||
}
|
||||
studySocket = ws;
|
||||
ws.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(String(event.data));
|
||||
if (data && typeof data === "object") applyStudyControl(data as Record<string, unknown>);
|
||||
} catch { /* ignore */ }
|
||||
};
|
||||
ws.onopen = () => {
|
||||
studyBackoff = 1000;
|
||||
stopStudyFallback();
|
||||
void loadStudyControl();
|
||||
if (studyPing) window.clearInterval(studyPing);
|
||||
studyPing = window.setInterval(() => {
|
||||
if (ws.readyState === WebSocket.OPEN) ws.send("ping");
|
||||
}, 8000);
|
||||
};
|
||||
ws.onclose = () => {
|
||||
if (studyPing) {
|
||||
window.clearInterval(studyPing);
|
||||
studyPing = 0;
|
||||
}
|
||||
if (studySocket === ws) studySocket = null;
|
||||
if (!studyClosed) {
|
||||
startStudyFallback();
|
||||
scheduleStudyReconnect();
|
||||
}
|
||||
};
|
||||
ws.onerror = () => {
|
||||
ws.close();
|
||||
};
|
||||
}
|
||||
|
||||
function stopStudyTick() {
|
||||
if (studyTick) {
|
||||
window.clearInterval(studyTick);
|
||||
studyTick = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function startStudyTick() {
|
||||
if (studyTick) return;
|
||||
nowTick.value = Date.now();
|
||||
studyTick = window.setInterval(() => {
|
||||
nowTick.value = Date.now();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
watch(proxyOpen, (open, wasOpen) => {
|
||||
if (wasOpen && !open) restoreProxy();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => studyControl.value.started,
|
||||
(started) => {
|
||||
if (started) startStudyPoll();
|
||||
else stopStudyPoll();
|
||||
},
|
||||
);
|
||||
function studyWake() {
|
||||
if (studyClosed) return;
|
||||
void loadStudyControl();
|
||||
if (!studySocket || studySocket.readyState === WebSocket.CLOSING || studySocket.readyState === WebSocket.CLOSED) {
|
||||
connectStudySocket();
|
||||
return;
|
||||
}
|
||||
if (studySocket.readyState === WebSocket.OPEN) {
|
||||
try {
|
||||
studySocket.send("ping");
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
function onStudyVisible() {
|
||||
if (document.visibilityState === "visible") studyWake();
|
||||
}
|
||||
|
||||
watch(countdownOn, (on) => {
|
||||
if (on) startStudyTick();
|
||||
else stopStudyTick();
|
||||
});
|
||||
|
||||
async function toggleStudy() {
|
||||
if (studyBusy.value) return;
|
||||
@@ -484,13 +658,20 @@ onMounted(() => {
|
||||
loadStart();
|
||||
loadWorkers();
|
||||
loadProxy();
|
||||
connectStudySocket();
|
||||
document.addEventListener("visibilitychange", onStudyVisible);
|
||||
window.addEventListener("focus", studyWake);
|
||||
window.addEventListener("online", studyWake);
|
||||
window.addEventListener("pageshow", studyWake);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
stopStudyPoll();
|
||||
clearTimeout(targetSaveTimer);
|
||||
clearTimeout(startSaveTimer);
|
||||
clearTimeout(workersSaveTimer);
|
||||
document.removeEventListener("visibilitychange", onStudyVisible);
|
||||
window.removeEventListener("focus", studyWake);
|
||||
window.removeEventListener("online", studyWake);
|
||||
window.removeEventListener("pageshow", studyWake);
|
||||
stopStudySocket();
|
||||
stopStudyTick();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -548,89 +729,125 @@ onUnmounted(() => {
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="panel-card study-card">
|
||||
<section class="panel-card study-card" :class="{ 'is-busy': studyingWorkers.length > 0 }">
|
||||
<header class="panel-card-head">
|
||||
<h3>自动学习</h3>
|
||||
<div class="study-head-actions">
|
||||
<n-button v-if="proxyLoaded" size="small" quaternary @click="proxyOpen = true">
|
||||
<template #icon><n-icon><GlobeOutline /></n-icon></template>
|
||||
代理
|
||||
</n-button>
|
||||
<n-button
|
||||
:type="studyControl.started ? 'error' : 'primary'"
|
||||
size="small"
|
||||
:loading="studyBusy"
|
||||
@click="toggleStudy"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon><StopOutline v-if="studyControl.started" /><PlayOutline v-else /></n-icon>
|
||||
</template>
|
||||
{{ studyControl.started ? "停止" : "立即开始" }}
|
||||
</n-button>
|
||||
</div>
|
||||
</header>
|
||||
<n-alert v-if="studyError" class="summary-error" type="error">{{ studyError }}</n-alert>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="96" :show-feedback="false" size="small">
|
||||
<n-form-item v-if="targetLoaded" label="每月目标">
|
||||
<div class="target-control">
|
||||
<n-input-number
|
||||
id="monthly-target"
|
||||
v-model:value="monthlyTarget"
|
||||
button-placement="both"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
:precision="0"
|
||||
size="small"
|
||||
/>
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="startLoaded" label="定时启动">
|
||||
<div class="target-control start-control">
|
||||
<n-select id="study-start-day" v-model:value="startDay" size="small" :options="dayOptions" class="day-select" />
|
||||
<n-tooltip v-if="startDay === 1" placement="top">
|
||||
<n-alert v-if="scheduleError" class="summary-error" type="error">{{ scheduleError }}</n-alert>
|
||||
<div class="study-card-body">
|
||||
<div class="study-config">
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="96" :show-feedback="false" size="small">
|
||||
<n-form-item v-if="targetLoaded" label="每月目标">
|
||||
<div class="target-control">
|
||||
<n-input-number
|
||||
id="monthly-target"
|
||||
v-model:value="monthlyTarget"
|
||||
button-placement="both"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
:precision="0"
|
||||
size="small"
|
||||
/>
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="startLoaded" label="定时开启">
|
||||
<n-switch v-model:value="scheduleEnabled" size="small" />
|
||||
</n-form-item>
|
||||
<n-form-item v-if="startLoaded" label="定时启动">
|
||||
<div class="start-control">
|
||||
<n-select id="study-start-day" v-model:value="startDay" size="small" :options="dayOptions" class="day-select" :disabled="!scheduleEnabled" />
|
||||
<n-tooltip v-if="scheduleEnabled && startDay === 1" placement="top">
|
||||
<template #trigger>
|
||||
<n-icon class="day-warn"><WarningOutline /></n-icon>
|
||||
</template>
|
||||
不推荐使用
|
||||
</n-tooltip>
|
||||
<n-time-picker
|
||||
class="start-time"
|
||||
v-model:formatted-value="startTime"
|
||||
value-format="HH:mm:ss"
|
||||
size="small"
|
||||
:actions="null"
|
||||
:disabled="!scheduleEnabled"
|
||||
/>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="workersLoaded" label="线程数量">
|
||||
<div class="target-control">
|
||||
<n-select id="course-workers" class="worker-select" v-model:value="courseWorkers" size="small" :options="workerOptions" />
|
||||
<n-tooltip v-if="courseWorkers === 1" placement="top">
|
||||
<template #trigger>
|
||||
<button type="button" class="hint-icon" aria-label="说明">
|
||||
<n-icon><HelpCircleOutline /></n-icon>
|
||||
</button>
|
||||
</template>
|
||||
{{ workerHint }}
|
||||
</n-tooltip>
|
||||
</div>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<div class="study-actions">
|
||||
<n-button v-if="proxyLoaded" size="small" quaternary @click="proxyOpen = true">
|
||||
<template #icon><n-icon><GlobeOutline /></n-icon></template>
|
||||
代理
|
||||
</n-button>
|
||||
<n-button v-if="scheduleReady" type="primary" size="small" :loading="scheduleSaving" @click="saveSchedule">保存定时配置</n-button>
|
||||
<n-tooltip v-if="!studyControl.started" placement="top">
|
||||
<template #trigger>
|
||||
<n-icon class="day-warn"><WarningOutline /></n-icon>
|
||||
<span class="study-start-wrap">
|
||||
<n-button type="success" size="small" :disabled="studyControl.hours_met" :loading="studyBusy" @click="toggleStudy">
|
||||
<template #icon>
|
||||
<n-icon><PlayOutline /></n-icon>
|
||||
</template>
|
||||
立即开始
|
||||
</n-button>
|
||||
</span>
|
||||
</template>
|
||||
不推荐使用
|
||||
{{ studyControl.hours_met ? "本月目标已达到" : "会跳过设定的定时启动时间,立刻开始学习任务。" }}
|
||||
</n-tooltip>
|
||||
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" size="small" :actions="null" />
|
||||
<n-button v-else type="error" size="small" :loading="studyBusy" @click="toggleStudy">
|
||||
<template #icon>
|
||||
<n-icon><StopOutline /></n-icon>
|
||||
</template>
|
||||
停止
|
||||
</n-button>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="workersLoaded">
|
||||
<template #label>
|
||||
<span class="field-title">
|
||||
<span>线程数量</span>
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
<button type="button" class="hint-icon" aria-label="说明">
|
||||
<n-icon><HelpCircleOutline /></n-icon>
|
||||
</button>
|
||||
</template>
|
||||
{{ workerHint }}
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
<n-select id="course-workers" class="worker-select" v-model:value="courseWorkers" size="small" :options="workerOptions" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<div class="home-study-status">
|
||||
<span class="study-indicator" :class="{ active: studyControl.started || studyControl.active }"></span>
|
||||
<span class="study-text" :class="{ muted: !studyControl.active }">{{ studyLabel }}</span>
|
||||
</div>
|
||||
<div class="study-live">
|
||||
<div class="study-live-status">
|
||||
<span
|
||||
class="study-indicator"
|
||||
:class="{
|
||||
active: !studyFailed && (studyControl.started || studyControl.active),
|
||||
down: studyFailed,
|
||||
}"
|
||||
></span>
|
||||
<span class="study-text" :class="{ muted: !studyControl.started && !studyControl.active }">{{ studyLabel }}</span>
|
||||
</div>
|
||||
<div v-if="targetLoaded" class="study-progress">
|
||||
<div class="study-progress-meta">
|
||||
<span>本月进度</span>
|
||||
<span>{{ monthProgress.current }} / {{ monthProgress.target }} 分钟</span>
|
||||
</div>
|
||||
<n-progress type="line" :percentage="monthProgress.pct" :show-indicator="false" :height="6" />
|
||||
</div>
|
||||
<ul v-if="studyingWorkers.length" class="study-workers" aria-label="当前课程">
|
||||
<li v-for="row in studyingWorkers" :key="row.id" class="study-worker">
|
||||
<span class="study-worker-title">{{ workerTitle(row) }}</span>
|
||||
<div class="study-worker-bar">
|
||||
<n-progress type="line" :percentage="workerPercent(row)" :show-indicator="false" :height="6" />
|
||||
</div>
|
||||
<span class="study-worker-pct">{{ workerPercent(row) }}%</span>
|
||||
<span class="study-worker-count">{{ workerCount(row) }}</span>
|
||||
<span v-if="showHeartbeat(row)" class="study-heartbeat">{{ heartbeatLeft(row) }}</span>
|
||||
<span class="study-dot" :class="row.ok ? 'up' : 'down'" :aria-label="row.ok ? '正常' : '异常'"></span>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else-if="studyHint" class="study-live-hint">{{ studyHint }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<ul v-if="studyControl.started && studyControl.workers.length" class="study-workers">
|
||||
<li v-for="row in studyControl.workers" :key="row.id" class="study-worker">
|
||||
<div class="study-worker-main">
|
||||
<span class="study-worker-title">{{ workerTitle(row) }}</span>
|
||||
<n-progress type="line" :percentage="workerPercent(row)" :show-indicator="false" :height="8" />
|
||||
</div>
|
||||
<div class="study-worker-meta">
|
||||
<span class="study-worker-pct">{{ workerPercent(row) }}%</span>
|
||||
<span class="study-heartbeat">{{ heartbeatLeft(row) }}</span>
|
||||
<span class="study-dot" :class="row.ok ? 'up' : 'down'"></span>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
<n-modal
|
||||
|
||||
Reference in New Issue
Block a user