feat: 学习进度轮询、学时依据与首页代理弹窗
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NInput, NPagination, NTooltip } from "naive-ui";
|
||||
import { FlashOutline, RefreshOutline } from "@vicons/ionicons5";
|
||||
import { NAlert, NButton, NIcon, NInput, NPagination, NSpin, NTooltip } from "naive-ui";
|
||||
import { RefreshOutline } from "@vicons/ionicons5";
|
||||
|
||||
interface ProxyRow {
|
||||
id: number;
|
||||
@@ -89,6 +89,12 @@ function formatLatency(value: number | null) {
|
||||
return `${value} ms`;
|
||||
}
|
||||
|
||||
const probingHost = computed(() => {
|
||||
if (probingId.value == null) return "";
|
||||
const row = items.value.find((item) => item.id === probingId.value);
|
||||
return row ? `${row.host}:${row.port}` : "";
|
||||
});
|
||||
|
||||
function schemeLabel(value: string) {
|
||||
return value ? value.toUpperCase() : "—";
|
||||
}
|
||||
@@ -261,14 +267,9 @@ onUnmounted(() => stopPoll());
|
||||
</template>
|
||||
立即更新
|
||||
</n-tooltip>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button quaternary circle attr-type="button" :loading="probingAll" :disabled="probingAll || fetching || !items.length" aria-label="测试全部延迟" @click="probeAll">
|
||||
<template #icon><n-icon><FlashOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
测试全部延迟
|
||||
</n-tooltip>
|
||||
<n-button size="small" attr-type="button" :loading="probingAll" :disabled="probingAll || fetching || !items.length" @click="probeAll">
|
||||
测试全部
|
||||
</n-button>
|
||||
<n-input v-model:value="query" placeholder="地址" clearable @clear="search" />
|
||||
<n-button attr-type="submit">搜索</n-button>
|
||||
</form>
|
||||
@@ -287,6 +288,8 @@ 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-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>
|
||||
@@ -314,26 +317,23 @@ onUnmounted(() => stopPoll());
|
||||
<td>{{ schemeLabel(row.scheme) }}</td>
|
||||
<td>{{ row.anonymity }}</td>
|
||||
<td>{{ row.source }}</td>
|
||||
<td class="when">{{ formatLatency(row.latency_ms) }}</td>
|
||||
<td class="when">
|
||||
<span v-if="probingAll || probingId === row.id" class="probe-loading">
|
||||
<n-spin :size="14" />测试中
|
||||
</span>
|
||||
<template v-else>{{ formatLatency(row.latency_ms) }}</template>
|
||||
</td>
|
||||
<td :class="statusClass(row)">{{ row.status_text }}</td>
|
||||
<td class="when">{{ formatTime(row.last_checked_at) || "—" }}</td>
|
||||
<td>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button
|
||||
size="small"
|
||||
quaternary
|
||||
circle
|
||||
:loading="probingId === row.id"
|
||||
:disabled="probingAll || fetching || (probingId != null && probingId !== row.id)"
|
||||
:aria-label="`测试 ${row.host} 延迟`"
|
||||
@click="probeOne(row)"
|
||||
>
|
||||
<template #icon><n-icon><FlashOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
测试延迟
|
||||
</n-tooltip>
|
||||
<n-button
|
||||
size="tiny"
|
||||
:loading="probingId === row.id"
|
||||
:disabled="probingAll || fetching || (probingId != null && probingId !== row.id)"
|
||||
@click="probeOne(row)"
|
||||
>
|
||||
测试
|
||||
</n-button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -20,6 +20,7 @@ const hbMode = ref("manual");
|
||||
const hbVideo = ref<number | null>(30);
|
||||
const hbDocument = ref<number | null>(120);
|
||||
const hbScorm = ref<number | null>(120);
|
||||
const hoursSource = ref("api");
|
||||
|
||||
const preferenceLabel = computed(() =>
|
||||
showManualJigsaw.value ? "默认勾选手动滑动验证码" : "先尝试自动滑动验证码",
|
||||
@@ -66,6 +67,7 @@ onMounted(async () => {
|
||||
hbVideo.value = readNumber(body.heartbeat_video_seconds) ?? 30;
|
||||
hbDocument.value = readNumber(body.heartbeat_document_seconds) ?? 120;
|
||||
hbScorm.value = readNumber(body.heartbeat_scorm_seconds) ?? 120;
|
||||
hoursSource.value = body.hours_source === "history" ? "history" : "api";
|
||||
loaded.value = true;
|
||||
} catch {
|
||||
errorText.value = "系统配置没有获取到。";
|
||||
@@ -119,6 +121,7 @@ async function save() {
|
||||
heartbeat_video_seconds: hbVideo.value as number,
|
||||
heartbeat_document_seconds: hbDocument.value as number,
|
||||
heartbeat_scorm_seconds: hbScorm.value as number,
|
||||
hours_source: hoursSource.value,
|
||||
};
|
||||
if (password.value !== "" || confirmPassword.value !== "") {
|
||||
if (password.value !== confirmPassword.value) {
|
||||
@@ -218,6 +221,18 @@ async function save() {
|
||||
</template>
|
||||
</n-form>
|
||||
</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-item label="判断依据">
|
||||
<n-radio-group v-model:value="hoursSource" size="small">
|
||||
<n-radio-button value="api">接口本月学时</n-radio-button>
|
||||
<n-radio-button value="history">学时历史统计</n-radio-button>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<p class="form-hint">学时历史按倒序分页统计到上个月为止</p>
|
||||
</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">
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NCheckbox, NDropdown, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NSelect, NTimePicker, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
||||
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, HelpCircleOutline, PauseOutline, PlayOutline, SettingsOutline } from "@vicons/ionicons5";
|
||||
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, PauseOutline, PlayOutline, SettingsOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerOptions } from "../../shared/studyFields";
|
||||
|
||||
interface UserRow {
|
||||
employee_id: string;
|
||||
@@ -704,62 +705,51 @@ 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="88" :show-feedback="false" size="small" @submit.prevent="saveSettings">
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="96" :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" />
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item label="每月开始">
|
||||
<n-form-item label="定时启动">
|
||||
<div class="target-control start-control">
|
||||
<n-input-number id="admin-start-day" v-model:value="startDay" button-placement="both" :min="1" :max="31" :precision="0" />
|
||||
<span class="target-unit">日</span>
|
||||
<n-select id="admin-start-day" v-model:value="startDay" :options="dayOptions" class="day-select" />
|
||||
<n-tooltip v-if="startDay === 1" placement="top">
|
||||
<template #trigger>
|
||||
<n-icon class="day-warn"><WarningOutline /></n-icon>
|
||||
</template>
|
||||
不推荐使用
|
||||
</n-tooltip>
|
||||
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" :actions="null" />
|
||||
</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>
|
||||
速度较慢,但是稳定且不容易触发风控,最大可设置8
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
<div class="target-control">
|
||||
<n-input-number id="admin-course-workers" v-model:value="workersValue" button-placement="both" :min="1" :max="8" :precision="0" />
|
||||
<span class="target-unit">门</span>
|
||||
<span v-if="workersValue === 1" class="recommend-mark">推荐</span>
|
||||
</div>
|
||||
<n-form-item label="线程数量">
|
||||
<n-select id="admin-course-workers" v-model:value="workersValue" :options="workerOptions" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理类型">
|
||||
<n-select v-model:value="proxyScheme" :options="proxyOptions" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理地址">
|
||||
<n-input v-model:value="proxyHost" placeholder="例如 127.0.0.1" :disabled="!proxyManual" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理端口">
|
||||
<n-input-number v-model:value="proxyPort" button-placement="both" :min="1" :max="65535" :precision="0" :disabled="!proxyManual" placeholder="请输入" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理账号">
|
||||
<n-input v-model:value="proxyUser" placeholder="可不填" autocomplete="off" :disabled="!proxyManual" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理密码">
|
||||
<n-input
|
||||
v-model:value="proxyPassword"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="settingsIds.length === 1 && proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
autocomplete="new-password"
|
||||
:disabled="!proxyManual"
|
||||
/>
|
||||
</n-form-item>
|
||||
<template v-if="proxyManual">
|
||||
<n-form-item label="代理地址">
|
||||
<n-input v-model:value="proxyHost" placeholder="例如 127.0.0.1" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理端口">
|
||||
<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-form-item>
|
||||
<n-form-item label="代理密码">
|
||||
<n-input
|
||||
v-model:value="proxyPassword"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="settingsIds.length === 1 && proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
</n-form-item>
|
||||
</template>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
|
||||
@@ -86,6 +86,45 @@ function refresh() {
|
||||
});
|
||||
}
|
||||
|
||||
function beijingParts(now = new Date()) {
|
||||
const fmt = new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone: "Asia/Shanghai",
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
});
|
||||
const mapped = Object.fromEntries(fmt.formatToParts(now).map((part) => [part.type, part.value]));
|
||||
return { y: Number(mapped.year), m: Number(mapped.month), d: Number(mapped.day) };
|
||||
}
|
||||
|
||||
function stampParts(text: string) {
|
||||
const match = /^(\d{4})-(\d{2})-(\d{2})/.exec(text.trim());
|
||||
if (!match) return null;
|
||||
return { y: Number(match[1]), m: Number(match[2]), d: Number(match[3]) };
|
||||
}
|
||||
|
||||
function sumMinutes(filter: (stamp: { y: number; m: number; d: number }) => boolean) {
|
||||
const rows = items.value ?? [];
|
||||
let total = 0;
|
||||
for (const item of rows) {
|
||||
if (typeof item.minutes !== "number") continue;
|
||||
const stamp = stampParts(item.studied_at);
|
||||
if (!stamp) continue;
|
||||
if (filter(stamp)) total += item.minutes;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
const historyFacts = computed(() => {
|
||||
const now = beijingParts();
|
||||
return [
|
||||
{ label: "总学时", value: sumMinutes(() => true) },
|
||||
{ label: "本年学时", value: sumMinutes((stamp) => stamp.y === now.y) },
|
||||
{ label: "本月学时", value: sumMinutes((stamp) => stamp.y === now.y && stamp.m === now.m) },
|
||||
{ label: "本日学时", value: sumMinutes((stamp) => stamp.y === now.y && stamp.m === now.m && stamp.d === now.d) },
|
||||
];
|
||||
});
|
||||
|
||||
const paged = computed(() => {
|
||||
const rows = items.value ?? [];
|
||||
const start = (page.value - 1) * pageSize.value;
|
||||
@@ -157,6 +196,15 @@ onMounted(refresh);
|
||||
</n-tooltip>
|
||||
</header>
|
||||
<n-alert v-if="state === 'error'" 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>
|
||||
<dd>
|
||||
<span v-if="state === 'loading'" class="bone bone-value"></span>
|
||||
<template v-else>{{ state === "ready" ? item.value : "—" }}</template>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<div class="history-table">
|
||||
<n-data-table
|
||||
v-if="state !== 'error'"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInput, NInputNumber, NSelect, NTimePicker, NTooltip } from "naive-ui";
|
||||
import { HelpCircleOutline, PlayOutline, RefreshOutline, StopOutline } from "@vicons/ionicons5";
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NProgress, NSelect, NTimePicker, NTooltip } from "naive-ui";
|
||||
import { GlobeOutline, PlayOutline, RefreshOutline, StopOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import { dayOptions, workerOptions } from "../../shared/studyFields";
|
||||
|
||||
interface HomeSummary {
|
||||
name: string;
|
||||
@@ -16,6 +17,15 @@ interface HomeSummary {
|
||||
points: string | number | null;
|
||||
}
|
||||
|
||||
interface StudyWorker {
|
||||
id: number;
|
||||
course: string;
|
||||
progress: number;
|
||||
interval: number;
|
||||
heartbeat_at: number;
|
||||
ok: boolean;
|
||||
}
|
||||
|
||||
type SectionState = "loading" | "ready" | "error";
|
||||
|
||||
const props = defineProps<{ employeeId: string }>();
|
||||
@@ -25,22 +35,13 @@ const summaryError = ref("");
|
||||
const refreshing = ref(false);
|
||||
let refreshRunning = false;
|
||||
let busy = false;
|
||||
let studyPoll = 0;
|
||||
const nowTick = ref(Date.now());
|
||||
|
||||
const monthlyTarget = ref<number | null>(null);
|
||||
const targetLoaded = ref(false);
|
||||
let targetSaveTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
interface StudyUserState {
|
||||
state?: string;
|
||||
course?: string;
|
||||
}
|
||||
|
||||
const studyStatus = ref<{
|
||||
running: boolean;
|
||||
users?: Record<string, StudyUserState>;
|
||||
message: string;
|
||||
} | null>(null);
|
||||
|
||||
const studyControl = ref({
|
||||
started: false,
|
||||
paused: false,
|
||||
@@ -49,28 +50,22 @@ const studyControl = ref({
|
||||
active: false,
|
||||
state: "",
|
||||
course: "",
|
||||
message: "",
|
||||
workers: [] as StudyWorker[],
|
||||
});
|
||||
const studyBusy = ref(false);
|
||||
const studyError = ref("");
|
||||
|
||||
const myStudy = computed(() => {
|
||||
const users = studyStatus.value?.users;
|
||||
if (!users) return null;
|
||||
return users[props.employeeId] ?? null;
|
||||
});
|
||||
|
||||
const studyLabel = computed(() => {
|
||||
const live = myStudy.value;
|
||||
const state = live?.state || studyControl.value.state;
|
||||
const course = live?.course || studyControl.value.course;
|
||||
const state = studyControl.value.state;
|
||||
const course = studyControl.value.course;
|
||||
if (state === "已达标") return "本月目标已达到";
|
||||
if (state === "已停止" || studyControl.value.paused) return "任务已停止";
|
||||
if (studyControl.value.active || live) {
|
||||
if (studyControl.value.active) {
|
||||
return `正在学习:${course || state || "准备中"}`;
|
||||
}
|
||||
if (studyControl.value.started) return "任务已开始,等待执行";
|
||||
if (studyStatus.value?.message) return studyStatus.value.message;
|
||||
if (studyStatus.value?.running) return "自动学习进行中";
|
||||
if (studyControl.value.message) return studyControl.value.message;
|
||||
return "未到开始时间";
|
||||
});
|
||||
|
||||
@@ -102,6 +97,41 @@ function pad(value: number) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
|
||||
function asWorkers(value: unknown): StudyWorker[] {
|
||||
if (!Array.isArray(value)) return [];
|
||||
const rows: StudyWorker[] = [];
|
||||
for (const item of value) {
|
||||
if (!item || typeof item !== "object") continue;
|
||||
const row = item as Record<string, unknown>;
|
||||
rows.push({
|
||||
id: typeof row.id === "number" ? row.id : rows.length + 1,
|
||||
course: typeof row.course === "string" ? row.course : "",
|
||||
progress: typeof row.progress === "number" ? row.progress : 0,
|
||||
interval: typeof row.interval === "number" ? row.interval : 0,
|
||||
heartbeat_at: typeof row.heartbeat_at === "number" ? row.heartbeat_at : 0,
|
||||
ok: row.ok !== false,
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
function workerPercent(row: StudyWorker) {
|
||||
return Math.min(100, Math.max(0, Math.round(row.progress)));
|
||||
}
|
||||
|
||||
function workerTitle(row: StudyWorker) {
|
||||
if (row.course) return row.course;
|
||||
if (workerPercent(row) >= 100) return "空闲";
|
||||
return "准备";
|
||||
}
|
||||
|
||||
function heartbeatLeft(row: StudyWorker) {
|
||||
void nowTick.value;
|
||||
if (!row.heartbeat_at) return "—";
|
||||
const left = Math.max(0, Math.ceil(row.heartbeat_at - Date.now() / 1000));
|
||||
return `${left}s`;
|
||||
}
|
||||
|
||||
async function loadSummary() {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
@@ -134,7 +164,7 @@ function refresh() {
|
||||
if (refreshRunning) return;
|
||||
refreshRunning = true;
|
||||
refreshing.value = true;
|
||||
void Promise.all([loadSummary(), loadStudyStatus(), loadStudyControl()]).finally(() => {
|
||||
void Promise.all([loadSummary(), loadStudyControl()]).finally(() => {
|
||||
refreshRunning = false;
|
||||
refreshing.value = false;
|
||||
});
|
||||
@@ -256,6 +286,7 @@ function saveWorkers(value: number | null) {
|
||||
|
||||
watch(courseWorkers, (v) => { if (workersLoaded.value) saveWorkers(v); });
|
||||
|
||||
const proxyOpen = ref(false);
|
||||
const proxyLoaded = ref(false);
|
||||
const proxySaving = ref(false);
|
||||
const proxyError = ref("");
|
||||
@@ -266,6 +297,31 @@ const proxyUser = ref("");
|
||||
const proxyPassword = ref("");
|
||||
const proxyHasPassword = ref(false);
|
||||
const proxyManual = computed(() => proxyScheme.value !== "off" && proxyScheme.value !== "pool");
|
||||
const savedProxy = {
|
||||
scheme: "off",
|
||||
host: "",
|
||||
port: null as number | null,
|
||||
username: "",
|
||||
hasPassword: false,
|
||||
};
|
||||
|
||||
function rememberProxy() {
|
||||
savedProxy.scheme = proxyScheme.value;
|
||||
savedProxy.host = proxyHost.value;
|
||||
savedProxy.port = proxyPort.value;
|
||||
savedProxy.username = proxyUser.value;
|
||||
savedProxy.hasPassword = proxyHasPassword.value;
|
||||
}
|
||||
|
||||
function restoreProxy() {
|
||||
proxyScheme.value = savedProxy.scheme;
|
||||
proxyHost.value = savedProxy.host;
|
||||
proxyPort.value = savedProxy.port;
|
||||
proxyUser.value = savedProxy.username;
|
||||
proxyPassword.value = "";
|
||||
proxyHasPassword.value = savedProxy.hasPassword;
|
||||
proxyError.value = "";
|
||||
}
|
||||
const proxyOptions = [
|
||||
{ label: "关闭", value: "off" },
|
||||
{ label: "自动", value: "pool" },
|
||||
@@ -287,6 +343,7 @@ async function loadProxy() {
|
||||
proxyPassword.value = "";
|
||||
proxyHasPassword.value = data.has_password === true;
|
||||
proxyLoaded.value = true;
|
||||
rememberProxy();
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
@@ -339,6 +396,8 @@ async function saveProxy() {
|
||||
proxyUser.value = "";
|
||||
proxyHasPassword.value = false;
|
||||
}
|
||||
rememberProxy();
|
||||
proxyOpen.value = false;
|
||||
} catch {
|
||||
proxyError.value = "没有保存。";
|
||||
} finally {
|
||||
@@ -346,13 +405,6 @@ async function saveProxy() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStudyStatus() {
|
||||
try {
|
||||
const res = await fetch("/api/autostudy/status");
|
||||
if (res.ok) studyStatus.value = await res.json();
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
function applyStudyControl(payload: Record<string, unknown>) {
|
||||
studyControl.value = {
|
||||
started: payload.started === true,
|
||||
@@ -362,6 +414,8 @@ function applyStudyControl(payload: Record<string, unknown>) {
|
||||
active: payload.active === true,
|
||||
state: typeof payload.state === "string" ? payload.state : "",
|
||||
course: typeof payload.course === "string" ? payload.course : "",
|
||||
message: typeof payload.message === "string" ? payload.message : "",
|
||||
workers: asWorkers(payload.workers),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -373,6 +427,33 @@ async function loadStudyControl() {
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
function startStudyPoll() {
|
||||
if (studyPoll) return;
|
||||
studyPoll = window.setInterval(() => {
|
||||
nowTick.value = Date.now();
|
||||
void loadStudyControl();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function stopStudyPoll() {
|
||||
if (studyPoll) {
|
||||
window.clearInterval(studyPoll);
|
||||
studyPoll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
watch(proxyOpen, (open, wasOpen) => {
|
||||
if (wasOpen && !open) restoreProxy();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => studyControl.value.started,
|
||||
(started) => {
|
||||
if (started) startStudyPoll();
|
||||
else stopStudyPoll();
|
||||
},
|
||||
);
|
||||
|
||||
async function toggleStudy() {
|
||||
if (studyBusy.value) return;
|
||||
studyBusy.value = true;
|
||||
@@ -390,7 +471,6 @@ async function toggleStudy() {
|
||||
return;
|
||||
}
|
||||
applyStudyControl(data);
|
||||
await loadStudyStatus();
|
||||
} catch {
|
||||
studyError.value = action === "start" ? "没有开始。" : "没有停止。";
|
||||
} finally {
|
||||
@@ -405,6 +485,13 @@ onMounted(() => {
|
||||
loadWorkers();
|
||||
loadProxy();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
stopStudyPoll();
|
||||
clearTimeout(targetSaveTimer);
|
||||
clearTimeout(startSaveTimer);
|
||||
clearTimeout(workersSaveTimer);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -461,7 +548,7 @@ onMounted(() => {
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="panel-card">
|
||||
<section class="panel-card study-card">
|
||||
<header class="panel-card-head">
|
||||
<h3>自动学习</h3>
|
||||
<n-button
|
||||
@@ -477,7 +564,7 @@ onMounted(() => {
|
||||
</n-button>
|
||||
</header>
|
||||
<n-alert v-if="studyError" class="summary-error" type="error">{{ studyError }}</n-alert>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="88" :show-feedback="false" size="small">
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="96" :show-feedback="false" size="small">
|
||||
<n-form-item v-if="targetLoaded" label="每月目标">
|
||||
<div class="target-control">
|
||||
<n-input-number
|
||||
@@ -492,66 +579,68 @@ onMounted(() => {
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="startLoaded" label="每月开始">
|
||||
<n-form-item v-if="startLoaded" label="定时启动">
|
||||
<div class="target-control start-control">
|
||||
<n-input-number id="study-start-day" v-model:value="startDay" button-placement="both" :min="1" :max="31" :precision="0" size="small" />
|
||||
<span class="target-unit">日</span>
|
||||
<n-select id="study-start-day" v-model:value="startDay" size="small" :options="dayOptions" class="day-select" />
|
||||
<n-tooltip v-if="startDay === 1" placement="top">
|
||||
<template #trigger>
|
||||
<n-icon class="day-warn"><WarningOutline /></n-icon>
|
||||
</template>
|
||||
不推荐使用
|
||||
</n-tooltip>
|
||||
<n-time-picker v-model:formatted-value="startTime" value-format="HH:mm:ss" size="small" :actions="null" />
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="workersLoaded">
|
||||
<template #label>
|
||||
<span class="field-title">
|
||||
<span>同时课程</span>
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
<button type="button" class="hint-icon" aria-label="说明">
|
||||
<n-icon><HelpCircleOutline /></n-icon>
|
||||
</button>
|
||||
</template>
|
||||
速度较慢,但是稳定且不容易触发风控,最大可设置8
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</template>
|
||||
<div class="target-control">
|
||||
<n-input-number
|
||||
id="course-workers"
|
||||
v-model:value="courseWorkers"
|
||||
button-placement="both"
|
||||
:min="1"
|
||||
:max="8"
|
||||
:precision="0"
|
||||
size="small"
|
||||
/>
|
||||
<span class="target-unit">门</span>
|
||||
<span v-if="courseWorkers === 1" class="recommend-mark">推荐</span>
|
||||
</div>
|
||||
<n-form-item v-if="workersLoaded" label="线程数量">
|
||||
<n-select id="course-workers" v-model:value="courseWorkers" size="small" :options="workerOptions" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<div class="home-study-status">
|
||||
<span class="study-indicator" :class="{ active: studyControl.started || studyControl.active }"></span>
|
||||
<span class="study-text" :class="{ muted: !studyControl.active }">{{ studyLabel }}</span>
|
||||
</div>
|
||||
<ul v-if="studyControl.started && studyControl.workers.length" class="study-workers">
|
||||
<li v-for="row in studyControl.workers" :key="row.id" class="study-worker">
|
||||
<div class="study-worker-main">
|
||||
<span class="study-worker-title">{{ workerTitle(row) }}</span>
|
||||
<n-progress type="line" :percentage="workerPercent(row)" :show-indicator="false" :height="8" />
|
||||
</div>
|
||||
<div class="study-worker-meta">
|
||||
<span class="study-worker-pct">{{ workerPercent(row) }}%</span>
|
||||
<span class="study-heartbeat">{{ heartbeatLeft(row) }}</span>
|
||||
<span class="study-dot" :class="row.ok ? 'up' : 'down'"></span>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="study-card-foot">
|
||||
<n-button v-if="proxyLoaded" size="small" quaternary @click="proxyOpen = true">
|
||||
<template #icon><n-icon><GlobeOutline /></n-icon></template>
|
||||
代理
|
||||
</n-button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<form v-if="proxyLoaded" class="panel-card" @submit.prevent="saveProxy">
|
||||
<header class="panel-card-head">
|
||||
<h3>代理</h3>
|
||||
<n-button type="primary" size="small" attr-type="submit" :loading="proxySaving">保存</n-button>
|
||||
</header>
|
||||
<n-alert v-if="proxyError" class="summary-error" type="error">{{ proxyError }}</n-alert>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="88" :show-feedback="false" size="small">
|
||||
<n-form-item label="类型">
|
||||
<n-select v-model:value="proxyScheme" size="small" :options="proxyOptions" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<n-modal
|
||||
:show="proxyOpen"
|
||||
preset="card"
|
||||
title="代理"
|
||||
:style="{ width: 'min(420px, calc(100vw - 32px))' }"
|
||||
@update:show="(show) => (proxyOpen = show)"
|
||||
>
|
||||
<n-alert v-if="proxyError" class="summary-error" type="error">{{ proxyError }}</n-alert>
|
||||
<n-form class="compact-nform" label-placement="left" label-align="left" :label-width="72" :show-feedback="false" size="small">
|
||||
<n-form-item label="类型">
|
||||
<n-select v-model:value="proxyScheme" size="small" :options="proxyOptions" />
|
||||
</n-form-item>
|
||||
<template v-if="proxyManual">
|
||||
<n-form-item label="地址">
|
||||
<n-input v-model:value="proxyHost" size="small" placeholder="例如 127.0.0.1" :disabled="!proxyManual" />
|
||||
<n-input v-model:value="proxyHost" size="small" placeholder="例如 127.0.0.1" />
|
||||
</n-form-item>
|
||||
<n-form-item label="端口">
|
||||
<n-input-number v-model:value="proxyPort" size="small" button-placement="both" :min="1" :max="65535" :precision="0" :disabled="!proxyManual" placeholder="请输入" />
|
||||
<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" :disabled="!proxyManual" />
|
||||
<n-input v-model:value="proxyUser" size="small" placeholder="可不填" autocomplete="off" />
|
||||
</n-form-item>
|
||||
<n-form-item label="密码">
|
||||
<n-input
|
||||
@@ -561,11 +650,16 @@ onMounted(() => {
|
||||
show-password-on="click"
|
||||
:placeholder="proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
autocomplete="new-password"
|
||||
:disabled="!proxyManual"
|
||||
/>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
<n-button @click="proxyOpen = false">取消</n-button>
|
||||
<n-button type="primary" :loading="proxySaving" @click="saveProxy">保存</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export const workerOptions = [
|
||||
{ label: "1 · 推荐,速度较慢,稳定且不容易触发风控", value: 1 },
|
||||
{ label: "2", value: 2 },
|
||||
{ label: "3", value: 3 },
|
||||
{ label: "4", value: 4 },
|
||||
{ label: "5", value: 5 },
|
||||
{ label: "6", value: 6 },
|
||||
{ label: "7", value: 7 },
|
||||
{ label: "8 · 最大", value: 8 },
|
||||
];
|
||||
|
||||
export const dayOptions = Array.from({ length: 31 }, (_, index) => ({
|
||||
label: `${index + 1}日`,
|
||||
value: index + 1,
|
||||
}));
|
||||
@@ -558,10 +558,20 @@ select {
|
||||
width: 88px;
|
||||
}
|
||||
|
||||
.start-control .day-select {
|
||||
width: 108px;
|
||||
}
|
||||
|
||||
.start-control .n-time-picker {
|
||||
width: 148px;
|
||||
}
|
||||
|
||||
.day-warn {
|
||||
color: #d29922;
|
||||
font-size: 18px;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.target-unit {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
@@ -597,6 +607,97 @@ select {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.study-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.study-workers {
|
||||
list-style: none;
|
||||
margin: 12px 0 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.study-worker {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.study-worker-main {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.study-worker-title {
|
||||
font-size: 13px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.study-worker-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: none;
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.study-worker-pct {
|
||||
width: 36px;
|
||||
text-align: right;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.study-heartbeat {
|
||||
width: 36px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.study-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.study-dot.up {
|
||||
background: #3fb950;
|
||||
box-shadow: 0 0 6px rgba(63, 185, 80, 0.5);
|
||||
}
|
||||
|
||||
.study-dot.down {
|
||||
background: #f85149;
|
||||
box-shadow: 0 0 6px rgba(248, 81, 73, 0.5);
|
||||
}
|
||||
|
||||
.study-card-foot {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.history-facts {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.probe-loading {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.profile {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -1022,6 +1123,10 @@ select {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.history-facts {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.detail-facts {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user