1210 lines
43 KiB
Vue
1210 lines
43 KiB
Vue
<script setup lang="ts">
|
||
import { apiFetch } from "../../shared/http";
|
||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInputNumber, NModal, NProgress, NRadioButton, NRadioGroup, NSelect, NSwitch, NTimePicker, NTooltip } from "naive-ui";
|
||
import { GlobeOutline, PlayOutline, RefreshOutline, StopOutline } from "@vicons/ionicons5";
|
||
import ProxyFields from "../../shared/ProxyFields.vue";
|
||
import { STUDY_DAY_DEFAULT, STUDY_DAY_MAX, STUDY_DAY_MIN, dayOptions, workerOptions } from "../../shared/studyFields";
|
||
import { failureText } from "../../shared/text";
|
||
|
||
interface HomeSummary {
|
||
name: string;
|
||
avatar: string;
|
||
department: string;
|
||
level: string;
|
||
year_hours: string;
|
||
month_hours: string;
|
||
today_hours: string | number | null;
|
||
total_hours: string;
|
||
total_score: string;
|
||
points: string | number | null;
|
||
limited?: boolean;
|
||
}
|
||
|
||
interface StudyWorker {
|
||
id: number;
|
||
course: string;
|
||
progress: number;
|
||
interval: number;
|
||
heartbeat_at: number;
|
||
heartbeat_in: number;
|
||
seen_at: number;
|
||
sent: number;
|
||
total: number;
|
||
ok: boolean;
|
||
finished: boolean;
|
||
}
|
||
|
||
type SectionState = "loading" | "ready" | "error";
|
||
|
||
const props = defineProps<{ employeeId: string }>();
|
||
const summary = ref<HomeSummary | null>(null);
|
||
const summaryState = ref<SectionState>("loading");
|
||
const summaryError = ref("");
|
||
const refreshing = ref(false);
|
||
const avatarBroken = ref(false);
|
||
let refreshRunning = false;
|
||
let busy = false;
|
||
let studyTick = 0;
|
||
let studySocket: PingSocket | null = null;
|
||
let studyReconnect = 0;
|
||
let studyFallback = 0;
|
||
let studyBackoff = 1000;
|
||
let studyClosed = false;
|
||
const nowTick = ref(Date.now());
|
||
|
||
const monthlyTarget = ref<number | null>(null);
|
||
const progressHours = ref("");
|
||
const progressTarget = ref(0);
|
||
const targetLoaded = ref(false);
|
||
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: "",
|
||
message: "",
|
||
workers: [] as StudyWorker[],
|
||
});
|
||
const studyBusy = ref(false);
|
||
const hoursRefreshIn = ref(0);
|
||
const hoursRefreshSeen = ref(0);
|
||
const studyError = ref("");
|
||
|
||
const studyingWorkers = computed(() => (
|
||
studyControl.value.workers.filter((row) => row.course.trim() && !workerDone(row))
|
||
));
|
||
|
||
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 = progressHours.value.match(/(\d+)/);
|
||
const current = match ? Number(match[1]) : 0;
|
||
const target = progressTarget.value;
|
||
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 message = studyControl.value.message.trim();
|
||
if (studyControl.value.hours_met) return "本月目标已达到";
|
||
if (studyFailed.value) return message || state;
|
||
if (state === "排队中") return "排队中,马上开始";
|
||
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 "课程已全部学完";
|
||
if (!studyControl.value.schedule_enabled) return "未开始";
|
||
if (!studyControl.value.window_open) return "等待定时启动";
|
||
return "等待启动";
|
||
});
|
||
|
||
const startBlocked = computed(() => {
|
||
if (!scheduleReady.value) return "正在读取配置";
|
||
const target = monthlyTarget.value ?? 0;
|
||
if (target <= 0) return "先把每月目标设为大于 0";
|
||
if (monthProgress.value.current >= target) return "本月学时已达到目标,把每月目标调高后可以再开始";
|
||
return "";
|
||
});
|
||
|
||
const studyHint = computed(() => {
|
||
if (studyingWorkers.value.length || !targetLoaded.value) return "";
|
||
const control = studyControl.value;
|
||
if (progressTarget.value <= 0) return "每月目标为 0 时不会学习。先把每月目标设为大于 0。";
|
||
if (control.hours_met) return "本月学时已达到目标。想继续学,把每月目标调高后点「立即开始」。";
|
||
if (control.state === "会话失效") return "登录已失效。请退出后重新登录,登录后会接着学。";
|
||
if (studyFailed.value && control.message.includes("没有可用的课程")) {
|
||
return "课程清单还没有准备好。请稍后再试,或联系管理员加载课程清单。";
|
||
}
|
||
if (studyFailed.value) return "稍后会自动重试,也可以点「立即开始」马上重试。";
|
||
if (control.started || control.active) return "正在准备,稍后这里会列出正在学的课程。";
|
||
if (control.state === "已学完") return "课程清单里的课程已全部学完。";
|
||
if (control.state === "已停止" || control.paused) {
|
||
return control.schedule_enabled
|
||
? "本月已手动停止。点「立即开始」可以继续;下个月到开始时刻会自动恢复。"
|
||
: "已手动停止。点「立即开始」可以继续。";
|
||
}
|
||
if (!control.schedule_enabled) return "定时启动已关闭。需要学习时点「立即开始」。";
|
||
if (!control.window_open) return "到开始时刻会自动开始学习,也可以点「立即开始」马上开始。";
|
||
return "点「立即开始」开始学习。";
|
||
});
|
||
|
||
function amount(value: string | number | null | undefined) {
|
||
if (value === null || value === undefined || value === "") return "—";
|
||
const numeric = Number(value);
|
||
if (!Number.isFinite(numeric)) return String(value);
|
||
if (Number.isInteger(numeric)) return String(numeric);
|
||
return String(value);
|
||
}
|
||
|
||
function withMinutes(value: string) {
|
||
if (!value || value === "—") return "—";
|
||
return `${value} 分钟`;
|
||
}
|
||
|
||
const facts = computed(() => {
|
||
const current = summary.value;
|
||
return [
|
||
{ label: "本年学时", value: current ? withMinutes(amount(current.year_hours)) : "" },
|
||
{ label: "本月学时", value: current ? withMinutes(amount(current.month_hours)) : "" },
|
||
{ label: "本日学时", value: current ? withMinutes(amount(current.today_hours)) : "" },
|
||
{ label: "总学时", value: current ? withMinutes(amount(current.total_hours)) : "" },
|
||
{ label: "累计学分", value: current ? amount(current.total_score) : "" },
|
||
{ label: "可用积分", value: current ? amount(current.points) : "" },
|
||
];
|
||
});
|
||
|
||
function asSummary(value: unknown): HomeSummary | null {
|
||
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
||
const row = value as Record<string, unknown>;
|
||
const known = ["name", "month_hours", "year_hours", "total_hours", "today_hours"].some((key) => key in row);
|
||
if (!known) return null;
|
||
const text = (key: string) => (typeof row[key] === "string" || typeof row[key] === "number" ? row[key] : "");
|
||
return {
|
||
name: typeof row.name === "string" ? row.name : "",
|
||
avatar: typeof row.avatar === "string" ? row.avatar : "",
|
||
department: typeof row.department === "string" ? row.department : "",
|
||
level: typeof row.level === "string" ? row.level : "",
|
||
year_hours: String(text("year_hours") ?? ""),
|
||
month_hours: String(text("month_hours") ?? ""),
|
||
today_hours: typeof row.today_hours === "number" || typeof row.today_hours === "string" ? row.today_hours : null,
|
||
total_hours: String(text("total_hours") ?? ""),
|
||
total_score: String(text("total_score") ?? ""),
|
||
points: typeof row.points === "number" || typeof row.points === "string" ? row.points : null,
|
||
limited: row.limited === true,
|
||
};
|
||
}
|
||
|
||
function pad(value: number) {
|
||
return String(value).padStart(2, "0");
|
||
}
|
||
|
||
function asWorkers(value: unknown): StudyWorker[] {
|
||
if (!Array.isArray(value)) return [];
|
||
const rows: StudyWorker[] = [];
|
||
for (const item of value) {
|
||
if (!item || typeof item !== "object") continue;
|
||
const row = item as Record<string, unknown>;
|
||
rows.push({
|
||
id: typeof row.id === "number" ? row.id : rows.length + 1,
|
||
course: typeof row.course === "string" ? row.course : "",
|
||
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,
|
||
heartbeat_in: typeof row.heartbeat_in === "number" ? row.heartbeat_in : 0,
|
||
seen_at: Date.now(),
|
||
sent: typeof row.sent === "number" ? row.sent : 0,
|
||
total: typeof row.total === "number" ? row.total : 0,
|
||
ok: row.ok !== false,
|
||
finished: row.finished === true || row.completed === true || row.done === true,
|
||
});
|
||
}
|
||
return rows;
|
||
}
|
||
|
||
function workerDone(row: StudyWorker) {
|
||
return row.finished;
|
||
}
|
||
|
||
function workerPercent(row: StudyWorker) {
|
||
if (workerDone(row)) return 100;
|
||
const value = Number(row.progress);
|
||
if (!Number.isFinite(value)) return 0;
|
||
return Math.min(100, Math.max(0, Math.round(value * 100) / 100));
|
||
}
|
||
|
||
function workerPercentText(row: StudyWorker) {
|
||
const value = workerPercent(row);
|
||
if (Number.isInteger(value)) return `${value}%`;
|
||
return `${value.toFixed(2).replace(/0$/, "")}%`;
|
||
}
|
||
|
||
function workerTitle(row: StudyWorker) {
|
||
return row.course;
|
||
}
|
||
|
||
function showHeartbeat(row: StudyWorker) {
|
||
return row.interval > 0 && (row.heartbeat_in > 0 || row.heartbeat_at > 0);
|
||
}
|
||
|
||
function workerMinutes(row: StudyWorker) {
|
||
if (row.total > 0) return `${row.sent} / ${row.total}`;
|
||
if (row.sent > 0) return `${row.sent} / —`;
|
||
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;
|
||
const elapsed = (Date.now() - row.seen_at) / 1000;
|
||
const left = Math.max(0, row.heartbeat_in - elapsed);
|
||
return `${Math.ceil(left)}s`;
|
||
}
|
||
|
||
async function loadSummary() {
|
||
if (busy) return;
|
||
busy = true;
|
||
const hadData = summary.value !== null;
|
||
if (!hadData) summaryState.value = "loading";
|
||
try {
|
||
const response = await apiFetch("/api/home/summary");
|
||
const payload = await response.json().catch(() => ({}));
|
||
if (!response.ok) {
|
||
summaryError.value = "个人学习信息没有获取到。";
|
||
if (!hadData) summaryState.value = "error";
|
||
return;
|
||
}
|
||
const parsed = asSummary(payload);
|
||
if (!parsed) {
|
||
summaryError.value = "数据异常";
|
||
if (!hadData) summaryState.value = "error";
|
||
return;
|
||
}
|
||
const studying = studyControl.value.active || studyControl.value.started;
|
||
if (studying && progressHours.value) parsed.month_hours = progressHours.value;
|
||
else if (parsed.month_hours) progressHours.value = parsed.month_hours;
|
||
summary.value = parsed;
|
||
avatarBroken.value = false;
|
||
summaryError.value = "";
|
||
summaryState.value = "ready";
|
||
} catch {
|
||
summaryError.value = "个人学习信息没有获取到。";
|
||
if (!hadData) summaryState.value = "error";
|
||
} finally {
|
||
busy = false;
|
||
}
|
||
}
|
||
|
||
const settingsLoadError = ref("");
|
||
|
||
function refresh() {
|
||
if (refreshRunning) return;
|
||
refreshRunning = true;
|
||
refreshing.value = true;
|
||
void Promise.all([loadSummary(), loadStudyControl(), loadSettings()]).finally(() => {
|
||
refreshRunning = false;
|
||
refreshing.value = false;
|
||
});
|
||
}
|
||
|
||
async function loadTarget() {
|
||
try {
|
||
const res = await apiFetch("/api/settings/monthly-target");
|
||
if (!res.ok) return false;
|
||
const data = await res.json();
|
||
monthlyTarget.value = data.monthly_target ?? 600;
|
||
targetLoaded.value = true;
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
const startLoaded = ref(false);
|
||
const scheduleEnabled = ref(true);
|
||
const startDay = ref<number | null>(STUDY_DAY_DEFAULT);
|
||
const loadedStartDay = ref<number | null>(null);
|
||
const userDayOptions = computed(() => {
|
||
const current = loadedStartDay.value;
|
||
if (
|
||
current != null
|
||
&& (current < STUDY_DAY_MIN || current > STUDY_DAY_MAX)
|
||
&& current >= 1
|
||
&& current <= 28
|
||
) {
|
||
return [...dayOptions, { label: `每月 ${current} 日`, value: current }].sort((left, right) => left.value - right.value);
|
||
}
|
||
return dayOptions;
|
||
});
|
||
const startHour = ref<number | null>(0);
|
||
const startMinute = ref<number | null>(0);
|
||
const startSecond = ref<number | null>(0);
|
||
|
||
const startTime = computed({
|
||
get() {
|
||
return `${pad(startHour.value ?? 0)}:${pad(startMinute.value ?? 0)}:${pad(startSecond.value ?? 0)}`;
|
||
},
|
||
set(value: string | null) {
|
||
if (!value) return;
|
||
const [hour, minute, second] = value.split(":").map((part) => Number(part));
|
||
if (![hour, minute, second].every((part) => Number.isInteger(part))) return;
|
||
startHour.value = hour;
|
||
startMinute.value = minute;
|
||
startSecond.value = second;
|
||
},
|
||
});
|
||
|
||
async function loadStart() {
|
||
try {
|
||
const res = await apiFetch("/api/settings/study-start");
|
||
if (!res.ok) return false;
|
||
const data = await res.json();
|
||
startDay.value = typeof data.day === "number" ? data.day : STUDY_DAY_DEFAULT;
|
||
loadedStartDay.value = startDay.value;
|
||
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;
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
const workersLoaded = ref(false);
|
||
const courseWorkers = ref<number | null>(1);
|
||
const heartbeatLoaded = ref(false);
|
||
const heartbeatMode = ref("auto");
|
||
const heartbeatVideo = ref<number | null>(30);
|
||
const heartbeatDocument = ref<number | null>(120);
|
||
const heartbeatScorm = ref<number | null>(120);
|
||
const scheduleReady = computed(() => targetLoaded.value && startLoaded.value && workersLoaded.value && heartbeatLoaded.value);
|
||
|
||
async function loadWorkers() {
|
||
try {
|
||
const res = await apiFetch("/api/settings/course-workers");
|
||
if (!res.ok) return false;
|
||
const data = await res.json();
|
||
courseWorkers.value = typeof data.workers === "number" ? data.workers : 1;
|
||
workersLoaded.value = true;
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
async function putJson(url: string, body: Record<string, unknown>, fallback: string) {
|
||
const res = await apiFetch(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));
|
||
}
|
||
|
||
function scheduleBody(): Record<string, unknown> | null {
|
||
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 null;
|
||
}
|
||
if (
|
||
day == null || hour == null || minute == null || second == null
|
||
|| !Number.isInteger(day) || !Number.isInteger(hour) || !Number.isInteger(minute) || !Number.isInteger(second)
|
||
|| hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59
|
||
) {
|
||
scheduleError.value = "请填写完整的开始时刻";
|
||
return null;
|
||
}
|
||
const keptByAdmin = loadedStartDay.value != null && day === loadedStartDay.value && (day < STUDY_DAY_MIN || day > STUDY_DAY_MAX);
|
||
if (!keptByAdmin && (day < STUDY_DAY_MIN || day > STUDY_DAY_MAX)) {
|
||
scheduleError.value = "每月开始日须为 5 到 25 的整数";
|
||
return null;
|
||
}
|
||
if (workers == null || !Number.isInteger(workers) || workers < 1 || workers > 8) {
|
||
scheduleError.value = "同时学习课程数须为 1 到 8";
|
||
return null;
|
||
}
|
||
if (heartbeatMode.value !== "auto" && heartbeatMode.value !== "manual") {
|
||
scheduleError.value = "心跳间隔须为自动获取或手动设定";
|
||
return null;
|
||
}
|
||
if (heartbeatMode.value === "manual") {
|
||
if (heartbeatVideo.value == null || !Number.isInteger(heartbeatVideo.value) || heartbeatVideo.value < 0 || heartbeatVideo.value > 300) {
|
||
scheduleError.value = "视频心跳间隔须为 0 到 300 的整数";
|
||
return null;
|
||
}
|
||
if (heartbeatDocument.value == null || !Number.isInteger(heartbeatDocument.value) || heartbeatDocument.value < 0 || heartbeatDocument.value > 600) {
|
||
scheduleError.value = "文档心跳间隔须为 0 到 600 的整数";
|
||
return null;
|
||
}
|
||
if (heartbeatScorm.value == null || !Number.isInteger(heartbeatScorm.value) || heartbeatScorm.value < 0 || heartbeatScorm.value > 600) {
|
||
scheduleError.value = "Scorm 心跳间隔须为 0 到 600 的整数";
|
||
return null;
|
||
}
|
||
}
|
||
scheduleError.value = "";
|
||
return {
|
||
monthly_target: target,
|
||
day,
|
||
hour,
|
||
minute,
|
||
second,
|
||
enabled: scheduleEnabled.value,
|
||
workers,
|
||
heartbeat_mode: heartbeatMode.value,
|
||
heartbeat_video_seconds: heartbeatVideo.value ?? 30,
|
||
heartbeat_document_seconds: heartbeatDocument.value ?? 120,
|
||
heartbeat_scorm_seconds: heartbeatScorm.value ?? 120,
|
||
};
|
||
}
|
||
|
||
async function saveSchedule() {
|
||
if (scheduleSaving.value || !scheduleReady.value) return;
|
||
const body = scheduleBody();
|
||
if (!body) return;
|
||
scheduleSaving.value = true;
|
||
try {
|
||
await putJson("/api/settings/study", body, "没有保存定时配置。");
|
||
await loadStudyControl();
|
||
} catch (exc) {
|
||
scheduleError.value = exc instanceof Error ? exc.message : "没有保存。";
|
||
} finally {
|
||
scheduleSaving.value = false;
|
||
}
|
||
}
|
||
|
||
const proxyOpen = ref(false);
|
||
const proxyLoaded = ref(false);
|
||
const proxySaving = ref(false);
|
||
const proxyError = ref("");
|
||
const proxyScheme = ref("off");
|
||
const proxyHost = ref("");
|
||
const proxyPort = ref<number | null>(null);
|
||
const proxyUser = ref("");
|
||
const proxyPassword = ref("");
|
||
const proxyHasPassword = ref(false);
|
||
const proxyManual = computed(() => proxyScheme.value !== "off" && proxyScheme.value !== "pool");
|
||
const savedProxy = {
|
||
scheme: "off",
|
||
host: "",
|
||
port: null as number | null,
|
||
username: "",
|
||
hasPassword: false,
|
||
};
|
||
|
||
function rememberProxy() {
|
||
savedProxy.scheme = proxyScheme.value;
|
||
savedProxy.host = proxyHost.value;
|
||
savedProxy.port = proxyPort.value;
|
||
savedProxy.username = proxyUser.value;
|
||
savedProxy.hasPassword = proxyHasPassword.value;
|
||
}
|
||
|
||
function restoreProxy() {
|
||
proxyScheme.value = savedProxy.scheme;
|
||
proxyHost.value = savedProxy.host;
|
||
proxyPort.value = savedProxy.port;
|
||
proxyUser.value = savedProxy.username;
|
||
proxyPassword.value = "";
|
||
proxyHasPassword.value = savedProxy.hasPassword;
|
||
proxyError.value = "";
|
||
}
|
||
const proxyOptions = [
|
||
{ label: "关闭", value: "off" },
|
||
{ label: "自动", value: "pool" },
|
||
{ label: "HTTP", value: "http" },
|
||
{ label: "HTTPS", value: "https" },
|
||
{ label: "SOCKS4", value: "socks4" },
|
||
{ label: "SOCKS5", value: "socks5" },
|
||
];
|
||
|
||
async function loadProxy() {
|
||
try {
|
||
const res = await apiFetch("/api/settings/proxy");
|
||
const data = await res.json().catch(() => ({}));
|
||
if (!res.ok) return false;
|
||
proxyScheme.value = typeof data.scheme === "string" && data.scheme ? data.scheme : "off";
|
||
proxyHost.value = typeof data.host === "string" ? data.host : "";
|
||
proxyPort.value = typeof data.port === "number" ? data.port : null;
|
||
proxyUser.value = typeof data.username === "string" ? data.username : "";
|
||
proxyPassword.value = "";
|
||
proxyHasPassword.value = data.has_password === true;
|
||
proxyLoaded.value = true;
|
||
rememberProxy();
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
async function loadHeartbeat() {
|
||
try {
|
||
const res = await apiFetch("/api/settings/heartbeat");
|
||
if (!res.ok) return false;
|
||
const data = await res.json();
|
||
heartbeatMode.value = data.heartbeat_mode === "manual" ? "manual" : "auto";
|
||
heartbeatVideo.value = typeof data.heartbeat_video_seconds === "number" ? data.heartbeat_video_seconds : 30;
|
||
heartbeatDocument.value = typeof data.heartbeat_document_seconds === "number" ? data.heartbeat_document_seconds : 120;
|
||
heartbeatScorm.value = typeof data.heartbeat_scorm_seconds === "number" ? data.heartbeat_scorm_seconds : 120;
|
||
heartbeatLoaded.value = true;
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
async function loadSettings() {
|
||
const [target, start, workers, heartbeat, proxy] = await Promise.all([
|
||
loadTarget(),
|
||
loadStart(),
|
||
loadWorkers(),
|
||
loadHeartbeat(),
|
||
loadProxy(),
|
||
]);
|
||
settingsLoadError.value = target && start && workers && heartbeat && proxy ? "" : "定时配置没有获取到。";
|
||
}
|
||
|
||
function proxyPasswordPayload() {
|
||
if (proxyPassword.value !== "") return proxyPassword.value;
|
||
if (!proxyUser.value.trim()) return "";
|
||
return proxyHasPassword.value ? null : "";
|
||
}
|
||
|
||
async function saveProxy() {
|
||
if (proxySaving.value) return;
|
||
proxyError.value = "";
|
||
if (proxyManual.value) {
|
||
if (!proxyHost.value.trim()) {
|
||
proxyError.value = "请填写代理地址";
|
||
return;
|
||
}
|
||
if (proxyPort.value == null || !Number.isInteger(proxyPort.value)) {
|
||
proxyError.value = "请填写代理端口";
|
||
return;
|
||
}
|
||
}
|
||
proxySaving.value = true;
|
||
try {
|
||
const res = await apiFetch("/api/settings/proxy", {
|
||
method: "PUT",
|
||
headers: { "Content-Type": "application/json" },
|
||
body: JSON.stringify(
|
||
proxyManual.value
|
||
? {
|
||
scheme: proxyScheme.value,
|
||
host: proxyHost.value.trim(),
|
||
port: proxyPort.value,
|
||
username: proxyUser.value.trim(),
|
||
password: proxyPasswordPayload(),
|
||
}
|
||
: { scheme: proxyScheme.value },
|
||
),
|
||
});
|
||
const data = await res.json().catch(() => ({}));
|
||
if (!res.ok) {
|
||
proxyError.value = failureText(data, "没有保存。");
|
||
return;
|
||
}
|
||
proxyPassword.value = "";
|
||
proxyHasPassword.value = data.has_password === true;
|
||
if (!proxyManual.value) {
|
||
proxyHost.value = "";
|
||
proxyPort.value = null;
|
||
proxyUser.value = "";
|
||
proxyHasPassword.value = false;
|
||
}
|
||
rememberProxy();
|
||
proxyOpen.value = false;
|
||
} catch {
|
||
proxyError.value = "没有保存。";
|
||
} finally {
|
||
proxySaving.value = false;
|
||
}
|
||
}
|
||
|
||
let lastStudySeq = 0;
|
||
let lastStudyBoot = "";
|
||
|
||
function applyStudyControl(payload: Record<string, unknown>) {
|
||
const seq = typeof payload.seq === "number" ? payload.seq : 0;
|
||
const boot = typeof payload.boot === "string" ? payload.boot : "";
|
||
if (boot && boot !== lastStudyBoot) {
|
||
lastStudyBoot = boot;
|
||
lastStudySeq = 0;
|
||
}
|
||
if (seq > 0 && seq < lastStudySeq) return;
|
||
if (seq > 0) lastStudySeq = seq;
|
||
studyControl.value = {
|
||
started: payload.started === true,
|
||
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),
|
||
};
|
||
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;
|
||
}
|
||
const incomingHours = typeof payload.month_hours === "string" ? payload.month_hours.trim() : "";
|
||
if (incomingHours) {
|
||
const shown = progressHours.value || summary.value?.month_hours || "";
|
||
const incomingMinutes = Number(incomingHours.match(/(\d+)/)?.[1] ?? 0);
|
||
const shownMinutes = Number(String(shown).match(/(\d+)/)?.[1] ?? 0);
|
||
// 达标后任务已停,这一帧仍要补上本月学时和进度条。空闲帧不把刚刷新到的更大数字改小。
|
||
if (studying || incomingMinutes > shownMinutes) {
|
||
progressHours.value = incomingHours;
|
||
if (summary.value) summary.value = { ...summary.value, month_hours: incomingHours };
|
||
}
|
||
}
|
||
if (typeof payload.monthly_target === "number" && Number.isFinite(payload.monthly_target)) {
|
||
progressTarget.value = Math.trunc(payload.monthly_target);
|
||
}
|
||
}
|
||
|
||
async function loadStudyControl() {
|
||
try {
|
||
const res = await apiFetch("/api/settings/study-control");
|
||
if (res.status === 401) {
|
||
stopStudySocket();
|
||
return;
|
||
}
|
||
const data = await res.json().catch(() => ({}));
|
||
if (res.ok) applyStudyControl(data);
|
||
} catch { /* 静默 */ }
|
||
}
|
||
|
||
function studySocketUrl() {
|
||
const proto = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||
return `${proto}//${window.location.host}/api/settings/study-control/ws`;
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
type PingSocket = WebSocket & { ping?: number };
|
||
|
||
// 状态没变时服务器也会每 5 秒发一帧。超过 15 秒一帧都没有,说明连接其实已经断了。
|
||
const STUDY_STALE_MS = 15000;
|
||
const STUDY_CONNECT_MS = 8000;
|
||
const STUDY_RETRY_MAX_MS = 10000;
|
||
let studyFrameAt = 0;
|
||
let studyDialAt = 0;
|
||
let studyWatch = 0;
|
||
|
||
function clearSocketPing(ws: PingSocket) {
|
||
if (!ws.ping) return;
|
||
window.clearInterval(ws.ping);
|
||
ws.ping = 0;
|
||
}
|
||
|
||
function releaseStudySocket() {
|
||
const ws = studySocket;
|
||
studySocket = null;
|
||
if (!ws) return;
|
||
clearSocketPing(ws);
|
||
ws.onopen = null;
|
||
ws.onclose = null;
|
||
ws.onerror = null;
|
||
ws.onmessage = null;
|
||
try {
|
||
ws.close();
|
||
} catch { /* 已经关了 */ }
|
||
}
|
||
|
||
function stopStudySocket() {
|
||
studyClosed = true;
|
||
if (studyReconnect) {
|
||
window.clearTimeout(studyReconnect);
|
||
studyReconnect = 0;
|
||
}
|
||
if (studyWatch) {
|
||
window.clearInterval(studyWatch);
|
||
studyWatch = 0;
|
||
}
|
||
stopStudyFallback();
|
||
releaseStudySocket();
|
||
}
|
||
|
||
function scheduleStudyReconnect() {
|
||
if (studyClosed || studyReconnect) return;
|
||
const delay = Math.round(studyBackoff * (0.8 + Math.random() * 0.4));
|
||
studyBackoff = Math.min(STUDY_RETRY_MAX_MS, studyBackoff * 2);
|
||
studyReconnect = window.setTimeout(() => {
|
||
studyReconnect = 0;
|
||
connectStudySocket();
|
||
}, delay);
|
||
}
|
||
|
||
// 连接没了:先每 3 秒查一次顶着,同时按 1、2、4 秒直到 10 秒的间隔一直重连,连上为止。
|
||
function retryStudySocket() {
|
||
releaseStudySocket();
|
||
if (studyClosed) return;
|
||
startStudyFallback();
|
||
scheduleStudyReconnect();
|
||
}
|
||
|
||
function watchStudySocket() {
|
||
if (studyClosed) return;
|
||
const ws = studySocket;
|
||
if (!ws) {
|
||
scheduleStudyReconnect();
|
||
return;
|
||
}
|
||
const now = Date.now();
|
||
if (ws.readyState === WebSocket.CONNECTING) {
|
||
if (now - studyDialAt > STUDY_CONNECT_MS) retryStudySocket();
|
||
return;
|
||
}
|
||
if (ws.readyState === WebSocket.OPEN) {
|
||
if (now - studyFrameAt > STUDY_STALE_MS) retryStudySocket();
|
||
return;
|
||
}
|
||
retryStudySocket();
|
||
}
|
||
|
||
function connectStudySocket() {
|
||
if (studyClosed) return;
|
||
if (!studyWatch) studyWatch = window.setInterval(watchStudySocket, 3000);
|
||
if (studySocket && (studySocket.readyState === WebSocket.OPEN || studySocket.readyState === WebSocket.CONNECTING)) {
|
||
return;
|
||
}
|
||
releaseStudySocket();
|
||
let ws: WebSocket;
|
||
try {
|
||
ws = new WebSocket(studySocketUrl());
|
||
} catch {
|
||
startStudyFallback();
|
||
scheduleStudyReconnect();
|
||
return;
|
||
}
|
||
const socket = ws as PingSocket;
|
||
studySocket = socket;
|
||
studyDialAt = Date.now();
|
||
studyFrameAt = studyDialAt;
|
||
socket.onmessage = (event) => {
|
||
studyFrameAt = Date.now();
|
||
studyBackoff = 1000;
|
||
try {
|
||
const data = JSON.parse(String(event.data));
|
||
if (data && typeof data === "object") applyStudyControl(data as Record<string, unknown>);
|
||
} catch { /* ignore */ }
|
||
};
|
||
socket.onopen = () => {
|
||
studyFrameAt = Date.now();
|
||
stopStudyFallback();
|
||
clearSocketPing(socket);
|
||
socket.ping = window.setInterval(() => {
|
||
if (socket.readyState !== WebSocket.OPEN) return;
|
||
try {
|
||
socket.send("ping");
|
||
} catch { /* 下一轮检查会重连 */ }
|
||
}, 8000);
|
||
};
|
||
socket.onclose = (event) => {
|
||
if (studySocket !== socket) return;
|
||
if (event.code === 4401 || event.code === 4403) {
|
||
stopStudySocket();
|
||
return;
|
||
}
|
||
retryStudySocket();
|
||
};
|
||
socket.onerror = () => {
|
||
if (studySocket === socket) retryStudySocket();
|
||
};
|
||
}
|
||
|
||
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();
|
||
});
|
||
|
||
let lastWake = 0;
|
||
|
||
function reconnectStudyNow() {
|
||
if (studyClosed) return;
|
||
if (studyReconnect) {
|
||
window.clearTimeout(studyReconnect);
|
||
studyReconnect = 0;
|
||
}
|
||
studyBackoff = 1000;
|
||
releaseStudySocket();
|
||
void loadStudyControl();
|
||
connectStudySocket();
|
||
}
|
||
|
||
// 回到页面时:连接还在就要一帧最新的,不在就不等重连间隔,马上连。
|
||
function studyWake() {
|
||
const now = Date.now();
|
||
if (now - lastWake < 800) return;
|
||
lastWake = now;
|
||
if (studyClosed) return;
|
||
const ws = studySocket;
|
||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||
try {
|
||
ws.send("ping");
|
||
return;
|
||
} catch { /* 发不出去,按断开处理 */ }
|
||
} else if (ws && ws.readyState === WebSocket.CONNECTING) {
|
||
return;
|
||
}
|
||
reconnectStudyNow();
|
||
}
|
||
|
||
// 网络从断开恢复后,原来的连接多半已经失效,直接换一条新的。
|
||
function studyOnline() {
|
||
lastWake = Date.now();
|
||
reconnectStudyNow();
|
||
}
|
||
|
||
function onStudyVisible() {
|
||
if (document.visibilityState === "visible") studyWake();
|
||
}
|
||
|
||
watch([countdownOn, showHoursRefresh], ([heart, hours]) => {
|
||
if (heart || hours) startStudyTick();
|
||
else stopStudyTick();
|
||
});
|
||
|
||
async function toggleStudy() {
|
||
if (studyBusy.value) return;
|
||
const action = studyControl.value.started ? "stop" : "start";
|
||
const request: Record<string, unknown> = { action };
|
||
if (action === "start") {
|
||
if (!scheduleReady.value) return;
|
||
const settings = scheduleBody();
|
||
if (!settings) return;
|
||
request.settings = settings;
|
||
}
|
||
studyBusy.value = true;
|
||
studyError.value = "";
|
||
try {
|
||
const res = await apiFetch("/api/settings/study-control", {
|
||
method: "POST",
|
||
headers: { "Content-Type": "application/json" },
|
||
body: JSON.stringify(request),
|
||
});
|
||
const data = await res.json().catch(() => ({}));
|
||
if (!res.ok) {
|
||
studyError.value = failureText(data, action === "start" ? "没有开始。" : "没有停止。");
|
||
return;
|
||
}
|
||
applyStudyControl(data);
|
||
} catch {
|
||
studyError.value = action === "start" ? "没有开始。" : "没有停止。";
|
||
} finally {
|
||
studyBusy.value = false;
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
refresh();
|
||
connectStudySocket();
|
||
document.addEventListener("visibilitychange", onStudyVisible);
|
||
window.addEventListener("focus", studyWake);
|
||
window.addEventListener("online", studyOnline);
|
||
window.addEventListener("pageshow", studyWake);
|
||
});
|
||
|
||
onUnmounted(() => {
|
||
document.removeEventListener("visibilitychange", onStudyVisible);
|
||
window.removeEventListener("focus", studyWake);
|
||
window.removeEventListener("online", studyOnline);
|
||
window.removeEventListener("pageshow", studyWake);
|
||
stopStudySocket();
|
||
stopStudyTick();
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<section class="page home-page">
|
||
<div class="home">
|
||
<section class="panel-card home-summary" :aria-busy="summaryState === 'loading'">
|
||
<div class="home-top">
|
||
<div class="home-top-main">
|
||
<n-alert v-if="summaryError" class="summary-error" type="error">{{ summaryError }}</n-alert>
|
||
<div v-if="summary" class="profile">
|
||
<img v-if="summary.avatar && !avatarBroken" class="avatar" :src="summary.avatar" alt="" referrerpolicy="no-referrer" @error="avatarBroken = true" />
|
||
<div v-else class="brand-mark avatar-fallback" aria-hidden="true">{{ (summary.name || props.employeeId).slice(0, 1) || "E" }}</div>
|
||
<div>
|
||
<strong>{{ summary.name || props.employeeId }}</strong>
|
||
<span>{{ summary.department }}<template v-if="summary.level"> · {{ summary.level }}</template></span>
|
||
</div>
|
||
</div>
|
||
<div v-else-if="summaryState === 'loading'" class="profile">
|
||
<div class="bone bone-avatar"></div>
|
||
<div class="bone-copy">
|
||
<div class="bone bone-name"></div>
|
||
<div class="bone bone-meta"></div>
|
||
</div>
|
||
<div class="spin" role="status" aria-label="正在获取"></div>
|
||
</div>
|
||
</div>
|
||
<n-tooltip placement="bottom">
|
||
<template #trigger>
|
||
<n-button
|
||
class="home-refresh"
|
||
quaternary
|
||
circle
|
||
size="small"
|
||
aria-label="刷新数据"
|
||
:loading="refreshing"
|
||
@click="refresh"
|
||
>
|
||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||
</n-button>
|
||
</template>
|
||
刷新数据
|
||
</n-tooltip>
|
||
</div>
|
||
<dl class="facts">
|
||
<div v-for="item in facts" :key="item.label">
|
||
<dt>{{ item.label }}</dt>
|
||
<dd>
|
||
<span v-if="summaryState === 'loading'" class="bone bone-value"></span>
|
||
<template v-else>{{ item.value || "—" }}</template>
|
||
</dd>
|
||
</div>
|
||
</dl>
|
||
<p v-if="summary?.limited" class="study-live-hint">只统计了最近 50 页</p>
|
||
</section>
|
||
|
||
<section class="panel-card study-card" :class="{ 'is-busy': studyingWorkers.length > 0 }">
|
||
<header class="study-head">
|
||
<h3>自动学习</h3>
|
||
<div class="study-state">
|
||
<span
|
||
class="study-indicator"
|
||
aria-hidden="true"
|
||
:class="{
|
||
active: !studyFailed && (studyControl.started || studyControl.active),
|
||
down: studyFailed,
|
||
}"
|
||
></span>
|
||
<span class="study-text" role="status" aria-live="polite" :class="{ muted: !studyControl.started && !studyControl.active && !studyFailed }">{{ studyLabel }}</span>
|
||
<span v-if="showHoursRefresh" class="study-text muted">页面学时刷新倒计时: {{ hoursRefreshLeft() }}s</span>
|
||
</div>
|
||
</header>
|
||
<n-alert v-if="studyError" class="summary-error" type="error">{{ studyError }}</n-alert>
|
||
<n-alert v-if="settingsLoadError" class="summary-error" type="error">
|
||
{{ settingsLoadError }}
|
||
<n-button class="retry-settings" size="tiny" quaternary @click="loadSettings">重试</n-button>
|
||
</n-alert>
|
||
<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="132" :show-feedback="false" size="small">
|
||
<n-form-item v-if="targetLoaded" label="每月目标">
|
||
<div class="target-control">
|
||
<n-input-number
|
||
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="start-control">
|
||
<n-switch v-model:value="scheduleEnabled" size="small" aria-label="定时启动" />
|
||
<n-select
|
||
v-model:value="startDay"
|
||
size="small"
|
||
:options="userDayOptions"
|
||
class="day-select"
|
||
:disabled="!scheduleEnabled"
|
||
aria-label="每月开始日"
|
||
/>
|
||
<n-time-picker
|
||
class="start-time"
|
||
v-model:formatted-value="startTime"
|
||
value-format="HH:mm:ss"
|
||
size="small"
|
||
:actions="null"
|
||
:disabled="!scheduleEnabled"
|
||
aria-label="开始时刻"
|
||
/>
|
||
</div>
|
||
</n-form-item>
|
||
<n-form-item v-if="workersLoaded" label="同时学习课程数">
|
||
<div class="target-control">
|
||
<n-select class="worker-select" v-model:value="courseWorkers" size="small" :options="workerOptions" />
|
||
<span class="target-unit">推荐:1</span>
|
||
</div>
|
||
</n-form-item>
|
||
<n-form-item v-if="heartbeatLoaded" label="心跳间隔">
|
||
<div class="target-control heartbeat-control">
|
||
<n-radio-group v-model:value="heartbeatMode" size="small">
|
||
<n-radio-button value="auto">自动获取</n-radio-button>
|
||
<n-radio-button value="manual">手动设定</n-radio-button>
|
||
</n-radio-group>
|
||
<span class="target-unit">推荐:自动获取</span>
|
||
</div>
|
||
</n-form-item>
|
||
<n-form-item v-if="heartbeatLoaded && heartbeatMode === 'manual'" label="间隔秒数">
|
||
<div class="pace-fields">
|
||
<label class="pace-field">
|
||
<span>视频</span>
|
||
<n-input-number v-model:value="heartbeatVideo" :show-button="false" :min="0" :max="300" :precision="0" size="small" />
|
||
</label>
|
||
<label class="pace-field">
|
||
<span>文档</span>
|
||
<n-input-number v-model:value="heartbeatDocument" :show-button="false" :min="0" :max="600" :precision="0" size="small" />
|
||
</label>
|
||
<label class="pace-field">
|
||
<span>Scorm</span>
|
||
<n-input-number v-model:value="heartbeatScorm" :show-button="false" :min="0" :max="600" :precision="0" size="small" />
|
||
</label>
|
||
</div>
|
||
</n-form-item>
|
||
</n-form>
|
||
<p v-if="heartbeatLoaded && heartbeatMode === 'manual'" class="study-config-hint">
|
||
间隔越短,发送越频繁。设为 0 时连续发送,课程列表不显示倒计时。
|
||
</p>
|
||
<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>
|
||
<span class="study-start-wrap">
|
||
<n-button type="success" size="small" :disabled="startBlocked !== ''" :loading="studyBusy" @click="toggleStudy">
|
||
<template #icon>
|
||
<n-icon><PlayOutline /></n-icon>
|
||
</template>
|
||
立即开始
|
||
</n-button>
|
||
</span>
|
||
</template>
|
||
{{ startBlocked || "按当前配置立刻开始,同时保存配置" }}
|
||
</n-tooltip>
|
||
<n-button v-else type="error" size="small" :loading="studyBusy" @click="toggleStudy">
|
||
<template #icon>
|
||
<n-icon><StopOutline /></n-icon>
|
||
</template>
|
||
停止
|
||
</n-button>
|
||
</div>
|
||
</div>
|
||
<div class="study-live">
|
||
<div v-if="targetLoaded" class="study-progress">
|
||
<div class="study-progress-meta">
|
||
<span>本月进度</span>
|
||
<span v-if="monthProgress.target > 0">{{ monthProgress.current }} / {{ monthProgress.target }} 分钟</span>
|
||
<span v-else>{{ monthProgress.current }} 分钟</span>
|
||
</div>
|
||
<n-progress type="line" :percentage="monthProgress.pct" :show-indicator="false" :height="6" />
|
||
</div>
|
||
<div v-if="studyingWorkers.length" class="study-courses" :class="{ 'no-countdown': !countdownOn }">
|
||
<div class="study-course-head" aria-hidden="true">
|
||
<span>正在学习</span>
|
||
<span></span>
|
||
<span class="num">进度</span>
|
||
<span class="num">学时(分钟)</span>
|
||
<span v-if="countdownOn" class="num">下次心跳</span>
|
||
<span></span>
|
||
</div>
|
||
<ul class="study-workers" aria-label="正在学习的课程">
|
||
<li v-for="row in studyingWorkers" :key="row.id" class="study-worker">
|
||
<span class="study-worker-title" :title="workerTitle(row)">{{ 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">{{ workerPercentText(row) }}</span>
|
||
<span class="study-worker-count" :aria-label="`已学 ${row.sent} 分钟,共 ${row.total} 分钟`">{{ workerMinutes(row) }}</span>
|
||
<span v-if="countdownOn" class="study-heartbeat">{{ showHeartbeat(row) ? heartbeatLeft(row) : "" }}</span>
|
||
<span class="study-dot" role="img" :class="row.ok ? 'up' : 'down'" :aria-label="row.ok ? '正常' : '异常'"></span>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<p v-else-if="studyHint" class="study-live-hint">{{ studyHint }}</p>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
<n-modal
|
||
:show="proxyOpen"
|
||
preset="card"
|
||
title="代理"
|
||
:style="{ width: 'min(420px, calc(100vw - 32px))' }"
|
||
@update:show="(show) => (proxyOpen = show)"
|
||
>
|
||
<n-alert v-if="proxyError" class="summary-error" type="error">{{ proxyError }}</n-alert>
|
||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="72" :show-feedback="false" size="small">
|
||
<ProxyFields
|
||
v-model:scheme="proxyScheme"
|
||
v-model:host="proxyHost"
|
||
v-model:port="proxyPort"
|
||
v-model:username="proxyUser"
|
||
v-model:password="proxyPassword"
|
||
:options="proxyOptions"
|
||
:manual="proxyManual"
|
||
size="small"
|
||
:password-placeholder="proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||
/>
|
||
</n-form>
|
||
<template #footer>
|
||
<div class="modal-actions">
|
||
<n-button @click="proxyOpen = false">取消</n-button>
|
||
<n-button type="primary" :loading="proxySaving" @click="saveProxy">保存</n-button>
|
||
</div>
|
||
</template>
|
||
</n-modal>
|
||
</section>
|
||
</template>
|