fix: 整理首页、登录和管理端的交互
This commit is contained in:
@@ -3,7 +3,18 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="robots" content="noindex" />
|
||||
<title>EunivTools</title>
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='4' fill='%23161A22'/%3E%3Ctext x='16' y='22' text-anchor='middle' font-size='18' font-family='Segoe UI,sans-serif' fill='%2379C0FF'%3EE%3C/text%3E%3C/svg%3E" />
|
||||
<script>
|
||||
try {
|
||||
if (localStorage.getItem("euniv-scheme") === "day") {
|
||||
document.documentElement.dataset.scheme = "day";
|
||||
}
|
||||
} catch {
|
||||
/* 本地存储不可用时沿用默认主题 */
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
+69
-24
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { darkTheme, dateZhCN, NConfigProvider, NDialogProvider, NMessageProvider, zhCN } from "naive-ui";
|
||||
import { darkTheme, dateZhCN, NButton, NConfigProvider, NDialogProvider, NMessageProvider, zhCN } from "naive-ui";
|
||||
import LoginView from "./features/auth/LoginView.vue";
|
||||
import Shell from "./shell/Shell.vue";
|
||||
import AdminShell from "./shell/AdminShell.vue";
|
||||
@@ -9,55 +9,88 @@ import { sessionFromPayload, type AppSession } from "./shared/session";
|
||||
|
||||
const ready = ref(false);
|
||||
const session = ref<AppSession | null>(null);
|
||||
const sessionError = ref("");
|
||||
|
||||
function applyPayload(payload: unknown) {
|
||||
if (!payload || typeof payload !== "object") return null;
|
||||
return sessionFromPayload(payload);
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await fetch("/api/session");
|
||||
if (response.ok) {
|
||||
session.value = applyPayload(await response.json().catch(() => null));
|
||||
}
|
||||
} finally {
|
||||
ready.value = true;
|
||||
}
|
||||
});
|
||||
|
||||
async function reloadSession() {
|
||||
async function loadSession() {
|
||||
try {
|
||||
const response = await fetch("/api/session");
|
||||
if (response.status === 401) {
|
||||
session.value = null;
|
||||
sessionError.value = "";
|
||||
return;
|
||||
}
|
||||
if (!response.ok) {
|
||||
sessionError.value = "暂时无法确认登录状态";
|
||||
return;
|
||||
}
|
||||
if (!response.ok) return;
|
||||
const next = applyPayload(await response.json().catch(() => null));
|
||||
if (next) session.value = next;
|
||||
if (!next) {
|
||||
sessionError.value = "暂时无法确认登录状态";
|
||||
return;
|
||||
}
|
||||
session.value = next;
|
||||
sessionError.value = "";
|
||||
} catch {
|
||||
return;
|
||||
sessionError.value = "暂时无法确认登录状态";
|
||||
} finally {
|
||||
ready.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadSession();
|
||||
});
|
||||
|
||||
async function exitSystem() {
|
||||
await fetch("/api/logout", { method: "POST" });
|
||||
session.value = null;
|
||||
try {
|
||||
const response = await fetch("/api/logout", { method: "POST" });
|
||||
if (!response.ok) {
|
||||
sessionError.value = "没有退出。";
|
||||
return;
|
||||
}
|
||||
session.value = null;
|
||||
sessionError.value = "";
|
||||
} catch {
|
||||
sessionError.value = "没有退出。";
|
||||
}
|
||||
}
|
||||
|
||||
async function revokeAccount() {
|
||||
await fetch("/api/revoke", { method: "POST" });
|
||||
session.value = null;
|
||||
try {
|
||||
const response = await fetch("/api/revoke", { method: "POST" });
|
||||
if (!response.ok) {
|
||||
sessionError.value = "没有注销。";
|
||||
return;
|
||||
}
|
||||
session.value = null;
|
||||
sessionError.value = "";
|
||||
} catch {
|
||||
sessionError.value = "没有注销。";
|
||||
}
|
||||
}
|
||||
|
||||
async function exitAdmin() {
|
||||
await fetch("/api/admin/logout", { method: "POST" });
|
||||
session.value = null;
|
||||
try {
|
||||
const response = await fetch("/api/admin/logout", { method: "POST" });
|
||||
if (!response.ok) {
|
||||
sessionError.value = "没有退出。";
|
||||
return;
|
||||
}
|
||||
session.value = null;
|
||||
sessionError.value = "";
|
||||
} catch {
|
||||
sessionError.value = "没有退出。";
|
||||
}
|
||||
}
|
||||
|
||||
function onLogin(next: AppSession) {
|
||||
session.value = next;
|
||||
sessionError.value = "";
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -65,10 +98,22 @@ function onLogin(next: AppSession) {
|
||||
<n-config-provider class="app-root" :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides">
|
||||
<n-message-provider class="app-root">
|
||||
<n-dialog-provider>
|
||||
<div v-if="ready" class="app-root">
|
||||
<div v-if="ready && sessionError && !session" class="gate">
|
||||
<section class="gate-card">
|
||||
<p class="session-note">暂时无法确认登录状态</p>
|
||||
<div class="gate-actions">
|
||||
<n-button type="primary" @click="loadSession">重试</n-button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div v-else-if="ready" class="app-root">
|
||||
<div v-if="session && sessionError" class="session-banner session-banner-float">
|
||||
<p>暂时无法确认登录状态</p>
|
||||
<n-button size="small" @click="loadSession">重试</n-button>
|
||||
</div>
|
||||
<LoginView v-if="!session" @success="onLogin" />
|
||||
<Shell v-else-if="session.kind === 'user'" :employee-id="session.employeeId" @logout="exitSystem" @revoke="revokeAccount" />
|
||||
<AdminShell v-else-if="session.kind === 'admin'" :username="session.username" @logout="exitAdmin" @refresh="reloadSession" />
|
||||
<AdminShell v-else-if="session.kind === 'admin'" :username="session.username" @logout="exitAdmin" @refresh="loadSession" />
|
||||
</div>
|
||||
</n-dialog-provider>
|
||||
</n-message-provider>
|
||||
|
||||
@@ -11,7 +11,6 @@ interface CourseRow {
|
||||
learners: string;
|
||||
released_on: string;
|
||||
updated_on: string;
|
||||
comments: string;
|
||||
}
|
||||
|
||||
interface KindOption {
|
||||
@@ -54,10 +53,19 @@ function asCourse(value: unknown): CourseRow | null {
|
||||
learners: textOf(value.learners),
|
||||
released_on: textOf(value.released_on),
|
||||
updated_on: textOf(value.updated_on),
|
||||
comments: textOf(value.comments),
|
||||
};
|
||||
}
|
||||
|
||||
function setError(next: string) {
|
||||
if (errorText.value !== next) errorText.value = next;
|
||||
}
|
||||
|
||||
function courseKey(row: CourseRow, index: number) {
|
||||
const base = row.url || row.title || "course";
|
||||
const first = items.value.findIndex((item) => (item.url || item.title || "course") === base);
|
||||
return first === index ? base : `${base}#${index}`;
|
||||
}
|
||||
|
||||
function formatTime(value: string | null) {
|
||||
if (!value) return "";
|
||||
const date = new Date(value);
|
||||
@@ -66,9 +74,8 @@ function formatTime(value: string | null) {
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = items.value.length === 0;
|
||||
errorText.value = "";
|
||||
async function load(clamp = true) {
|
||||
if (items.value.length === 0) loading.value = true;
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
q: appliedQuery.value,
|
||||
@@ -79,11 +86,11 @@ async function load() {
|
||||
const response = await fetch(`/api/admin/courses?${params}`);
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "课程清单没有获取到。";
|
||||
setError("课程清单没有获取到。");
|
||||
return;
|
||||
}
|
||||
if (!isRecord(payload) || !Array.isArray(payload.items)) {
|
||||
errorText.value = "课程清单没有获取到。";
|
||||
setError("数据异常");
|
||||
return;
|
||||
}
|
||||
items.value = payload.items.map(asCourse).filter((item): item is CourseRow => item !== null);
|
||||
@@ -91,11 +98,17 @@ async function load() {
|
||||
syncedAt.value = typeof payload.synced_at === "string" ? payload.synced_at : null;
|
||||
kinds.value = Array.isArray(payload.kinds) ? payload.kinds.flatMap(asKind) : [];
|
||||
fetching.value = payload.running === true;
|
||||
if (typeof payload.message === "string" && payload.message) errorText.value = payload.message;
|
||||
const message = typeof payload.message === "string" ? payload.message : "";
|
||||
setError(message);
|
||||
if (fetching.value) startPoll();
|
||||
else stopPoll();
|
||||
const maxPage = Math.max(1, Math.ceil(total.value / pageSize.value));
|
||||
if (clamp && page.value > maxPage) {
|
||||
page.value = maxPage;
|
||||
await load(false);
|
||||
}
|
||||
} catch {
|
||||
errorText.value = "课程清单没有获取到。";
|
||||
setError("课程清单没有获取到。");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
@@ -112,20 +125,20 @@ function stopPoll() {
|
||||
}
|
||||
|
||||
async function loadCourses() {
|
||||
errorText.value = "";
|
||||
setError("");
|
||||
fetching.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/admin/courses/load", { method: "POST" });
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
fetching.value = false;
|
||||
errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "课程清单没有获取到。";
|
||||
setError("课程清单没有获取到。");
|
||||
return;
|
||||
}
|
||||
startPoll();
|
||||
await load();
|
||||
} catch {
|
||||
fetching.value = false;
|
||||
errorText.value = "课程清单没有获取到。";
|
||||
setError("课程清单没有获取到。");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,11 +186,11 @@ onUnmounted(() => stopPoll());
|
||||
<form class="course-search" @submit.prevent="search">
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button quaternary circle attr-type="button" :loading="fetching" :disabled="fetching" aria-label="加载课程列表" @click="loadCourses">
|
||||
<n-button quaternary circle attr-type="button" :loading="fetching" :disabled="fetching" aria-label="加载课程清单" @click="loadCourses">
|
||||
<template #icon><n-icon><DownloadOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
加载课程列表
|
||||
加载课程清单
|
||||
</n-tooltip>
|
||||
<n-input v-model:value="query" placeholder="名称或贡献者" clearable @clear="search" />
|
||||
<n-button attr-type="submit">搜索</n-button>
|
||||
@@ -200,8 +213,8 @@ onUnmounted(() => stopPoll());
|
||||
<div class="admin-scroll">
|
||||
<p v-if="loading" class="admin-status">正在获取</p>
|
||||
<p v-else-if="fetching && !items.length" class="admin-status">正在获取</p>
|
||||
<p v-else-if="!items.length" class="admin-status">还没有课程</p>
|
||||
<table v-else class="admin-table">
|
||||
<p v-else-if="!items.length && !errorText" class="admin-status">还没有课程</p>
|
||||
<table v-else-if="items.length" class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>名称</th>
|
||||
@@ -214,7 +227,7 @@ onUnmounted(() => stopPoll());
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in items" :key="`${row.title}-${row.updated_on}`">
|
||||
<tr v-for="(row, index) in items" :key="courseKey(row, index)">
|
||||
<td>{{ row.title }}</td>
|
||||
<td>{{ row.kind }}</td>
|
||||
<td class="course-url"><a v-if="row.url" :href="row.url" target="_blank" rel="noreferrer">{{ row.url }}</a></td>
|
||||
|
||||
@@ -49,6 +49,7 @@ const kinds = computed<StatusOption[]>(() => [
|
||||
{ name: "待检测", value: "new", count: pending.value },
|
||||
]);
|
||||
const kindTotal = computed(() => alive.value + dead.value + pending.value);
|
||||
const probeScope = computed(() => (appliedQuery.value || status.value ? "当前筛选" : "全部"));
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return !!value && typeof value === "object" && !Array.isArray(value);
|
||||
@@ -99,15 +100,35 @@ function schemeLabel(value: string) {
|
||||
return value ? value.toUpperCase() : "—";
|
||||
}
|
||||
|
||||
function setError(next: string) {
|
||||
if (errorText.value !== next) errorText.value = next;
|
||||
}
|
||||
|
||||
function proxyKey(row: ProxyRow, index: number) {
|
||||
const first = items.value.findIndex((item) => item.id === row.id);
|
||||
return first === index ? String(row.id) : `${row.id}#${index}`;
|
||||
}
|
||||
|
||||
function shiftCount(kind: string, delta: number) {
|
||||
if (kind === "alive") alive.value += delta;
|
||||
else if (kind === "dead") dead.value += delta;
|
||||
else if (kind === "new") pending.value += delta;
|
||||
}
|
||||
|
||||
function adjustCounts(previous: ProxyRow, next: ProxyRow) {
|
||||
if (previous.status === next.status) return;
|
||||
shiftCount(previous.status, -1);
|
||||
shiftCount(next.status, 1);
|
||||
}
|
||||
|
||||
function statusClass(row: ProxyRow) {
|
||||
if (row.status === "alive") return "ok";
|
||||
if (row.status === "dead") return "late";
|
||||
return "quiet";
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = items.value.length === 0;
|
||||
errorText.value = "";
|
||||
async function load(clamp = true) {
|
||||
if (items.value.length === 0) loading.value = true;
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
q: appliedQuery.value,
|
||||
@@ -118,11 +139,11 @@ async function load() {
|
||||
const response = await fetch(`/api/admin/proxies?${params}`);
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "代理列表没有获取到。";
|
||||
setError("代理列表没有获取到。");
|
||||
return;
|
||||
}
|
||||
if (!isRecord(payload) || !Array.isArray(payload.items)) {
|
||||
errorText.value = "代理列表没有获取到。";
|
||||
setError("数据异常");
|
||||
return;
|
||||
}
|
||||
items.value = payload.items.map(asRow).filter((item): item is ProxyRow => item !== null);
|
||||
@@ -132,11 +153,17 @@ async function load() {
|
||||
pending.value = typeof payload.pending === "number" ? payload.pending : 0;
|
||||
fetchedAt.value = typeof payload.fetched_at === "string" && payload.fetched_at ? payload.fetched_at : null;
|
||||
fetching.value = payload.running === true;
|
||||
if (typeof payload.message === "string" && payload.message) errorText.value = payload.message;
|
||||
const message = typeof payload.message === "string" ? payload.message : "";
|
||||
setError(message);
|
||||
if (fetching.value) startPoll();
|
||||
else stopPoll();
|
||||
const maxPage = Math.max(1, Math.ceil(total.value / pageSize.value));
|
||||
if (clamp && page.value > maxPage) {
|
||||
page.value = maxPage;
|
||||
await load(false);
|
||||
}
|
||||
} catch {
|
||||
errorText.value = "代理列表没有获取到。";
|
||||
setError("代理列表没有获取到。");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
@@ -159,62 +186,95 @@ function applyProbed(row: ProxyRow) {
|
||||
async function probeOne(row: ProxyRow) {
|
||||
if (probingId.value != null || probingAll.value || fetching.value) return;
|
||||
probingId.value = row.id;
|
||||
errorText.value = "";
|
||||
setError("");
|
||||
try {
|
||||
const response = await fetch(`/api/admin/proxies/${row.id}/probe`, { method: "POST" });
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "没有测出延迟。";
|
||||
setError("没有测出延迟。");
|
||||
return;
|
||||
}
|
||||
const next = asRow(payload);
|
||||
if (next) applyProbed(next);
|
||||
if (next) {
|
||||
const previous = items.value.find((item) => item.id === next.id);
|
||||
if (previous) adjustCounts(previous, next);
|
||||
applyProbed(next);
|
||||
}
|
||||
} catch {
|
||||
errorText.value = "没有测出延迟。";
|
||||
setError("没有测出延迟。");
|
||||
} finally {
|
||||
probingId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function filteredIds() {
|
||||
if (!appliedQuery.value && !status.value) return null;
|
||||
const ids: number[] = [];
|
||||
const limit = 100;
|
||||
let offset = 0;
|
||||
for (;;) {
|
||||
const params = new URLSearchParams({
|
||||
q: appliedQuery.value,
|
||||
status: status.value,
|
||||
offset: String(offset),
|
||||
limit: String(limit),
|
||||
});
|
||||
const response = await fetch(`/api/admin/proxies?${params}`);
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok || !isRecord(payload) || !Array.isArray(payload.items)) {
|
||||
throw new Error("代理列表没有获取到。");
|
||||
}
|
||||
const page = payload.items.map(asRow).filter((item): item is ProxyRow => item !== null);
|
||||
for (const row of page) ids.push(row.id);
|
||||
if (page.length < limit) return ids;
|
||||
offset += limit;
|
||||
if (offset > 10000) return ids;
|
||||
}
|
||||
}
|
||||
|
||||
async function probeAll() {
|
||||
if (probingId.value != null || probingAll.value || fetching.value || !items.value.length) return;
|
||||
if (probingId.value != null || probingAll.value || fetching.value) return;
|
||||
probingAll.value = true;
|
||||
errorText.value = "";
|
||||
setError("");
|
||||
try {
|
||||
const ids = await filteredIds();
|
||||
if (ids && !ids.length) {
|
||||
setError("没有可测试的代理。");
|
||||
return;
|
||||
}
|
||||
const response = await fetch("/api/admin/proxies/probe", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({}),
|
||||
body: JSON.stringify(ids ? { ids } : {}),
|
||||
});
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "没有测出延迟。";
|
||||
if (!response.ok || !isRecord(payload)) {
|
||||
setError("没有测出延迟。");
|
||||
return;
|
||||
}
|
||||
await load();
|
||||
} catch {
|
||||
errorText.value = "没有测出延迟。";
|
||||
setError("没有测出延迟。");
|
||||
} finally {
|
||||
probingAll.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshNow() {
|
||||
errorText.value = "";
|
||||
setError("");
|
||||
fetching.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/admin/proxies/refresh", { method: "POST" });
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
fetching.value = false;
|
||||
errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "没有更新。";
|
||||
setError("没有更新。");
|
||||
return;
|
||||
}
|
||||
startPoll();
|
||||
await load();
|
||||
} catch {
|
||||
fetching.value = false;
|
||||
errorText.value = "没有更新。";
|
||||
setError("没有更新。");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,8 +324,8 @@ onUnmounted(() => stopPoll());
|
||||
</template>
|
||||
立即更新
|
||||
</n-tooltip>
|
||||
<n-button size="small" attr-type="button" :loading="probingAll" :disabled="probingAll || fetching || !items.length" @click="probeAll">
|
||||
测试全部
|
||||
<n-button size="small" attr-type="button" :loading="probingAll" :disabled="probingAll || fetching" @click="probeAll">
|
||||
测试{{ probeScope }}
|
||||
</n-button>
|
||||
<n-input v-model:value="query" placeholder="地址" clearable @clear="search" />
|
||||
<n-button attr-type="submit">搜索</n-button>
|
||||
@@ -285,13 +345,13 @@ onUnmounted(() => stopPoll());
|
||||
</button>
|
||||
</div>
|
||||
<n-alert v-if="errorText" class="admin-alert" type="error">{{ errorText }}</n-alert>
|
||||
<n-alert v-if="probingAll" class="admin-alert" type="info">正在测试全部代理延迟</n-alert>
|
||||
<n-alert v-if="probingAll" class="admin-alert" type="info">正在测试{{ probeScope }}代理延迟</n-alert>
|
||||
<n-alert v-else-if="probingId != null" class="admin-alert" type="info">正在测试 {{ probingHost }} 延迟</n-alert>
|
||||
<div class="admin-scroll">
|
||||
<p v-if="loading" class="admin-status">正在获取</p>
|
||||
<p v-else-if="fetching && !items.length" class="admin-status">正在获取</p>
|
||||
<p v-else-if="!items.length" class="admin-status">还没有代理</p>
|
||||
<table v-else class="admin-table">
|
||||
<p v-else-if="!items.length && !errorText" class="admin-status">还没有代理</p>
|
||||
<table v-else-if="items.length" class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>国家</th>
|
||||
@@ -307,7 +367,7 @@ onUnmounted(() => stopPoll());
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="row in items" :key="row.id">
|
||||
<tr v-for="(row, index) in items" :key="proxyKey(row, index)">
|
||||
<td>{{ row.country }}</td>
|
||||
<td class="employee">{{ row.host }}</td>
|
||||
<td class="when">{{ row.port }}</td>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import { NAlert, NButton, NForm, NFormItem, NInput, NInputNumber, NRadioButton, NRadioGroup, NSwitch } from "naive-ui";
|
||||
|
||||
const emit = defineEmits<{ saved: [] }>();
|
||||
@@ -23,9 +23,7 @@ const hbDocument = ref<number | null>(120);
|
||||
const hbScorm = ref<number | null>(120);
|
||||
const hoursSource = ref("api");
|
||||
|
||||
const preferenceLabel = computed(() =>
|
||||
showManualJigsaw.value ? "默认勾选手动滑动验证码" : "先尝试自动滑动验证码",
|
||||
);
|
||||
let savedTimer = 0;
|
||||
|
||||
function detailOf(payload: unknown, fallback: string) {
|
||||
if (payload && typeof payload === "object" && "detail" in payload) {
|
||||
@@ -44,6 +42,8 @@ function readNumber(value: unknown) {
|
||||
return null;
|
||||
}
|
||||
|
||||
onUnmounted(() => window.clearTimeout(savedTimer));
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await fetch("/api/admin/settings");
|
||||
@@ -126,7 +126,7 @@ async function save() {
|
||||
};
|
||||
if (password.value !== "" || confirmPassword.value !== "") {
|
||||
if (!currentPassword.value) {
|
||||
errorText.value = "请填写当前管理员密码";
|
||||
errorText.value = "请填写管理员密码";
|
||||
return;
|
||||
}
|
||||
if (password.value !== confirmPassword.value) {
|
||||
@@ -152,6 +152,11 @@ async function save() {
|
||||
confirmPassword.value = "";
|
||||
currentPassword.value = "";
|
||||
successText.value = "已保存";
|
||||
window.clearTimeout(savedTimer);
|
||||
savedTimer = window.setTimeout(() => {
|
||||
successText.value = "";
|
||||
savedTimer = 0;
|
||||
}, 3000);
|
||||
emit("saved");
|
||||
} catch {
|
||||
errorText.value = "没有保存。";
|
||||
@@ -163,9 +168,9 @@ async function save() {
|
||||
|
||||
<template>
|
||||
<section class="page admin-page">
|
||||
<form class="settings-form" @submit.prevent="save">
|
||||
<div class="settings-form">
|
||||
<header class="page-head">
|
||||
<n-button type="primary" attr-type="submit" :loading="saving" :disabled="!loaded">保存</n-button>
|
||||
<n-button type="primary" :loading="saving" :disabled="!loaded" @click="save">保存</n-button>
|
||||
</header>
|
||||
<n-alert v-if="errorText" class="admin-alert" type="error">{{ errorText }}</n-alert>
|
||||
<n-alert v-else-if="successText" class="admin-alert" type="success">{{ successText }}</n-alert>
|
||||
@@ -174,22 +179,22 @@ async function save() {
|
||||
<template v-else-if="loaded">
|
||||
<section class="panel-card">
|
||||
<h3>登录验证</h3>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small">
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
||||
<n-form-item label="定时刷新间隔">
|
||||
<div class="target-control">
|
||||
<n-input-number id="refresh-interval" v-model:value="refreshInterval" button-placement="both" :min="1" :max="1440" :precision="0" />
|
||||
<n-input-number v-model:value="refreshInterval" button-placement="both" :min="1" :max="1440" :precision="0" />
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item label="显示手动滑动验证码">
|
||||
<n-switch v-model:value="showManualJigsaw" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="preferenceLabel">
|
||||
<n-form-item label="默认勾选手动滑动验证码">
|
||||
<n-switch v-model:value="manualPreference" />
|
||||
</n-form-item>
|
||||
<n-form-item label="自动滑动次数">
|
||||
<div class="target-control">
|
||||
<n-input-number id="auto-attempts" v-model:value="attempts" button-placement="both" :min="1" :max="10" :precision="0" />
|
||||
<n-input-number v-model:value="attempts" button-placement="both" :min="1" :max="10" :precision="0" />
|
||||
<span class="target-unit">次</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
@@ -197,7 +202,7 @@ async function save() {
|
||||
</section>
|
||||
<section class="panel-card">
|
||||
<h3>自动学习心跳</h3>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small">
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
||||
<n-form-item label="间隔来源">
|
||||
<n-radio-group v-model:value="hbMode" size="small">
|
||||
<n-radio-button value="auto">自动获取</n-radio-button>
|
||||
@@ -208,19 +213,19 @@ async function save() {
|
||||
<template v-else>
|
||||
<n-form-item label="视频">
|
||||
<div class="target-control">
|
||||
<n-input-number id="hb-video" v-model:value="hbVideo" button-placement="both" :min="0" :max="300" :precision="0" />
|
||||
<n-input-number v-model:value="hbVideo" button-placement="both" :min="0" :max="300" :precision="0" />
|
||||
<span class="target-unit">秒</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item label="文档">
|
||||
<div class="target-control">
|
||||
<n-input-number id="hb-document" v-model:value="hbDocument" button-placement="both" :min="0" :max="600" :precision="0" />
|
||||
<n-input-number v-model:value="hbDocument" button-placement="both" :min="0" :max="600" :precision="0" />
|
||||
<span class="target-unit">秒</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item label="Scorm">
|
||||
<div class="target-control">
|
||||
<n-input-number id="hb-scorm" v-model:value="hbScorm" button-placement="both" :min="0" :max="600" :precision="0" />
|
||||
<n-input-number v-model:value="hbScorm" button-placement="both" :min="0" :max="600" :precision="0" />
|
||||
<span class="target-unit">秒</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
@@ -229,7 +234,7 @@ async function save() {
|
||||
</section>
|
||||
<section class="panel-card">
|
||||
<h3>学时达标</h3>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small">
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
||||
<n-form-item label="判断依据">
|
||||
<n-radio-group v-model:value="hoursSource" size="small">
|
||||
<n-radio-button value="api">接口本月学时</n-radio-button>
|
||||
@@ -241,23 +246,23 @@ async function save() {
|
||||
</section>
|
||||
<section class="panel-card">
|
||||
<h3>管理员</h3>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small">
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="176" :show-feedback="false" size="small" @submit.prevent="save">
|
||||
<n-form-item label="用户名">
|
||||
<n-input v-model:value="username" autocomplete="username" />
|
||||
<n-input v-model:value="username" :input-props="{ autocomplete: 'username', name: 'username' }" />
|
||||
</n-form-item>
|
||||
<n-form-item label="当前管理员密码">
|
||||
<n-input v-model:value="currentPassword" type="password" show-password-on="click" placeholder="修改密码时填写" autocomplete="current-password" />
|
||||
<n-form-item label="管理员密码">
|
||||
<n-input v-model:value="currentPassword" type="password" show-password-on="click" placeholder="修改密码时填写" :input-props="{ autocomplete: 'current-password', name: 'current-password' }" />
|
||||
</n-form-item>
|
||||
<n-form-item label="新管理员密码">
|
||||
<n-input v-model:value="password" type="password" show-password-on="click" placeholder="不修改请留空" autocomplete="new-password" />
|
||||
<n-input v-model:value="password" type="password" show-password-on="click" placeholder="不修改请留空" :input-props="{ autocomplete: 'new-password', name: 'new-password' }" />
|
||||
</n-form-item>
|
||||
<n-form-item label="再输入一次">
|
||||
<n-input v-model:value="confirmPassword" type="password" show-password-on="click" placeholder="请输入" autocomplete="new-password" />
|
||||
<n-input v-model:value="confirmPassword" type="password" show-password-on="click" placeholder="请输入" :input-props="{ autocomplete: 'new-password', name: 'confirm-password' }" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NCheckbox, NDropdown, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NSelect, NSwitch, NTimePicker, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
||||
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, HelpCircleOutline, PauseOutline, PlayOutline, SettingsOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerHint, workerOptions } from "../../shared/studyFields";
|
||||
import { NAlert, NButton, NCheckbox, NDropdown, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NRadioButton, NRadioGroup, NSelect, NTimePicker, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
||||
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, PauseOutline, PlayOutline, SettingsOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerOptions } from "../../shared/studyFields";
|
||||
|
||||
interface UserRow {
|
||||
employee_id: string;
|
||||
@@ -24,6 +24,9 @@ interface UserRow {
|
||||
study_paused: boolean;
|
||||
study_ignore_window: boolean;
|
||||
study_started: boolean;
|
||||
hours_month: string;
|
||||
study_active: boolean | null;
|
||||
study_state: string;
|
||||
}
|
||||
|
||||
interface SecretField {
|
||||
@@ -55,16 +58,21 @@ const startDay = ref<number | null>(1);
|
||||
const startHour = ref<number | null>(0);
|
||||
const startMinute = ref<number | null>(0);
|
||||
const startSecond = ref<number | null>(0);
|
||||
const scheduleEnabled = ref(true);
|
||||
const scheduleChoice = ref<"keep" | "on" | "off">("keep");
|
||||
const workersValue = ref<number | null>(1);
|
||||
const proxyScheme = ref("off");
|
||||
const proxyScheme = ref("keep");
|
||||
const settingsReady = ref(false);
|
||||
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 proxyManual = computed(() => proxyScheme.value !== "off" && proxyScheme.value !== "pool" && proxyScheme.value !== "keep");
|
||||
const scheduleTimeDisabled = computed(() => scheduleChoice.value === "off");
|
||||
const proxyAccountProps = { autocomplete: "off", name: "proxy-account" };
|
||||
const proxyPasswordProps = { autocomplete: "new-password", name: "proxy-password" };
|
||||
const proxyOptions = [
|
||||
{ label: "保持不变", value: "keep" },
|
||||
{ label: "关闭", value: "off" },
|
||||
{ label: "自动", value: "pool" },
|
||||
{ label: "HTTP", value: "http" },
|
||||
@@ -82,13 +90,30 @@ const moreOptions = computed<DropdownOption[]>(() => [
|
||||
]);
|
||||
|
||||
const tokenFields: { label: string; key: string }[] = [
|
||||
{ label: "统一认证 token", key: "ucs_token" },
|
||||
{ label: "统一认证登录凭证", key: "ucs_token" },
|
||||
{ label: "账号标识", key: "ucs_account_id" },
|
||||
{ label: "用户标识", key: "ucs_user_id" },
|
||||
{ label: "ssoinfo", key: "ucs_ssoinfo" },
|
||||
{ label: "unionId", key: "ucs_union_id" },
|
||||
{ label: "学习平台 token", key: "yxt_token" },
|
||||
{ label: "单点登录信息", key: "ucs_ssoinfo" },
|
||||
{ label: "联合身份", key: "ucs_union_id" },
|
||||
{ label: "学习平台登录凭证", key: "yxt_token" },
|
||||
];
|
||||
const QR_PASSWORD_MARK = "扫码登陆";
|
||||
let credentialRequest = 0;
|
||||
let settingsBaseline: SettingsBaseline | null = null;
|
||||
|
||||
interface SettingsBaseline {
|
||||
monthlyTarget: number | null;
|
||||
startDay: number | null;
|
||||
startHour: number | null;
|
||||
startMinute: number | null;
|
||||
startSecond: number | null;
|
||||
scheduleChoice: "keep" | "on" | "off";
|
||||
workers: number | null;
|
||||
scheme: string;
|
||||
host: string;
|
||||
port: number | null;
|
||||
username: string;
|
||||
}
|
||||
|
||||
function pad(value: number) {
|
||||
return String(value).padStart(2, "0");
|
||||
@@ -96,10 +121,16 @@ function pad(value: number) {
|
||||
|
||||
const startTime = computed({
|
||||
get() {
|
||||
return `${pad(startHour.value ?? 0)}:${pad(startMinute.value ?? 0)}:${pad(startSecond.value ?? 0)}`;
|
||||
if (startHour.value == null || startMinute.value == null || startSecond.value == null) return null;
|
||||
return `${pad(startHour.value)}:${pad(startMinute.value)}:${pad(startSecond.value)}`;
|
||||
},
|
||||
set(value: string | null) {
|
||||
if (!value) return;
|
||||
if (!value) {
|
||||
startHour.value = null;
|
||||
startMinute.value = null;
|
||||
startSecond.value = null;
|
||||
return;
|
||||
}
|
||||
const [hour, minute, second] = value.split(":").map((part) => Number(part));
|
||||
if (![hour, minute, second].every((part) => Number.isInteger(part))) return;
|
||||
startHour.value = hour;
|
||||
@@ -149,9 +180,40 @@ function asUser(value: unknown): UserRow | null {
|
||||
study_paused: value.study_paused === true,
|
||||
study_ignore_window: value.study_ignore_window === true,
|
||||
study_started: value.study_started === true,
|
||||
hours_month: textOf(value.hours_month),
|
||||
study_active: typeof value.study_active === "boolean" ? value.study_active : null,
|
||||
study_state: textOf(value.state) || textOf(value.study_state),
|
||||
};
|
||||
}
|
||||
|
||||
function beijingMonth() {
|
||||
return new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Shanghai", year: "numeric", month: "2-digit" }).format(new Date()).slice(0, 7);
|
||||
}
|
||||
|
||||
function monthHoursText(row: UserRow) {
|
||||
const hours = row.month_hours.trim();
|
||||
if (!hours) return "—";
|
||||
if (row.hours_month && row.hours_month !== beijingMonth()) return "—";
|
||||
return `${hours} 分钟`;
|
||||
}
|
||||
|
||||
function taskText(row: UserRow) {
|
||||
const state = row.study_state;
|
||||
if (row.study_active === true || state === "运行中" || state === "学习中" || state === "准备") return "运行中";
|
||||
if (state === "排队中") return "排队中";
|
||||
if (row.study_paused || state === "已停止") return "已停止";
|
||||
return "未开始";
|
||||
}
|
||||
|
||||
function taskCanStop(row: UserRow) {
|
||||
const text = taskText(row);
|
||||
return text === "运行中" || text === "排队中";
|
||||
}
|
||||
|
||||
function passwordText(password: string) {
|
||||
return password === QR_PASSWORD_MARK ? "扫码登录,没有保存密码" : password;
|
||||
}
|
||||
|
||||
function formatRefreshTime(value: string | null) {
|
||||
if (!value) return "";
|
||||
const date = new Date(value);
|
||||
@@ -163,7 +225,7 @@ function formatRefreshTime(value: string | null) {
|
||||
function checkLabel(payload: Record<string, unknown>) {
|
||||
const result = payload.result;
|
||||
if (result === "有效" || result === "已失效" || result === "检查失败") return result;
|
||||
if (result === "未保存" || result === "未保存凭证") return "未保存凭证";
|
||||
if (result === "未保存" || result === "未保存凭证" || result === "未保存凭据") return "未保存凭据";
|
||||
return "检查失败";
|
||||
}
|
||||
|
||||
@@ -171,7 +233,7 @@ function validityText(row: UserRow) {
|
||||
if (checkingAll.value || checkingId.value === row.employee_id) return "正在检查";
|
||||
const live = liveResults.value[row.employee_id];
|
||||
if (live) return live;
|
||||
if (!row.has_credential) return "未保存凭证";
|
||||
if (!row.has_credential) return "未保存凭据";
|
||||
if (row.credential_valid === true) return "有效";
|
||||
if (row.credential_valid === false) return "已失效";
|
||||
return "未检查";
|
||||
@@ -183,12 +245,6 @@ function validityClass(text: string) {
|
||||
return "quiet";
|
||||
}
|
||||
|
||||
function taskText(row: UserRow) {
|
||||
if (row.study_started) return "已开始";
|
||||
if (row.study_paused) return "已停止";
|
||||
return "未开始";
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
try {
|
||||
@@ -284,11 +340,11 @@ function resetCredential() {
|
||||
|
||||
function applyCredential(payload: Record<string, unknown>) {
|
||||
const note = textOf(payload.detail);
|
||||
const password = textOf(payload.password);
|
||||
const password = passwordText(textOf(payload.password));
|
||||
const tokens = tokenFields.map((item) => ({ label: item.label, value: textOf(payload[item.key]) }));
|
||||
const hasToken = tokens.some((item) => item.value !== "");
|
||||
if (note && !hasToken) {
|
||||
credentialNote.value = note;
|
||||
credentialNote.value = note === QR_PASSWORD_MARK ? "" : note;
|
||||
credentialFields.value = password ? [{ label: "密码", value: password }] : [];
|
||||
return;
|
||||
}
|
||||
@@ -296,12 +352,23 @@ function applyCredential(payload: Record<string, unknown>) {
|
||||
credentialFields.value = [{ label: "密码", value: password }, ...tokens];
|
||||
}
|
||||
|
||||
function closeCredentials() {
|
||||
credentialRequest += 1;
|
||||
credentialOpen.value = false;
|
||||
resetCredential();
|
||||
}
|
||||
|
||||
function onCredentialShow(show: boolean) {
|
||||
credentialOpen.value = show;
|
||||
if (!show) resetCredential();
|
||||
if (show) {
|
||||
credentialOpen.value = true;
|
||||
return;
|
||||
}
|
||||
if (credentialOpen.value) closeCredentials();
|
||||
else resetCredential();
|
||||
}
|
||||
|
||||
async function openCredentials(row: UserRow) {
|
||||
const current = ++credentialRequest;
|
||||
credentialTitle.value = `工号 ${row.employee_id} 的凭据`;
|
||||
resetCredential();
|
||||
credentialLoading.value = true;
|
||||
@@ -309,15 +376,16 @@ async function openCredentials(row: UserRow) {
|
||||
try {
|
||||
const response = await fetch(`/api/admin/users/${encodeURIComponent(row.employee_id)}/credentials`);
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (current !== credentialRequest || !credentialOpen.value) return;
|
||||
if (!response.ok || !isRecord(payload)) {
|
||||
credentialError.value = detailOf(payload, "凭据没有获取到。");
|
||||
credentialError.value = "凭据没有获取到。";
|
||||
return;
|
||||
}
|
||||
applyCredential(payload);
|
||||
} catch {
|
||||
credentialError.value = "凭据没有获取到。";
|
||||
if (current === credentialRequest && credentialOpen.value) credentialError.value = "凭据没有获取到。";
|
||||
} finally {
|
||||
credentialLoading.value = false;
|
||||
if (current === credentialRequest) credentialLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,14 +457,14 @@ function toggleAll(checked: boolean) {
|
||||
}
|
||||
|
||||
function resetSettingsForm() {
|
||||
monthlyTarget.value = 600;
|
||||
startDay.value = 1;
|
||||
startHour.value = 0;
|
||||
startMinute.value = 0;
|
||||
startSecond.value = 0;
|
||||
scheduleEnabled.value = true;
|
||||
workersValue.value = 1;
|
||||
proxyScheme.value = "off";
|
||||
monthlyTarget.value = null;
|
||||
startDay.value = null;
|
||||
startHour.value = null;
|
||||
startMinute.value = null;
|
||||
startSecond.value = null;
|
||||
scheduleChoice.value = "keep";
|
||||
workersValue.value = null;
|
||||
proxyScheme.value = "keep";
|
||||
proxyHost.value = "";
|
||||
proxyPort.value = null;
|
||||
proxyUser.value = "";
|
||||
@@ -405,72 +473,173 @@ function resetSettingsForm() {
|
||||
settingsError.value = "";
|
||||
}
|
||||
|
||||
function captureSettings(): SettingsBaseline {
|
||||
return {
|
||||
monthlyTarget: monthlyTarget.value,
|
||||
startDay: startDay.value,
|
||||
startHour: startHour.value,
|
||||
startMinute: startMinute.value,
|
||||
startSecond: startSecond.value,
|
||||
scheduleChoice: scheduleChoice.value,
|
||||
workers: workersValue.value,
|
||||
scheme: proxyScheme.value,
|
||||
host: proxyHost.value,
|
||||
port: proxyPort.value,
|
||||
username: proxyUser.value,
|
||||
};
|
||||
}
|
||||
|
||||
function applyRowSettings(row: UserRow) {
|
||||
monthlyTarget.value = row.monthly_target;
|
||||
startDay.value = row.study_start_day;
|
||||
startHour.value = row.study_start_hour;
|
||||
startMinute.value = row.study_start_minute;
|
||||
startSecond.value = row.study_start_second;
|
||||
scheduleEnabled.value = row.study_schedule_enabled !== false;
|
||||
scheduleChoice.value = row.study_schedule_enabled === false ? "off" : "on";
|
||||
workersValue.value = row.course_workers;
|
||||
}
|
||||
|
||||
async function openSettings(ids: string[]) {
|
||||
if (!ids.length) return;
|
||||
settingsIds.value = ids;
|
||||
settingsReady.value = false;
|
||||
resetSettingsForm();
|
||||
settingsOpen.value = true;
|
||||
if (ids.length !== 1) return;
|
||||
if (ids.length !== 1) {
|
||||
settingsBaseline = captureSettings();
|
||||
settingsReady.value = true;
|
||||
return;
|
||||
}
|
||||
const row = users.value.find((item) => item.employee_id === ids[0]);
|
||||
if (row) applyRowSettings(row);
|
||||
try {
|
||||
const response = await fetch(`/api/admin/users/${encodeURIComponent(ids[0])}/proxy`);
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok || !isRecord(payload)) return;
|
||||
proxyScheme.value = textOf(payload.scheme) || "off";
|
||||
proxyHost.value = textOf(payload.host);
|
||||
proxyPort.value = typeof payload.port === "number" ? payload.port : null;
|
||||
proxyUser.value = textOf(payload.username);
|
||||
proxyHasPassword.value = payload.has_password === true;
|
||||
} catch { /* 静默 */ }
|
||||
if (!response.ok || !isRecord(payload)) {
|
||||
proxyScheme.value = "keep";
|
||||
settingsError.value = "代理没有获取到,这次不会修改代理。";
|
||||
} else {
|
||||
proxyScheme.value = textOf(payload.scheme) || "off";
|
||||
proxyHost.value = textOf(payload.host);
|
||||
proxyPort.value = typeof payload.port === "number" ? payload.port : null;
|
||||
proxyUser.value = textOf(payload.username);
|
||||
proxyHasPassword.value = payload.has_password === true;
|
||||
}
|
||||
} catch {
|
||||
proxyScheme.value = "keep";
|
||||
settingsError.value = "代理没有获取到,这次不会修改代理。";
|
||||
}
|
||||
settingsBaseline = captureSettings();
|
||||
settingsReady.value = true;
|
||||
}
|
||||
|
||||
function proxyPasswordPayload() {
|
||||
if (proxyPassword.value !== "") return proxyPassword.value;
|
||||
if (!proxyUser.value.trim()) return "";
|
||||
if (settingsIds.value.length === 1 && proxyHasPassword.value) return null;
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
function scheduleValue() {
|
||||
if (scheduleChoice.value === "on") return true;
|
||||
if (scheduleChoice.value === "off") return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
function integerInRange(value: number | null, min: number, max: number) {
|
||||
return value != null && Number.isInteger(value) && value >= min && value <= max;
|
||||
}
|
||||
|
||||
function proxySummary(scheme: string, host: string, port: number | null) {
|
||||
if (scheme === "pool") return "自动";
|
||||
if (scheme === "off" || scheme === "keep" || !host || port == null) return "";
|
||||
return `${scheme.toUpperCase()} ${host}:${port}`;
|
||||
}
|
||||
|
||||
function applySavedRow(row: UserRow, sent: {
|
||||
monthlyTarget: number | null;
|
||||
scheduleEnabled: boolean | null;
|
||||
workers: number | null;
|
||||
day: number | null;
|
||||
hour: number | null;
|
||||
minute: number | null;
|
||||
second: number | null;
|
||||
scheme: string | null;
|
||||
host: string;
|
||||
port: number | null;
|
||||
}) {
|
||||
const next = { ...row };
|
||||
if (sent.monthlyTarget != null) next.monthly_target = sent.monthlyTarget;
|
||||
if (sent.scheduleEnabled != null) next.study_schedule_enabled = sent.scheduleEnabled;
|
||||
if (sent.workers != null) next.course_workers = sent.workers;
|
||||
if (sent.day != null && sent.hour != null && sent.minute != null && sent.second != null) {
|
||||
next.study_start_day = sent.day;
|
||||
next.study_start_hour = sent.hour;
|
||||
next.study_start_minute = sent.minute;
|
||||
next.study_start_second = sent.second;
|
||||
next.study_start = `每月${sent.day}日 ${pad(sent.hour)}:${pad(sent.minute)}:${pad(sent.second)}`;
|
||||
}
|
||||
if (sent.scheme) {
|
||||
next.has_proxy = sent.scheme !== "off";
|
||||
next.proxy = proxySummary(sent.scheme, sent.host, sent.port);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
if (settingsSaving.value || !settingsIds.value.length) return;
|
||||
if (settingsSaving.value || !settingsIds.value.length || !settingsReady.value || !settingsBaseline) return;
|
||||
settingsError.value = "";
|
||||
if (monthlyTarget.value == null || !Number.isInteger(monthlyTarget.value) || monthlyTarget.value < 0 || monthlyTarget.value > 9999) {
|
||||
settingsError.value = "每月学时目标须为 0 到 9999";
|
||||
const baseline = settingsBaseline;
|
||||
const targetChanged = monthlyTarget.value !== baseline.monthlyTarget;
|
||||
const scheduleTouched = startDay.value !== baseline.startDay
|
||||
|| startHour.value !== baseline.startHour
|
||||
|| startMinute.value !== baseline.startMinute
|
||||
|| startSecond.value !== baseline.startSecond;
|
||||
const scheduleChanged = scheduleChoice.value !== baseline.scheduleChoice && scheduleValue() !== null;
|
||||
const workersChanged = workersValue.value !== baseline.workers;
|
||||
const proxyTouched = proxyScheme.value !== baseline.scheme
|
||||
|| proxyHost.value.trim() !== baseline.host
|
||||
|| proxyPort.value !== baseline.port
|
||||
|| proxyUser.value.trim() !== baseline.username
|
||||
|| proxyPassword.value !== "";
|
||||
if (targetChanged && !integerInRange(monthlyTarget.value, 0, 9999)) {
|
||||
settingsError.value = "每月学时目标须为 0 到 9999 的整数";
|
||||
return;
|
||||
}
|
||||
if (
|
||||
startDay.value == null || startHour.value == null || startMinute.value == null || startSecond.value == null
|
||||
|| !Number.isInteger(startDay.value) || !Number.isInteger(startHour.value)
|
||||
|| !Number.isInteger(startMinute.value) || !Number.isInteger(startSecond.value)
|
||||
) {
|
||||
if (scheduleTouched && (
|
||||
!integerInRange(startDay.value, 1, 31)
|
||||
|| !integerInRange(startHour.value, 0, 23)
|
||||
|| !integerInRange(startMinute.value, 0, 59)
|
||||
|| !integerInRange(startSecond.value, 0, 59)
|
||||
)) {
|
||||
settingsError.value = "请填写完整的开始时刻";
|
||||
return;
|
||||
}
|
||||
if (workersValue.value == null || !Number.isInteger(workersValue.value) || workersValue.value < 1 || workersValue.value > 8) {
|
||||
if (workersChanged && !integerInRange(workersValue.value, 1, 8)) {
|
||||
settingsError.value = "同时学习课程数须为 1 到 8";
|
||||
return;
|
||||
}
|
||||
if (proxyManual.value) {
|
||||
if (proxyTouched && proxyScheme.value !== "keep" && proxyManual.value) {
|
||||
if (!proxyHost.value.trim()) {
|
||||
settingsError.value = "请填写代理地址";
|
||||
return;
|
||||
}
|
||||
if (proxyPort.value == null || !Number.isInteger(proxyPort.value)) {
|
||||
if (!integerInRange(proxyPort.value, 1, 65535)) {
|
||||
settingsError.value = "请填写代理端口";
|
||||
return;
|
||||
}
|
||||
}
|
||||
const sentTarget = targetChanged ? monthlyTarget.value : null;
|
||||
const sentSchedule = scheduleChanged ? scheduleValue() : null;
|
||||
const sentWorkers = workersChanged ? workersValue.value : null;
|
||||
const sentDay = scheduleTouched ? startDay.value : null;
|
||||
const sentHour = scheduleTouched ? startHour.value : null;
|
||||
const sentMinute = scheduleTouched ? startMinute.value : null;
|
||||
const sentSecond = scheduleTouched ? startSecond.value : null;
|
||||
const sentScheme = proxyTouched && proxyScheme.value !== "keep" ? proxyScheme.value : null;
|
||||
if (sentTarget == null && sentSchedule == null && sentWorkers == null && sentDay == null && sentScheme == null) {
|
||||
settingsOpen.value = false;
|
||||
return;
|
||||
}
|
||||
settingsSaving.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/admin/users/study-settings", {
|
||||
@@ -478,18 +647,18 @@ async function saveSettings() {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
employee_ids: settingsIds.value,
|
||||
monthly_target: monthlyTarget.value,
|
||||
day: startDay.value,
|
||||
hour: startHour.value,
|
||||
minute: startMinute.value,
|
||||
second: startSecond.value,
|
||||
schedule_enabled: scheduleEnabled.value,
|
||||
workers: workersValue.value,
|
||||
scheme: proxyScheme.value,
|
||||
host: proxyHost.value.trim(),
|
||||
port: proxyPort.value,
|
||||
username: proxyUser.value.trim(),
|
||||
password: proxyManual.value ? proxyPasswordPayload() : "",
|
||||
monthly_target: sentTarget,
|
||||
day: sentDay,
|
||||
hour: sentHour,
|
||||
minute: sentMinute,
|
||||
second: sentSecond,
|
||||
schedule_enabled: sentSchedule,
|
||||
workers: sentWorkers,
|
||||
scheme: sentScheme,
|
||||
host: sentScheme && proxyManual.value ? proxyHost.value.trim() : "",
|
||||
port: sentScheme && proxyManual.value ? proxyPort.value : null,
|
||||
username: sentScheme && proxyManual.value ? proxyUser.value.trim() : "",
|
||||
password: sentScheme ? (proxyManual.value ? proxyPasswordPayload() : "") : null,
|
||||
}),
|
||||
});
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
@@ -497,8 +666,21 @@ async function saveSettings() {
|
||||
settingsError.value = detailOf(payload, "没有保存。");
|
||||
return;
|
||||
}
|
||||
const sent = {
|
||||
monthlyTarget: sentTarget,
|
||||
scheduleEnabled: sentSchedule,
|
||||
workers: sentWorkers,
|
||||
day: sentDay,
|
||||
hour: sentHour,
|
||||
minute: sentMinute,
|
||||
second: sentSecond,
|
||||
scheme: sentScheme,
|
||||
host: proxyHost.value.trim(),
|
||||
port: proxyPort.value,
|
||||
};
|
||||
const ids = new Set(settingsIds.value);
|
||||
users.value = users.value.map((row) => (ids.has(row.employee_id) ? applySavedRow(row, sent) : row));
|
||||
settingsOpen.value = false;
|
||||
await load();
|
||||
} catch {
|
||||
settingsError.value = "没有保存。";
|
||||
} finally {
|
||||
@@ -569,7 +751,7 @@ function rowActions(row: UserRow): DropdownOption[] {
|
||||
const busy = checkingAll.value || checkingId.value !== "" || studyBusy.value;
|
||||
return [
|
||||
{ label: "学习设置", key: "settings" },
|
||||
{ label: row.study_started ? "停止任务" : "立即开始", key: "study", disabled: busy },
|
||||
{ label: taskCanStop(row) ? "停止任务" : "立即开始", key: "study", disabled: busy },
|
||||
{ label: "检查", key: "check", disabled: busy },
|
||||
{ label: "查看凭据", key: "credentials" },
|
||||
{ label: row.refresh_paused ? "恢复自动刷新" : "停止自动刷新", key: "refresh" },
|
||||
@@ -579,7 +761,7 @@ function rowActions(row: UserRow): DropdownOption[] {
|
||||
|
||||
function onRowAction(row: UserRow, key: string | number) {
|
||||
if (key === "settings") void openSettings([row.employee_id]);
|
||||
else if (key === "study") void setStudy([row.employee_id], row.study_started ? "stop" : "start");
|
||||
else if (key === "study") void setStudy([row.employee_id], taskCanStop(row) ? "stop" : "start");
|
||||
else if (key === "check") void checkOne(row);
|
||||
else if (key === "credentials") void openCredentials(row);
|
||||
else if (key === "refresh") confirmRefresh(row);
|
||||
@@ -638,10 +820,10 @@ onMounted(() => {
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="pick">
|
||||
<n-checkbox :checked="allPicked" :indeterminate="somePicked" @update:checked="toggleAll" />
|
||||
<n-checkbox aria-label="选择全部账号" :checked="allPicked" :indeterminate="somePicked" @update:checked="toggleAll" />
|
||||
</th>
|
||||
<th>工号</th>
|
||||
<th>凭证</th>
|
||||
<th>凭据</th>
|
||||
<th>有效</th>
|
||||
<th>本月学时</th>
|
||||
<th>任务</th>
|
||||
@@ -654,13 +836,13 @@ onMounted(() => {
|
||||
<tbody>
|
||||
<tr v-for="row in users" :key="row.employee_id">
|
||||
<td class="pick">
|
||||
<n-checkbox :checked="Boolean(picked[row.employee_id])" @update:checked="(checked) => (picked = { ...picked, [row.employee_id]: checked })" />
|
||||
<n-checkbox aria-label="选择该账号" :checked="Boolean(picked[row.employee_id])" @update:checked="(checked: boolean) => (picked = { ...picked, [row.employee_id]: checked })" />
|
||||
</td>
|
||||
<td class="employee">{{ row.employee_id }}</td>
|
||||
<td>{{ row.has_credential ? "已保存凭证" : "未保存凭证" }}</td>
|
||||
<td>{{ row.has_credential ? "已保存凭据" : "未保存凭据" }}</td>
|
||||
<td :class="validityClass(validityText(row))">{{ validityText(row) }}</td>
|
||||
<td class="when">{{ row.month_hours || "—" }}</td>
|
||||
<td :class="row.study_started ? 'ok' : 'quiet'">{{ taskText(row) }}</td>
|
||||
<td class="when">{{ monthHoursText(row) }}</td>
|
||||
<td :class="taskText(row) === '运行中' ? 'ok' : 'quiet'">{{ taskText(row) }}</td>
|
||||
<td class="when">{{ row.proxy || "—" }}</td>
|
||||
<td class="when">{{ formatRefreshTime(row.last_refresh_at) }}</td>
|
||||
<td>{{ row.refresh_paused ? "已停止" : "开启" }}</td>
|
||||
@@ -700,7 +882,7 @@ onMounted(() => {
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
<n-button @click="credentialOpen = false">关闭</n-button>
|
||||
<n-button @click="closeCredentials">关闭</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
@@ -713,43 +895,36 @@ onMounted(() => {
|
||||
@update:show="(show) => (settingsOpen = show)"
|
||||
>
|
||||
<n-alert v-if="settingsError" class="admin-alert" type="error">{{ settingsError }}</n-alert>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="96" :show-feedback="false" size="small" @submit.prevent="saveSettings">
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="132" :show-feedback="false" size="small" @submit.prevent="saveSettings">
|
||||
<n-form-item label="每月目标">
|
||||
<div class="target-control">
|
||||
<n-input-number id="admin-monthly-target" v-model:value="monthlyTarget" button-placement="both" :min="0" :max="9999" :precision="0" />
|
||||
<n-input-number v-model:value="monthlyTarget" button-placement="both" :min="0" :max="9999" :precision="0" placeholder="保持不变" />
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item label="定时开启">
|
||||
<n-switch v-model:value="scheduleEnabled" size="small" />
|
||||
</n-form-item>
|
||||
<n-form-item label="定时启动">
|
||||
<n-radio-group v-model:value="scheduleChoice" class="schedule-choice" size="small">
|
||||
<n-radio-button value="keep">保持不变</n-radio-button>
|
||||
<n-radio-button value="on">开启</n-radio-button>
|
||||
<n-radio-button value="off">关闭</n-radio-button>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
<n-form-item label="开始时刻">
|
||||
<div class="target-control start-control">
|
||||
<n-select id="admin-start-day" v-model:value="startDay" :options="dayOptions" class="day-select" :disabled="!scheduleEnabled" />
|
||||
<n-tooltip v-if="scheduleEnabled && startDay === 1" placement="top">
|
||||
<n-select v-model:value="startDay" :options="dayOptions" class="day-select" placeholder="保持不变" :disabled="scheduleTimeDisabled" />
|
||||
<n-tooltip v-if="!scheduleTimeDisabled && startDay === 1" placement="top">
|
||||
<template #trigger>
|
||||
<n-icon class="day-warn"><WarningOutline /></n-icon>
|
||||
<button type="button" class="hint-icon day-warn" aria-label="开始时刻说明">
|
||||
<n-icon><WarningOutline /></n-icon>
|
||||
</button>
|
||||
</template>
|
||||
不推荐使用
|
||||
公共代理不稳定,学习可能中断
|
||||
</n-tooltip>
|
||||
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" :actions="null" :disabled="!scheduleEnabled" />
|
||||
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" :actions="null" placeholder="保持不变" :disabled="scheduleTimeDisabled" />
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<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="admin-course-workers" class="worker-select" v-model:value="workersValue" :options="workerOptions" />
|
||||
<n-form-item label="同时学习课程数">
|
||||
<n-select class="worker-select" v-model:value="workersValue" :options="workerOptions" placeholder="保持不变" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理类型">
|
||||
<n-select v-model:value="proxyScheme" :options="proxyOptions" />
|
||||
@@ -762,7 +937,7 @@ onMounted(() => {
|
||||
<n-input-number v-model:value="proxyPort" button-placement="both" :min="1" :max="65535" :precision="0" placeholder="请输入" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理账号">
|
||||
<n-input v-model:value="proxyUser" placeholder="可不填" autocomplete="off" />
|
||||
<n-input v-model:value="proxyUser" placeholder="可不填" :input-props="proxyAccountProps" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理密码">
|
||||
<n-input
|
||||
@@ -770,17 +945,15 @@ onMounted(() => {
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="settingsIds.length === 1 && proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
autocomplete="new-password"
|
||||
:input-props="proxyPasswordProps"
|
||||
/>
|
||||
</n-form-item>
|
||||
</template>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
<n-button @click="settingsOpen = false">取消</n-button>
|
||||
<n-button type="primary" :loading="settingsSaving" @click="saveSettings">保存</n-button>
|
||||
<n-button attr-type="button" @click="settingsOpen = false">取消</n-button>
|
||||
<n-button attr-type="submit" type="primary" :loading="settingsSaving" :disabled="!settingsReady">保存</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-form>
|
||||
</n-modal>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { computed, onUnmounted, ref, watch } from "vue";
|
||||
import { NAlert, NButton, NCheckbox, NIcon, NInput, NTooltip } from "naive-ui";
|
||||
import { ChevronForward, MoonOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { isDark, toggleTheme } from "../../shared/theme";
|
||||
@@ -22,6 +22,7 @@ interface LoginPayload {
|
||||
attempt_id?: string;
|
||||
jigsaw?: JigsawPuzzle;
|
||||
qr_image?: string;
|
||||
ttl?: number;
|
||||
status?: string;
|
||||
detail?: unknown;
|
||||
}
|
||||
@@ -39,11 +40,17 @@ const attemptId = ref("");
|
||||
const jigsaw = ref<JigsawPuzzle | null>(null);
|
||||
const qrImage = ref("");
|
||||
const qrExpired = ref(false);
|
||||
const qrLeft = ref(0);
|
||||
const qrArmed = ref(false);
|
||||
const offset = ref(0);
|
||||
const dragging = ref(false);
|
||||
const stageEl = ref<HTMLElement | null>(null);
|
||||
const trackEl = ref<HTMLElement | null>(null);
|
||||
const stageWidth = ref(0);
|
||||
let startX = 0;
|
||||
let startOffset = 0;
|
||||
let pollTimer = 0;
|
||||
let qrTimer = 0;
|
||||
let polling = false;
|
||||
|
||||
const maxOffset = computed(() => {
|
||||
@@ -52,7 +59,40 @@ const maxOffset = computed(() => {
|
||||
return Math.max(puzzle.width - puzzle.piece_width, 0);
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
const scale = computed(() => {
|
||||
const puzzle = jigsaw.value;
|
||||
if (!puzzle || puzzle.width <= 0) return 1;
|
||||
const available = stageWidth.value > 0 ? stageWidth.value : Math.max(window.innerWidth - 80, 160);
|
||||
return Math.min(1, available / puzzle.width);
|
||||
});
|
||||
|
||||
const frameWidth = computed(() => (jigsaw.value ? Math.round(jigsaw.value.width * scale.value) : 0));
|
||||
const frameHeight = computed(() => (jigsaw.value ? Math.round(jigsaw.value.height * scale.value) : 0));
|
||||
const trackHeight = computed(() => Math.max(32, Math.round(36 * scale.value)));
|
||||
|
||||
const employeeInputProps = { id: "employee-id", autocomplete: "username", name: "username" };
|
||||
const passwordInputProps = { id: "password", autocomplete: "current-password", name: "current-password" };
|
||||
|
||||
watch(stageEl, (el, _previous, onCleanup) => {
|
||||
if (!el) return;
|
||||
const measure = () => {
|
||||
const width = el.clientWidth;
|
||||
if (width > 0) stageWidth.value = width;
|
||||
};
|
||||
measure();
|
||||
const observer = new ResizeObserver(measure);
|
||||
observer.observe(el);
|
||||
onCleanup(() => observer.disconnect());
|
||||
}, { flush: "post" });
|
||||
|
||||
void loadConfig();
|
||||
|
||||
onUnmounted(() => {
|
||||
stopPoll();
|
||||
stopQrTimer();
|
||||
});
|
||||
|
||||
async function loadConfig() {
|
||||
try {
|
||||
const response = await fetch("/api/login-config");
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
@@ -60,7 +100,7 @@ onMounted(async () => {
|
||||
showManual.value = Boolean((payload as { show_manual_checkbox?: unknown }).show_manual_checkbox);
|
||||
manualJigsaw.value = showManual.value && Boolean((payload as { manual_checkbox_checked?: unknown }).manual_checkbox_checked);
|
||||
} else if (payload && typeof payload === "object" && typeof (payload as { detail?: unknown }).detail === "string") {
|
||||
errorText.value = (payload as { detail: string }).detail;
|
||||
errorText.value = readableDetail((payload as { detail: string }).detail, "登录配置没有获取到。");
|
||||
}
|
||||
} catch {
|
||||
showManual.value = false;
|
||||
@@ -68,9 +108,13 @@ onMounted(async () => {
|
||||
} finally {
|
||||
configReady.value = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onUnmounted(() => stopPoll());
|
||||
function readableDetail(detail: unknown, fallback: string) {
|
||||
if (typeof detail !== "string" || !detail.trim()) return fallback;
|
||||
if (/traceback|exception|sqlite|httpx|errno|timeout|error:/i.test(detail)) return fallback;
|
||||
return detail;
|
||||
}
|
||||
|
||||
function stopPoll() {
|
||||
if (pollTimer) {
|
||||
@@ -79,6 +123,29 @@ function stopPoll() {
|
||||
}
|
||||
}
|
||||
|
||||
function stopQrTimer() {
|
||||
if (qrTimer) {
|
||||
window.clearInterval(qrTimer);
|
||||
qrTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function startQrTimer(ttl: number) {
|
||||
stopQrTimer();
|
||||
qrLeft.value = Math.max(1, Math.round(ttl));
|
||||
qrExpired.value = false;
|
||||
qrArmed.value = false;
|
||||
qrTimer = window.setInterval(() => {
|
||||
if (qrLeft.value <= 1) {
|
||||
stopQrTimer();
|
||||
qrLeft.value = 0;
|
||||
void startQr();
|
||||
return;
|
||||
}
|
||||
qrLeft.value -= 1;
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function applyResult(payload: LoginPayload) {
|
||||
if (payload.jigsaw && payload.attempt_id) {
|
||||
attemptId.value = payload.attempt_id;
|
||||
@@ -96,6 +163,7 @@ function applyResult(payload: LoginPayload) {
|
||||
jigsaw.value = null;
|
||||
qrImage.value = "";
|
||||
stopPoll();
|
||||
stopQrTimer();
|
||||
emit("success", next);
|
||||
}
|
||||
|
||||
@@ -110,26 +178,34 @@ async function setMode(next: "password" | "qr") {
|
||||
return;
|
||||
}
|
||||
stopPoll();
|
||||
stopQrTimer();
|
||||
qrImage.value = "";
|
||||
qrExpired.value = false;
|
||||
qrLeft.value = 0;
|
||||
qrArmed.value = false;
|
||||
}
|
||||
|
||||
async function startQr() {
|
||||
stopPoll();
|
||||
stopQrTimer();
|
||||
errorText.value = "";
|
||||
qrExpired.value = false;
|
||||
qrArmed.value = false;
|
||||
submitting.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/login/qr", { method: "POST" });
|
||||
const payload = await response.json().catch(() => ({})) as LoginPayload;
|
||||
if (!response.ok) {
|
||||
errorText.value = typeof payload.detail === "string" ? payload.detail : "二维码没有获取到";
|
||||
errorText.value = readableDetail(payload.detail, "二维码没有获取到");
|
||||
qrImage.value = "";
|
||||
qrExpired.value = true;
|
||||
qrLeft.value = 0;
|
||||
return;
|
||||
}
|
||||
attemptId.value = payload.attempt_id || "";
|
||||
qrImage.value = payload.qr_image || "";
|
||||
const ttl = typeof payload.ttl === "number" && payload.ttl > 0 ? payload.ttl : 60;
|
||||
if (attemptId.value && qrImage.value) startQrTimer(ttl);
|
||||
if (attemptId.value) {
|
||||
pollTimer = window.setInterval(() => {
|
||||
void pollQr();
|
||||
@@ -139,6 +215,7 @@ async function startQr() {
|
||||
errorText.value = "二维码没有获取到";
|
||||
qrImage.value = "";
|
||||
qrExpired.value = true;
|
||||
qrLeft.value = 0;
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
@@ -155,22 +232,32 @@ async function pollQr() {
|
||||
});
|
||||
const payload = await response.json().catch(() => ({})) as LoginPayload;
|
||||
if (!response.ok) {
|
||||
if (response.status >= 500) {
|
||||
errorText.value = "网络异常,继续等待。";
|
||||
return;
|
||||
}
|
||||
stopPoll();
|
||||
stopQrTimer();
|
||||
qrExpired.value = true;
|
||||
errorText.value = typeof payload.detail === "string" ? payload.detail : "请重新扫码";
|
||||
qrLeft.value = 0;
|
||||
errorText.value = "请重新扫码";
|
||||
return;
|
||||
}
|
||||
if (payload.status === "waiting") {
|
||||
if (errorText.value === "网络异常,继续等待。") errorText.value = "";
|
||||
return;
|
||||
}
|
||||
if (payload.status === "waiting") return;
|
||||
if (payload.status === "expired") {
|
||||
stopPoll();
|
||||
stopQrTimer();
|
||||
qrExpired.value = true;
|
||||
qrLeft.value = 0;
|
||||
errorText.value = "";
|
||||
return;
|
||||
}
|
||||
applyResult(payload);
|
||||
} catch {
|
||||
stopPoll();
|
||||
qrExpired.value = true;
|
||||
errorText.value = "网络异常,继续等待。";
|
||||
} finally {
|
||||
polling = false;
|
||||
}
|
||||
@@ -178,6 +265,13 @@ async function pollQr() {
|
||||
|
||||
async function refreshQr() {
|
||||
if (submitting.value) return;
|
||||
if (qrLeft.value > 0 && !qrExpired.value) {
|
||||
if (!qrArmed.value) {
|
||||
qrArmed.value = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
qrArmed.value = false;
|
||||
await startQr();
|
||||
}
|
||||
|
||||
@@ -196,15 +290,24 @@ async function submit() {
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
errorText.value = typeof payload.detail === "string" ? payload.detail : "登录失败";
|
||||
errorText.value = readableDetail(payload.detail, "登录失败");
|
||||
return;
|
||||
}
|
||||
applyResult(payload);
|
||||
} catch {
|
||||
errorText.value = "网络异常,登录没有完成。";
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function cancelJigsaw() {
|
||||
jigsaw.value = null;
|
||||
attemptId.value = "";
|
||||
offset.value = 0;
|
||||
errorText.value = "";
|
||||
}
|
||||
|
||||
async function sendOffset() {
|
||||
if (!attemptId.value || submitting.value) return;
|
||||
submitting.value = true;
|
||||
@@ -215,19 +318,37 @@ async function sendOffset() {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ attempt_id: attemptId.value, offset: offset.value }),
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
const payload = await response.json().catch(() => ({})) as LoginPayload;
|
||||
if (!response.ok) {
|
||||
const detail = typeof payload.detail === "string" ? payload.detail : "";
|
||||
if (/验证码|拼图|滑块|没对/.test(detail)) {
|
||||
errorText.value = "没对准,请再试一次";
|
||||
offset.value = 0;
|
||||
return;
|
||||
}
|
||||
jigsaw.value = null;
|
||||
attemptId.value = "";
|
||||
errorText.value = typeof payload.detail === "string" ? payload.detail : "登录失败";
|
||||
errorText.value = readableDetail(detail, "登录失败");
|
||||
return;
|
||||
}
|
||||
if (payload.jigsaw && payload.attempt_id) {
|
||||
errorText.value = "没对准,请再试一次";
|
||||
offset.value = 0;
|
||||
attemptId.value = payload.attempt_id;
|
||||
return;
|
||||
}
|
||||
applyResult(payload);
|
||||
} catch {
|
||||
errorText.value = "网络异常,登录没有完成。";
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function clampOffset(value: number) {
|
||||
return Math.min(Math.max(Math.round(value), 0), maxOffset.value);
|
||||
}
|
||||
|
||||
function onPointerDown(event: PointerEvent) {
|
||||
if (!jigsaw.value || submitting.value) return;
|
||||
dragging.value = true;
|
||||
@@ -238,15 +359,37 @@ function onPointerDown(event: PointerEvent) {
|
||||
|
||||
function onPointerMove(event: PointerEvent) {
|
||||
if (!dragging.value) return;
|
||||
const next = startOffset + (event.clientX - startX);
|
||||
offset.value = Math.min(Math.max(Math.round(next), 0), maxOffset.value);
|
||||
const ratio = scale.value || 1;
|
||||
const next = startOffset + (event.clientX - startX) / ratio;
|
||||
offset.value = clampOffset(next);
|
||||
}
|
||||
|
||||
function onPointerUp() {
|
||||
function releasedOnTrack(event: PointerEvent) {
|
||||
const track = trackEl.value;
|
||||
if (!track) return true;
|
||||
const rect = track.getBoundingClientRect();
|
||||
return event.clientX >= rect.left && event.clientX <= rect.right && event.clientY >= rect.top && event.clientY <= rect.bottom;
|
||||
}
|
||||
|
||||
function onPointerUp(event: PointerEvent) {
|
||||
if (!dragging.value) return;
|
||||
dragging.value = false;
|
||||
if (!releasedOnTrack(event)) return;
|
||||
if (offset.value > 0) void sendOffset();
|
||||
}
|
||||
|
||||
function onPointerCancel() {
|
||||
dragging.value = false;
|
||||
}
|
||||
|
||||
function onSliderKey(event: KeyboardEvent) {
|
||||
if (!jigsaw.value || submitting.value) return;
|
||||
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
|
||||
event.preventDefault();
|
||||
const ratio = scale.value || 1;
|
||||
const step = 4 / ratio;
|
||||
offset.value = clampOffset(offset.value + (event.key === "ArrowLeft" ? -step : step));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -267,26 +410,31 @@ function onPointerUp() {
|
||||
</div>
|
||||
</div>
|
||||
<div class="gate-tabs" role="tablist">
|
||||
<button type="button" role="tab" :class="{ active: mode === 'password' }" :disabled="!!jigsaw || submitting" @click="setMode('password')">密码登录</button>
|
||||
<button type="button" role="tab" :class="{ active: mode === 'qr' }" :disabled="!!jigsaw || submitting" @click="setMode('qr')">扫码登录</button>
|
||||
<button type="button" role="tab" :aria-selected="mode === 'password'" :class="{ active: mode === 'password' }" :disabled="!!jigsaw || submitting" @click="setMode('password')">密码登录</button>
|
||||
<button type="button" role="tab" :aria-selected="mode === 'qr'" :class="{ active: mode === 'qr' }" :disabled="!!jigsaw || submitting" @click="setMode('qr')">扫码登录</button>
|
||||
</div>
|
||||
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
|
||||
<div v-if="mode === 'qr'" class="qr-block">
|
||||
<p>请使用 iCenter 扫码登录</p>
|
||||
<button class="qr-frame" type="button" :disabled="submitting" aria-label="刷新二维码" @click="refreshQr">
|
||||
<div class="qr-frame" role="img" aria-label="登录二维码">
|
||||
<img v-if="qrImage" :src="qrImage" alt="" width="210" height="210" />
|
||||
<span v-if="qrExpired" class="qr-mask">点击刷新</span>
|
||||
<button v-if="qrExpired" class="qr-mask" type="button" :disabled="submitting" @click="startQr">点击刷新</button>
|
||||
<span v-else-if="!qrImage" class="qr-mask">正在获取</span>
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="qrLeft > 0 && !qrExpired" class="qr-ttl">{{ qrLeft }} 秒后刷新</p>
|
||||
<div v-if="qrImage && !qrExpired" class="gate-actions qr-refresh">
|
||||
<n-button :disabled="submitting" @click="refreshQr">刷新二维码</n-button>
|
||||
</div>
|
||||
<p v-if="qrArmed && qrLeft > 0" class="qr-ttl">再点一次更换</p>
|
||||
</div>
|
||||
<form v-else @submit.prevent="submit">
|
||||
<div class="form-row">
|
||||
<label for="employee-id">工号</label>
|
||||
<n-input id="employee-id" v-model:value="employeeId" placeholder="工号" autocomplete="username" :disabled="!!jigsaw || submitting" />
|
||||
<n-input v-model:value="employeeId" placeholder="工号" :input-props="employeeInputProps" :disabled="!!jigsaw || submitting" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="password">密码</label>
|
||||
<n-input id="password" v-model:value="password" type="password" show-password-on="click" placeholder="密码" autocomplete="current-password" :disabled="!!jigsaw || submitting" />
|
||||
<n-input v-model:value="password" type="password" show-password-on="click" placeholder="密码" :input-props="passwordInputProps" :disabled="!!jigsaw || submitting" />
|
||||
</div>
|
||||
<div v-if="showManual" class="form-row">
|
||||
<span></span>
|
||||
@@ -294,32 +442,42 @@ function onPointerUp() {
|
||||
</div>
|
||||
<div v-if="jigsaw" class="jigsaw-block">
|
||||
<p>拖动滑块完成拼图</p>
|
||||
<div class="jigsaw" :style="{ width: jigsaw.width + 'px', height: jigsaw.height + 'px' }">
|
||||
<img class="board" :src="jigsaw.big_img" alt="" :width="jigsaw.width" :height="jigsaw.height" draggable="false" />
|
||||
<img
|
||||
class="piece"
|
||||
:src="jigsaw.small_img"
|
||||
alt=""
|
||||
:width="jigsaw.piece_width"
|
||||
:height="jigsaw.piece_height"
|
||||
:style="{ top: jigsaw.y + 'px', left: offset + 'px' }"
|
||||
draggable="false"
|
||||
/>
|
||||
<div ref="stageEl" class="jigsaw-stage">
|
||||
<div class="jigsaw-frame" :style="{ width: frameWidth + 'px', height: frameHeight + 'px' }">
|
||||
<div class="jigsaw" :style="{ width: jigsaw.width + 'px', height: jigsaw.height + 'px', transform: `scale(${scale})` }">
|
||||
<img class="jigsaw-board" :src="jigsaw.big_img" alt="" :width="jigsaw.width" :height="jigsaw.height" draggable="false" />
|
||||
<img
|
||||
class="piece"
|
||||
:src="jigsaw.small_img"
|
||||
alt=""
|
||||
:width="jigsaw.piece_width"
|
||||
:height="jigsaw.piece_height"
|
||||
:style="{ top: jigsaw.y + 'px', left: offset + 'px' }"
|
||||
draggable="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div ref="trackEl" class="jigsaw-frame" :style="{ width: frameWidth + 'px', height: trackHeight + 'px' }">
|
||||
<div class="jigsaw-track" :style="{ width: jigsaw.width + 'px', transform: `scale(${scale})` }">
|
||||
<button
|
||||
type="button"
|
||||
class="jigsaw-handle"
|
||||
:style="{ left: offset + 'px' }"
|
||||
aria-label="拼图滑块"
|
||||
:disabled="submitting"
|
||||
@pointerdown="onPointerDown"
|
||||
@pointermove="onPointerMove"
|
||||
@pointerup="onPointerUp"
|
||||
@pointercancel="onPointerCancel"
|
||||
@keydown="onSliderKey"
|
||||
>
|
||||
<n-icon><ChevronForward /></n-icon>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jigsaw-track" :style="{ width: jigsaw.width + 'px' }">
|
||||
<button
|
||||
type="button"
|
||||
class="jigsaw-handle"
|
||||
:style="{ left: offset + 'px' }"
|
||||
aria-label="拼图滑块"
|
||||
:disabled="submitting"
|
||||
@pointerdown="onPointerDown"
|
||||
@pointermove="onPointerMove"
|
||||
@pointerup="onPointerUp"
|
||||
@pointercancel="onPointerUp"
|
||||
>
|
||||
<n-icon><ChevronForward /></n-icon>
|
||||
</button>
|
||||
<div class="gate-actions">
|
||||
<n-button :disabled="submitting" @click="cancelJigsaw">取消</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="gate-actions">
|
||||
|
||||
@@ -46,7 +46,10 @@ let refreshRunning = false;
|
||||
let busy = false;
|
||||
|
||||
function failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
return typeof payload.detail === "string" ? payload.detail : fallback;
|
||||
const detail = payload.detail;
|
||||
if (typeof detail !== "string" || !detail.trim()) return fallback;
|
||||
if (/traceback|exception|sqlite|httpx|errno|timeout|error:/i.test(detail)) return fallback;
|
||||
return detail;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
@@ -58,20 +61,21 @@ async function load() {
|
||||
const response = await fetch("/api/home/exams");
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
if (!hadData) {
|
||||
errorText.value = failureText(payload, "考试列表没有获取到。");
|
||||
state.value = "error";
|
||||
}
|
||||
errorText.value = "考试列表没有获取到。";
|
||||
if (!hadData) state.value = "error";
|
||||
return;
|
||||
}
|
||||
items.value = Array.isArray(payload.exams) ? payload.exams : [];
|
||||
if (!payload || typeof payload !== "object" || !Array.isArray((payload as { exams?: unknown }).exams)) {
|
||||
errorText.value = "数据异常";
|
||||
if (!hadData) state.value = "error";
|
||||
return;
|
||||
}
|
||||
items.value = (payload as { exams: ExamItem[] }).exams;
|
||||
errorText.value = "";
|
||||
state.value = "ready";
|
||||
} catch {
|
||||
if (!hadData) {
|
||||
errorText.value = "考试列表没有获取到。";
|
||||
state.value = "error";
|
||||
}
|
||||
errorText.value = "考试列表没有获取到。";
|
||||
if (!hadData) state.value = "error";
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
@@ -143,10 +147,10 @@ onMounted(refresh);
|
||||
</span>
|
||||
</header>
|
||||
<section class="board" aria-labelledby="exam-heading" :aria-busy="state === 'loading'">
|
||||
<div class="rail" tabindex="0">
|
||||
<n-alert v-if="state === 'error'" class="section-error" type="error">{{ errorText }}</n-alert>
|
||||
<p v-else-if="items && !items.length" class="rail-empty">没有考试</p>
|
||||
<ol v-else-if="items">
|
||||
<div class="rail" tabindex="0" aria-label="我的考试">
|
||||
<n-alert v-if="errorText" class="section-error" type="error">{{ errorText }}</n-alert>
|
||||
<p v-if="items && !items.length && !errorText" class="rail-empty">没有考试</p>
|
||||
<ol v-else-if="items && items.length">
|
||||
<li v-for="item in items" :key="`${item.start}-${item.name}`" class="event">
|
||||
<span class="mark" aria-hidden="true"></span>
|
||||
<button type="button" class="event-hit" @click="openDetail(item)">
|
||||
|
||||
@@ -30,10 +30,6 @@ const pageSizes = [10, 20, 50];
|
||||
let refreshRunning = false;
|
||||
let busy = false;
|
||||
|
||||
function failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
return typeof payload.detail === "string" ? payload.detail : fallback;
|
||||
}
|
||||
|
||||
function asItem(value: unknown): HistoryItem | null {
|
||||
if (!value || typeof value !== "object") return null;
|
||||
const row = value as Record<string, unknown>;
|
||||
@@ -62,6 +58,11 @@ function amount(value: string | number | null | undefined) {
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function withMinutes(value: string) {
|
||||
if (!value || value === "—") return "—";
|
||||
return `${value} 分钟`;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
@@ -71,13 +72,16 @@ async function load() {
|
||||
const response = await fetch("/api/home/history");
|
||||
const payload = await response.json().catch(() => ({})) as Record<string, unknown>;
|
||||
if (!response.ok) {
|
||||
if (!hadData) {
|
||||
errorText.value = failureText(payload, "学时历史没有获取到。");
|
||||
state.value = "error";
|
||||
}
|
||||
errorText.value = "学时历史没有获取到。";
|
||||
if (!hadData) state.value = "error";
|
||||
return;
|
||||
}
|
||||
const rows: unknown[] = Array.isArray(payload.items) ? payload.items : [];
|
||||
if (!payload || typeof payload !== "object" || !Array.isArray(payload.items)) {
|
||||
errorText.value = "数据异常";
|
||||
if (!hadData) state.value = "error";
|
||||
return;
|
||||
}
|
||||
const rows: unknown[] = payload.items;
|
||||
const parsed: HistoryItem[] = [];
|
||||
for (const row of rows) {
|
||||
const item = asItem(row);
|
||||
@@ -95,10 +99,8 @@ async function load() {
|
||||
const maxPage = Math.max(1, Math.ceil(parsed.length / pageSize.value));
|
||||
if (page.value > maxPage) page.value = maxPage;
|
||||
} catch {
|
||||
if (!hadData) {
|
||||
errorText.value = "学时历史没有获取到。";
|
||||
state.value = "error";
|
||||
}
|
||||
errorText.value = "学时历史没有获取到。";
|
||||
if (!hadData) state.value = "error";
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
@@ -117,10 +119,10 @@ function refresh() {
|
||||
const historyFacts = computed(() => {
|
||||
const current = hours.value;
|
||||
return [
|
||||
{ label: "总学时", value: current ? amount(current.total_hours) : "" },
|
||||
{ label: "本年学时", value: current ? amount(current.year_hours) : "" },
|
||||
{ label: "本月学时", value: current ? amount(current.month_hours) : "" },
|
||||
{ label: "本日学时", value: current ? amount(current.today_hours) : "" },
|
||||
{ label: "总学时", value: current ? withMinutes(amount(current.total_hours)) : "" },
|
||||
{ label: "本年学时", value: current ? withMinutes(amount(current.year_hours)) : "" },
|
||||
{ label: "本月学时", value: current ? withMinutes(amount(current.month_hours)) : "" },
|
||||
{ label: "本日学时", value: current ? withMinutes(amount(current.today_hours)) : "" },
|
||||
];
|
||||
});
|
||||
|
||||
@@ -194,7 +196,7 @@ onMounted(refresh);
|
||||
刷新
|
||||
</n-tooltip>
|
||||
</header>
|
||||
<n-alert v-if="state === 'error'" class="admin-alert" type="error">{{ errorText }}</n-alert>
|
||||
<n-alert v-if="errorText" class="admin-alert" type="error">{{ errorText }}</n-alert>
|
||||
<dl class="facts history-facts">
|
||||
<div v-for="item in historyFacts" :key="item.label">
|
||||
<dt>{{ item.label }}</dt>
|
||||
@@ -206,16 +208,17 @@ onMounted(refresh);
|
||||
</dl>
|
||||
<div class="history-table">
|
||||
<n-data-table
|
||||
v-if="state !== 'error'"
|
||||
v-if="items && items.length"
|
||||
:columns="columns"
|
||||
:data="state === 'loading' ? [] : paged"
|
||||
:loading="state === 'loading' || refreshing"
|
||||
:data="paged"
|
||||
:loading="refreshing"
|
||||
:bordered="false"
|
||||
:single-line="false"
|
||||
:scroll-x="720"
|
||||
:row-key="(row: HistoryItem) => `${row.studied_at}-${row.title}-${row.path}`"
|
||||
/>
|
||||
<p v-else-if="!errorText" class="admin-status">没有学时记录</p>
|
||||
<p v-else-if="state === 'loading'" class="admin-status">正在获取</p>
|
||||
<p v-else-if="items && !items.length && !errorText" class="admin-status">没有学时记录</p>
|
||||
</div>
|
||||
<n-pagination
|
||||
v-if="items && items.length"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
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";
|
||||
import { GlobeOutline, PlayOutline, RefreshOutline, StopOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerOptions } from "../../shared/studyFields";
|
||||
|
||||
interface HomeSummary {
|
||||
name: string;
|
||||
@@ -26,6 +26,7 @@ interface StudyWorker {
|
||||
sent: number;
|
||||
total: number;
|
||||
ok: boolean;
|
||||
finished: boolean;
|
||||
}
|
||||
|
||||
type SectionState = "loading" | "ready" | "error";
|
||||
@@ -35,6 +36,7 @@ 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;
|
||||
@@ -68,7 +70,7 @@ const studyBusy = ref(false);
|
||||
const studyError = ref("");
|
||||
|
||||
const studyingWorkers = computed(() => (
|
||||
studyControl.value.workers.filter((row) => row.course.trim() && workerPercent(row) < 100)
|
||||
studyControl.value.workers.filter((row) => row.course.trim() && !workerDone(row))
|
||||
));
|
||||
|
||||
const countdownOn = computed(() => (
|
||||
@@ -121,20 +123,48 @@ function amount(value: string | number | null | undefined) {
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function withMinutes(value: string) {
|
||||
if (!value || value === "—") return "—";
|
||||
return `${value} 分钟`;
|
||||
}
|
||||
|
||||
const facts = computed(() => {
|
||||
const current = summary.value;
|
||||
return [
|
||||
{ label: "本年学时", value: current ? amount(current.year_hours) : "" },
|
||||
{ label: "本月学时", value: current ? amount(current.month_hours) : "" },
|
||||
{ label: "今日学时", value: current ? amount(current.today_hours) : "" },
|
||||
{ label: "累计学时", value: current ? amount(current.total_hours) : "" },
|
||||
{ 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 failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
return typeof payload.detail === "string" ? payload.detail : fallback;
|
||||
const detail = payload.detail;
|
||||
if (typeof detail !== "string" || !detail.trim()) return fallback;
|
||||
if (/traceback|exception|sqlite|httpx|errno|timeout|error:/i.test(detail)) return fallback;
|
||||
return detail;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
function pad(value: number) {
|
||||
@@ -156,13 +186,19 @@ function asWorkers(value: unknown): StudyWorker[] {
|
||||
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 || row.progress >= 100;
|
||||
}
|
||||
|
||||
function workerPercent(row: StudyWorker) {
|
||||
return Math.min(100, Math.max(0, Math.round(row.progress)));
|
||||
if (workerDone(row)) return 100;
|
||||
return Math.min(99, Math.max(0, Math.floor(row.progress)));
|
||||
}
|
||||
|
||||
function workerTitle(row: StudyWorker) {
|
||||
@@ -201,20 +237,23 @@ async function loadSummary() {
|
||||
const response = await fetch("/api/home/summary");
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
if (!hadData) {
|
||||
summaryError.value = failureText(payload, "个人学习信息没有获取到。");
|
||||
summaryState.value = "error";
|
||||
}
|
||||
summaryError.value = "个人学习信息没有获取到。";
|
||||
if (!hadData) summaryState.value = "error";
|
||||
return;
|
||||
}
|
||||
summary.value = payload;
|
||||
const parsed = asSummary(payload);
|
||||
if (!parsed) {
|
||||
summaryError.value = "数据异常";
|
||||
if (!hadData) summaryState.value = "error";
|
||||
return;
|
||||
}
|
||||
summary.value = parsed;
|
||||
avatarBroken.value = false;
|
||||
summaryError.value = "";
|
||||
summaryState.value = "ready";
|
||||
} catch {
|
||||
if (!hadData) {
|
||||
summaryError.value = "个人学习信息没有获取到。";
|
||||
summaryState.value = "error";
|
||||
}
|
||||
summaryError.value = "个人学习信息没有获取到。";
|
||||
if (!hadData) summaryState.value = "error";
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
@@ -318,11 +357,11 @@ async function saveSchedule() {
|
||||
day == null || hour == null || minute == null || second == null
|
||||
|| !Number.isInteger(day) || !Number.isInteger(hour) || !Number.isInteger(minute) || !Number.isInteger(second)
|
||||
) {
|
||||
scheduleError.value = "请填写完整的定时启动时间";
|
||||
scheduleError.value = "请填写完整的开始时刻";
|
||||
return;
|
||||
}
|
||||
if (workers == null || !Number.isInteger(workers) || workers < 1 || workers > 8) {
|
||||
scheduleError.value = "线程数量须为 1 到 8";
|
||||
scheduleError.value = "同时学习课程数须为 1 到 8";
|
||||
return;
|
||||
}
|
||||
scheduleSaving.value = true;
|
||||
@@ -330,7 +369,7 @@ async function saveSchedule() {
|
||||
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 putJson("/api/settings/course-workers", { workers }, "没有保存同时学习课程数。");
|
||||
await loadStudyControl();
|
||||
} catch (exc) {
|
||||
scheduleError.value = exc instanceof Error ? exc.message : "没有保存。";
|
||||
@@ -375,6 +414,8 @@ function restoreProxy() {
|
||||
proxyHasPassword.value = savedProxy.hasPassword;
|
||||
proxyError.value = "";
|
||||
}
|
||||
const proxyAccountProps = { autocomplete: "off", name: "proxy-account" };
|
||||
const proxyPasswordProps = { autocomplete: "new-password", name: "proxy-password" };
|
||||
const proxyOptions = [
|
||||
{ label: "关闭", value: "off" },
|
||||
{ label: "自动", value: "pool" },
|
||||
@@ -618,7 +659,12 @@ watch(proxyOpen, (open, wasOpen) => {
|
||||
if (wasOpen && !open) restoreProxy();
|
||||
});
|
||||
|
||||
let lastWake = 0;
|
||||
|
||||
function studyWake() {
|
||||
const now = Date.now();
|
||||
if (now - lastWake < 800) return;
|
||||
lastWake = now;
|
||||
if (studyClosed) return;
|
||||
void loadStudyControl();
|
||||
if (!studySocket || studySocket.readyState === WebSocket.CLOSING || studySocket.readyState === WebSocket.CLOSED) {
|
||||
@@ -694,24 +740,22 @@ onUnmounted(() => {
|
||||
<section class="panel-card home-summary" :aria-busy="summaryState === 'loading'">
|
||||
<div class="home-top">
|
||||
<div class="home-top-main">
|
||||
<n-alert v-if="summaryState === 'error'" class="summary-error" type="error">{{ summaryError }}</n-alert>
|
||||
<div v-else class="profile">
|
||||
<template v-if="summary">
|
||||
<img v-if="summary.avatar" class="avatar" :src="summary.avatar" alt="" referrerpolicy="no-referrer" />
|
||||
<div v-else class="brand-mark avatar-fallback" aria-hidden="true">{{ summary.name.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>
|
||||
</template>
|
||||
<template v-else>
|
||||
<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>
|
||||
</template>
|
||||
<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">
|
||||
@@ -750,11 +794,10 @@ onUnmounted(() => {
|
||||
<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 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
|
||||
id="monthly-target"
|
||||
v-model:value="monthlyTarget"
|
||||
button-placement="both"
|
||||
:min="0"
|
||||
@@ -765,17 +808,19 @@ onUnmounted(() => {
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="startLoaded" label="定时开启">
|
||||
<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="定时启动">
|
||||
<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-select 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>
|
||||
<button type="button" class="hint-icon day-warn" aria-label="开始时刻说明">
|
||||
<n-icon><WarningOutline /></n-icon>
|
||||
</button>
|
||||
</template>
|
||||
不推荐使用
|
||||
公共代理不稳定,学习可能中断
|
||||
</n-tooltip>
|
||||
<n-time-picker
|
||||
class="start-time"
|
||||
@@ -787,18 +832,8 @@ onUnmounted(() => {
|
||||
/>
|
||||
</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 v-if="workersLoaded" label="同时学习课程数">
|
||||
<n-select class="worker-select" v-model:value="courseWorkers" size="small" :options="workerOptions" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<div class="study-actions">
|
||||
@@ -832,12 +867,13 @@ onUnmounted(() => {
|
||||
<div class="study-live-status">
|
||||
<span
|
||||
class="study-indicator"
|
||||
role="status"
|
||||
:class="{
|
||||
active: !studyFailed && (studyControl.started || studyControl.active),
|
||||
down: studyFailed,
|
||||
}"
|
||||
></span>
|
||||
<span class="study-text" :class="{ muted: !studyControl.started && !studyControl.active }">{{ studyLabel }}</span>
|
||||
<span class="study-text" aria-live="polite" :class="{ muted: !studyControl.started && !studyControl.active }">{{ studyLabel }}</span>
|
||||
</div>
|
||||
<div v-if="targetLoaded" class="study-progress">
|
||||
<div class="study-progress-meta">
|
||||
@@ -855,7 +891,7 @@ onUnmounted(() => {
|
||||
<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>
|
||||
<span class="study-dot" role="status" :class="row.ok ? 'up' : 'down'" :aria-label="row.ok ? '正常' : '异常'"></span>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else-if="studyHint" class="study-live-hint">{{ studyHint }}</p>
|
||||
@@ -883,7 +919,7 @@ onUnmounted(() => {
|
||||
<n-input-number v-model:value="proxyPort" size="small" button-placement="both" :min="1" :max="65535" :precision="0" placeholder="请输入" />
|
||||
</n-form-item>
|
||||
<n-form-item label="账号">
|
||||
<n-input v-model:value="proxyUser" size="small" placeholder="可不填" autocomplete="off" />
|
||||
<n-input v-model:value="proxyUser" size="small" placeholder="可不填" :input-props="proxyAccountProps" />
|
||||
</n-form-item>
|
||||
<n-form-item label="密码">
|
||||
<n-input
|
||||
@@ -892,7 +928,7 @@ onUnmounted(() => {
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
autocomplete="new-password"
|
||||
:input-props="proxyPasswordProps"
|
||||
/>
|
||||
</n-form-item>
|
||||
</template>
|
||||
|
||||
@@ -62,7 +62,10 @@ function trainingMeta(item: TrainingItem) {
|
||||
}
|
||||
|
||||
function failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
return typeof payload.detail === "string" ? payload.detail : fallback;
|
||||
const detail = payload.detail;
|
||||
if (typeof detail !== "string" || !detail.trim()) return fallback;
|
||||
if (/traceback|exception|sqlite|httpx|errno|timeout|error:/i.test(detail)) return fallback;
|
||||
return detail;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
@@ -74,20 +77,21 @@ async function load() {
|
||||
const response = await fetch("/api/home/trainings");
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
if (!hadData) {
|
||||
errorText.value = failureText(payload, "培训列表没有获取到。");
|
||||
state.value = "error";
|
||||
}
|
||||
errorText.value = "培训列表没有获取到。";
|
||||
if (!hadData) state.value = "error";
|
||||
return;
|
||||
}
|
||||
items.value = Array.isArray(payload.trainings) ? payload.trainings : [];
|
||||
if (!payload || typeof payload !== "object" || !Array.isArray((payload as { trainings?: unknown }).trainings)) {
|
||||
errorText.value = "数据异常";
|
||||
if (!hadData) state.value = "error";
|
||||
return;
|
||||
}
|
||||
items.value = (payload as { trainings: TrainingItem[] }).trainings;
|
||||
errorText.value = "";
|
||||
state.value = "ready";
|
||||
} catch {
|
||||
if (!hadData) {
|
||||
errorText.value = "培训列表没有获取到。";
|
||||
state.value = "error";
|
||||
}
|
||||
errorText.value = "培训列表没有获取到。";
|
||||
if (!hadData) state.value = "error";
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
@@ -159,10 +163,10 @@ onMounted(refresh);
|
||||
</span>
|
||||
</header>
|
||||
<section class="board" aria-labelledby="training-heading" :aria-busy="state === 'loading'">
|
||||
<div class="rail" tabindex="0">
|
||||
<n-alert v-if="state === 'error'" class="section-error" type="error">{{ errorText }}</n-alert>
|
||||
<p v-else-if="items && !items.length" class="rail-empty">没有线上培训</p>
|
||||
<ol v-else-if="items">
|
||||
<div class="rail" tabindex="0" aria-label="线上培训">
|
||||
<n-alert v-if="errorText" class="section-error" type="error">{{ errorText }}</n-alert>
|
||||
<p v-if="items && !items.length && !errorText" class="rail-empty">没有线上培训</p>
|
||||
<ol v-else-if="items && items.length">
|
||||
<li v-for="item in items" :key="`${item.assigned}-${item.name}`" class="event">
|
||||
<span class="mark" aria-hidden="true"></span>
|
||||
<button type="button" class="event-hit" @click="openDetail(item)">
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export interface AdminSession {
|
||||
interface AdminSession {
|
||||
kind: "admin";
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface UserSession {
|
||||
interface UserSession {
|
||||
kind: "user";
|
||||
employeeId: string;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
export const workerHint = "速度较慢,但是稳定且不容易触发风控,最大可设置8";
|
||||
|
||||
export const workerOptions = [
|
||||
{ label: "1 · 推荐", value: 1 },
|
||||
{ label: "2", value: 2 },
|
||||
@@ -12,6 +10,6 @@ export const workerOptions = [
|
||||
];
|
||||
|
||||
export const dayOptions = Array.from({ length: 31 }, (_, index) => ({
|
||||
label: `每月 ${index + 1}号`,
|
||||
label: `每月 ${index + 1} 日`,
|
||||
value: index + 1,
|
||||
}));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { computed, ref, watch } from "vue";
|
||||
import type { GlobalThemeOverrides } from "naive-ui";
|
||||
|
||||
export interface Scheme {
|
||||
interface Scheme {
|
||||
id: string;
|
||||
dark: boolean;
|
||||
primary: string;
|
||||
@@ -11,7 +11,7 @@ export interface Scheme {
|
||||
vars: Record<string, string>;
|
||||
}
|
||||
|
||||
export const schemes: Scheme[] = [
|
||||
const schemes: Scheme[] = [
|
||||
{
|
||||
id: "graphite",
|
||||
dark: true,
|
||||
@@ -55,8 +55,8 @@ export const schemes: Scheme[] = [
|
||||
];
|
||||
|
||||
const stored = localStorage.getItem("euniv-scheme");
|
||||
export const schemeId = ref(stored === "day" ? "day" : "graphite");
|
||||
export const scheme = computed(() => schemes.find((item) => item.id === schemeId.value) ?? schemes[0]);
|
||||
const schemeId = ref(stored === "day" ? "day" : "graphite");
|
||||
const scheme = computed(() => schemes.find((item) => item.id === schemeId.value) ?? schemes[0]);
|
||||
export const isDark = computed(() => scheme.value.dark);
|
||||
export const themeOverrides = computed<GlobalThemeOverrides>(() => {
|
||||
const current = scheme.value;
|
||||
@@ -158,7 +158,6 @@ export const themeOverrides = computed<GlobalThemeOverrides>(() => {
|
||||
watch(scheme, (value) => {
|
||||
localStorage.setItem("euniv-scheme", value.id);
|
||||
const root = document.documentElement;
|
||||
root.dataset.theme = value.dark ? "dark" : "light";
|
||||
root.dataset.scheme = value.id;
|
||||
for (const [key, cssValue] of Object.entries(value.vars)) {
|
||||
root.style.setProperty(key, cssValue);
|
||||
|
||||
@@ -13,28 +13,57 @@ defineProps<{ username: string }>();
|
||||
const emit = defineEmits<{ logout: []; refresh: [] }>();
|
||||
const page = ref<AdminPageKey>(pageFromHash());
|
||||
const collapsed = ref(window.innerWidth < 800);
|
||||
const holdOpen = ref(false);
|
||||
const pages = new Set<AdminPageKey>(["users", "courses", "proxies", "settings"]);
|
||||
|
||||
function hashName() {
|
||||
return window.location.hash.replace(/^#\/?/, "");
|
||||
}
|
||||
|
||||
function pageFromHash(): AdminPageKey {
|
||||
const name = window.location.hash.replace(/^#\/?/, "");
|
||||
const name = hashName();
|
||||
if (name === "courses" || name === "proxies" || name === "settings" || name === "users") return name;
|
||||
return "users";
|
||||
}
|
||||
|
||||
function remember(next: AdminPageKey) {
|
||||
function knownHash(name: string) {
|
||||
return pages.has(name as AdminPageKey);
|
||||
}
|
||||
|
||||
function show(next: AdminPageKey) {
|
||||
page.value = next;
|
||||
const hash = `#/${next}`;
|
||||
if (window.location.hash !== hash) history.replaceState(null, "", hash);
|
||||
if (window.location.hash !== hash) window.location.hash = hash;
|
||||
}
|
||||
|
||||
function onHashChange() {
|
||||
const name = hashName();
|
||||
if (name && !knownHash(name)) {
|
||||
history.replaceState(null, "", "#/users");
|
||||
page.value = "users";
|
||||
return;
|
||||
}
|
||||
page.value = pageFromHash();
|
||||
}
|
||||
|
||||
function onResize() {
|
||||
if (holdOpen.value) return;
|
||||
if (window.innerWidth < 800) collapsed.value = true;
|
||||
}
|
||||
|
||||
function onCollapse() {
|
||||
collapsed.value = true;
|
||||
holdOpen.value = false;
|
||||
}
|
||||
|
||||
function onExpand() {
|
||||
collapsed.value = false;
|
||||
holdOpen.value = true;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
remember(page.value);
|
||||
const name = hashName();
|
||||
if (!name || !knownHash(name)) history.replaceState(null, "", "#/users");
|
||||
window.addEventListener("resize", onResize);
|
||||
window.addEventListener("hashchange", onHashChange);
|
||||
});
|
||||
@@ -44,10 +73,7 @@ onUnmounted(() => {
|
||||
});
|
||||
|
||||
function onMenu(key: string) {
|
||||
if (key === "users" || key === "courses" || key === "proxies" || key === "settings") {
|
||||
page.value = key;
|
||||
remember(key);
|
||||
}
|
||||
if (key === "users" || key === "courses" || key === "proxies" || key === "settings") show(key);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -62,8 +88,8 @@ function onMenu(key: string) {
|
||||
show-trigger
|
||||
:native-scrollbar="false"
|
||||
:content-style="{ height: '100%', display: 'flex', flexDirection: 'column' }"
|
||||
@collapse="collapsed = true"
|
||||
@expand="collapsed = false"
|
||||
@collapse="onCollapse"
|
||||
@expand="onExpand"
|
||||
>
|
||||
<div class="sider-body">
|
||||
<div class="sider-brand" :class="{ compact: collapsed }">
|
||||
|
||||
+37
-11
@@ -13,28 +13,57 @@ const props = defineProps<{ employeeId: string }>();
|
||||
const emit = defineEmits<{ logout: []; revoke: [] }>();
|
||||
const page = ref<PageKey>(pageFromHash());
|
||||
const collapsed = ref(window.innerWidth < 800);
|
||||
const holdOpen = ref(false);
|
||||
const pages = new Set<PageKey>(["home", "history", "exams", "trainings"]);
|
||||
|
||||
function hashName() {
|
||||
return window.location.hash.replace(/^#\/?/, "");
|
||||
}
|
||||
|
||||
function pageFromHash(): PageKey {
|
||||
const name = window.location.hash.replace(/^#\/?/, "");
|
||||
const name = hashName();
|
||||
if (name === "exams" || name === "trainings" || name === "history" || name === "home") return name;
|
||||
return "home";
|
||||
}
|
||||
|
||||
function remember(next: PageKey) {
|
||||
function knownHash(name: string) {
|
||||
return pages.has(name as PageKey);
|
||||
}
|
||||
|
||||
function show(next: PageKey) {
|
||||
page.value = next;
|
||||
const hash = `#/${next}`;
|
||||
if (window.location.hash !== hash) history.replaceState(null, "", hash);
|
||||
if (window.location.hash !== hash) window.location.hash = hash;
|
||||
}
|
||||
|
||||
function onHashChange() {
|
||||
const name = hashName();
|
||||
if (name && !knownHash(name)) {
|
||||
history.replaceState(null, "", "#/home");
|
||||
page.value = "home";
|
||||
return;
|
||||
}
|
||||
page.value = pageFromHash();
|
||||
}
|
||||
|
||||
function onResize() {
|
||||
if (holdOpen.value) return;
|
||||
if (window.innerWidth < 800) collapsed.value = true;
|
||||
}
|
||||
|
||||
function onCollapse() {
|
||||
collapsed.value = true;
|
||||
holdOpen.value = false;
|
||||
}
|
||||
|
||||
function onExpand() {
|
||||
collapsed.value = false;
|
||||
holdOpen.value = true;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
remember(page.value);
|
||||
const name = hashName();
|
||||
if (!name || !knownHash(name)) history.replaceState(null, "", "#/home");
|
||||
window.addEventListener("resize", onResize);
|
||||
window.addEventListener("hashchange", onHashChange);
|
||||
});
|
||||
@@ -49,10 +78,7 @@ const logoutOptions = [
|
||||
];
|
||||
|
||||
function onMenu(key: string) {
|
||||
if (key === "home" || key === "history" || key === "exams" || key === "trainings") {
|
||||
page.value = key;
|
||||
remember(key);
|
||||
}
|
||||
if (key === "home" || key === "history" || key === "exams" || key === "trainings") show(key);
|
||||
}
|
||||
|
||||
function onLogout(key: string) {
|
||||
@@ -72,8 +98,8 @@ function onLogout(key: string) {
|
||||
show-trigger
|
||||
:native-scrollbar="false"
|
||||
:content-style="{ height: '100%', display: 'flex', flexDirection: 'column' }"
|
||||
@collapse="collapsed = true"
|
||||
@expand="collapsed = false"
|
||||
@collapse="onCollapse"
|
||||
@expand="onExpand"
|
||||
>
|
||||
<div class="sider-body">
|
||||
<div class="sider-brand" :class="{ compact: collapsed }">
|
||||
@@ -102,7 +128,7 @@ function onLogout(key: string) {
|
||||
</template>
|
||||
{{ isDark ? "切换到日间" : "切换到夜间" }}
|
||||
</n-tooltip>
|
||||
<n-dropdown trigger="hover" placement="top-end" :options="logoutOptions" @select="onLogout">
|
||||
<n-dropdown trigger="click" placement="top-end" :options="logoutOptions" @select="onLogout">
|
||||
<n-button class="logout-btn" quaternary circle size="small" aria-label="退出">
|
||||
<template #icon><n-icon><LogOutOutline /></n-icon></template>
|
||||
</n-button>
|
||||
|
||||
+158
-27
@@ -13,6 +13,10 @@
|
||||
--accent-soft: rgba(121, 192, 255, 0.16);
|
||||
--sidebar: #0d1117;
|
||||
--danger: #f85149;
|
||||
--ok: #3fb950;
|
||||
--warn: #d29922;
|
||||
--paper: #ffffff;
|
||||
--overlay: rgba(13, 17, 23, 0.72);
|
||||
}
|
||||
|
||||
:root[data-scheme="day"] {
|
||||
@@ -26,6 +30,10 @@
|
||||
--accent-soft: rgba(9, 105, 218, 0.12);
|
||||
--sidebar: #ffffff;
|
||||
--danger: #cf222e;
|
||||
--ok: #1a7f37;
|
||||
--warn: #9a6700;
|
||||
--paper: #ffffff;
|
||||
--overlay: rgba(13, 17, 23, 0.72);
|
||||
}
|
||||
|
||||
::selection {
|
||||
@@ -62,9 +70,11 @@ select {
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
justify-content: flex-start;
|
||||
padding: 32px 16px;
|
||||
background: var(--bg);
|
||||
}
|
||||
@@ -77,6 +87,9 @@ select {
|
||||
|
||||
.gate-card {
|
||||
width: min(440px, 100%);
|
||||
flex: none;
|
||||
margin-top: auto;
|
||||
margin-bottom: auto;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 4px;
|
||||
@@ -182,8 +195,7 @@ select {
|
||||
height: 210px;
|
||||
padding: 0;
|
||||
border: 1px solid var(--line);
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
background: var(--paper);
|
||||
}
|
||||
|
||||
.qr-frame img {
|
||||
@@ -197,14 +209,28 @@ select {
|
||||
inset: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: rgba(13, 17, 23, 0.72);
|
||||
color: #fff;
|
||||
width: 100%;
|
||||
border: 0;
|
||||
background: var(--overlay);
|
||||
color: var(--paper);
|
||||
font: inherit;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.qr-ttl {
|
||||
margin: 8px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.qr-refresh {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.gate-card.with-jigsaw {
|
||||
width: max-content;
|
||||
max-width: calc(100% - 32px);
|
||||
width: min(440px, 100%);
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.jigsaw-block {
|
||||
@@ -216,17 +242,30 @@ select {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.jigsaw {
|
||||
.jigsaw-stage {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.jigsaw-frame {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.jigsaw {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
transform-origin: top left;
|
||||
user-select: none;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.jigsaw .board,
|
||||
.jigsaw-board,
|
||||
.jigsaw .piece {
|
||||
display: block;
|
||||
max-width: none;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.jigsaw .piece {
|
||||
@@ -235,9 +274,11 @@ select {
|
||||
}
|
||||
|
||||
.jigsaw-track {
|
||||
position: relative;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 36px;
|
||||
margin: 8px auto 0;
|
||||
transform-origin: top left;
|
||||
border: 1px solid var(--line);
|
||||
background: var(--elevated);
|
||||
touch-action: none;
|
||||
@@ -245,7 +286,7 @@ select {
|
||||
|
||||
.jigsaw-handle {
|
||||
position: absolute;
|
||||
top: -1px;
|
||||
top: 0;
|
||||
width: 40px;
|
||||
height: 36px;
|
||||
display: grid;
|
||||
@@ -326,8 +367,8 @@ select {
|
||||
padding-top: 8px;
|
||||
}
|
||||
|
||||
.shell .n-menu .n-menu-item-content--selected::before {
|
||||
background-color: transparent !important;
|
||||
.shell .n-layout-sider .n-menu .n-menu-item-content.n-menu-item-content--selected::before {
|
||||
background-color: transparent;
|
||||
border-left: 2px solid var(--accent);
|
||||
border-radius: 0;
|
||||
}
|
||||
@@ -432,7 +473,8 @@ select {
|
||||
.home {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
@@ -485,9 +527,9 @@ select {
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.compact-nform .n-form-item-label {
|
||||
.compact-nform .n-form-item .n-form-item-label {
|
||||
white-space: nowrap;
|
||||
padding-right: 12px !important;
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
.compact-nform .n-form-item-blank {
|
||||
@@ -681,14 +723,12 @@ select {
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding-left: 96px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.day-warn {
|
||||
color: #d29922;
|
||||
color: var(--warn);
|
||||
font-size: 18px;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.target-unit {
|
||||
@@ -713,8 +753,8 @@ select {
|
||||
}
|
||||
|
||||
.study-indicator.active {
|
||||
background: #3fb950;
|
||||
box-shadow: 0 0 6px rgba(63, 185, 80, 0.5);
|
||||
background: var(--ok);
|
||||
box-shadow: 0 0 6px var(--ok);
|
||||
}
|
||||
|
||||
.study-indicator.down {
|
||||
@@ -878,13 +918,13 @@ select {
|
||||
}
|
||||
|
||||
.study-dot.up {
|
||||
background: #3fb950;
|
||||
box-shadow: 0 0 6px rgba(63, 185, 80, 0.5);
|
||||
background: var(--ok);
|
||||
box-shadow: 0 0 6px var(--ok);
|
||||
}
|
||||
|
||||
.study-dot.down {
|
||||
background: #f85149;
|
||||
box-shadow: 0 0 6px rgba(248, 81, 73, 0.5);
|
||||
background: var(--danger);
|
||||
box-shadow: 0 0 6px var(--danger);
|
||||
}
|
||||
|
||||
.history-facts {
|
||||
@@ -1310,7 +1350,15 @@ select {
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1099px) {
|
||||
@media (max-width: 1100px), (max-height: 760px) {
|
||||
.study-card,
|
||||
.study-card.is-busy {
|
||||
flex: none;
|
||||
overflow: visible;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.study-card-body,
|
||||
.study-card.is-busy .study-card-body {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
@@ -1587,6 +1635,41 @@ select {
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.app-root {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.session-note {
|
||||
margin: 0 0 16px;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.session-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.session-banner p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.session-banner-float {
|
||||
position: absolute;
|
||||
z-index: 30;
|
||||
top: 12px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: min(420px, calc(100% - 24px));
|
||||
padding: 8px 12px;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
body .n-input .n-input__input-el,
|
||||
@@ -1647,3 +1730,51 @@ body .n-base-select-menu .n-base-select-option__content {
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.gate {
|
||||
padding: 16px 12px;
|
||||
}
|
||||
|
||||
.gate-card {
|
||||
padding: 20px 16px 16px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.facts,
|
||||
.history-facts {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.page-head,
|
||||
.course-search,
|
||||
.target-control,
|
||||
.start-control {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.worker-select,
|
||||
.target-control .n-input-number,
|
||||
.day-select {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.compact-nform .n-form-item {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.compact-nform .n-form-item-label {
|
||||
width: 100% !important;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.schedule-choice {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"jsx": "preserve",
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
|
||||
export default defineConfig({
|
||||
base: "/",
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
proxy: {
|
||||
|
||||
Reference in New Issue
Block a user