feat: 立即开始停止学习并整理学时历史与界面
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NAlert, NButton, NInput, NPagination } from "naive-ui";
|
||||
import { NAlert, NButton, NIcon, NInput, NPagination, NTooltip } from "naive-ui";
|
||||
import { DownloadOutline } from "@vicons/ionicons5";
|
||||
|
||||
interface CourseRow {
|
||||
title: string;
|
||||
@@ -173,7 +174,14 @@ onUnmounted(() => stopPoll());
|
||||
</p>
|
||||
</div>
|
||||
<form class="course-search" @submit.prevent="search">
|
||||
<n-button attr-type="button" :loading="fetching" :disabled="fetching" @click="loadCourses">加载课程列表</n-button>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<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>
|
||||
</form>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NAlert, NButton, NInput, NPagination } from "naive-ui";
|
||||
import { NAlert, NButton, NIcon, NInput, NPagination, NTooltip } from "naive-ui";
|
||||
import { FlashOutline, RefreshOutline } from "@vicons/ionicons5";
|
||||
|
||||
interface ProxyRow {
|
||||
id: number;
|
||||
@@ -38,6 +39,8 @@ const page = ref(1);
|
||||
const pageSize = ref(50);
|
||||
const pageSizes = [20, 50, 100];
|
||||
const fetching = ref(false);
|
||||
const probingId = ref<number | null>(null);
|
||||
const probingAll = ref(false);
|
||||
let poll = 0;
|
||||
|
||||
const kinds = computed<StatusOption[]>(() => [
|
||||
@@ -143,6 +146,53 @@ function stopPoll() {
|
||||
poll = 0;
|
||||
}
|
||||
|
||||
function applyProbed(row: ProxyRow) {
|
||||
items.value = items.value.map((item) => (item.id === row.id ? row : item));
|
||||
}
|
||||
|
||||
async function probeOne(row: ProxyRow) {
|
||||
if (probingId.value != null || probingAll.value || fetching.value) return;
|
||||
probingId.value = row.id;
|
||||
errorText.value = "";
|
||||
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 : "没有测出延迟。";
|
||||
return;
|
||||
}
|
||||
const next = asRow(payload);
|
||||
if (next) applyProbed(next);
|
||||
} catch {
|
||||
errorText.value = "没有测出延迟。";
|
||||
} finally {
|
||||
probingId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function probeAll() {
|
||||
if (probingId.value != null || probingAll.value || fetching.value || !items.value.length) return;
|
||||
probingAll.value = true;
|
||||
errorText.value = "";
|
||||
try {
|
||||
const response = await fetch("/api/admin/proxies/probe", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "没有测出延迟。";
|
||||
return;
|
||||
}
|
||||
await load();
|
||||
} catch {
|
||||
errorText.value = "没有测出延迟。";
|
||||
} finally {
|
||||
probingAll.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshNow() {
|
||||
errorText.value = "";
|
||||
fetching.value = true;
|
||||
@@ -203,7 +253,22 @@ onUnmounted(() => stopPoll());
|
||||
</p>
|
||||
</div>
|
||||
<form class="course-search" @submit.prevent="search">
|
||||
<n-button attr-type="button" :loading="fetching" :disabled="fetching" @click="refreshNow">立即更新</n-button>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button quaternary circle attr-type="button" :loading="fetching" :disabled="fetching || probingAll" aria-label="立即更新" @click="refreshNow">
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</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-input v-model:value="query" placeholder="地址" clearable @clear="search" />
|
||||
<n-button attr-type="submit">搜索</n-button>
|
||||
</form>
|
||||
@@ -238,6 +303,7 @@ onUnmounted(() => stopPoll());
|
||||
<th>延迟</th>
|
||||
<th>状态</th>
|
||||
<th>检测时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -251,6 +317,24 @@ onUnmounted(() => stopPoll());
|
||||
<td class="when">{{ formatLatency(row.latency_ms) }}</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>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NInput, NInputNumber, NRadioButton, NRadioGroup, NSwitch } from "naive-ui";
|
||||
import { NAlert, NButton, NForm, NFormItem, NInput, NInputNumber, NRadioButton, NRadioGroup, NSwitch } from "naive-ui";
|
||||
|
||||
const emit = defineEmits<{ saved: [] }>();
|
||||
|
||||
@@ -160,77 +160,79 @@ async function save() {
|
||||
</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>
|
||||
<div class="admin-scroll">
|
||||
<div class="admin-scroll settings-stack">
|
||||
<p v-if="loading && !loaded" class="admin-status">正在获取</p>
|
||||
<div v-else-if="loaded">
|
||||
<div class="form-row">
|
||||
<label for="refresh-interval">定时刷新间隔</label>
|
||||
<div class="setting-control">
|
||||
<n-input-number id="refresh-interval" v-model:value="refreshInterval" button-placement="both" :min="1" :max="1440" :precision="0" />
|
||||
<span class="setting-unit">分钟</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="show-manual">显示手动滑动验证码</label>
|
||||
<n-switch id="show-manual" v-model:value="showManualJigsaw" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="manual-preference">{{ preferenceLabel }}</label>
|
||||
<n-switch id="manual-preference" v-model:value="manualPreference" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="auto-attempts">自动滑动次数</label>
|
||||
<div class="setting-control">
|
||||
<n-input-number id="auto-attempts" v-model:value="attempts" button-placement="both" :min="1" :max="10" :precision="0" />
|
||||
<span class="setting-unit">次</span>
|
||||
</div>
|
||||
</div>
|
||||
<h3 class="form-section">自动学习心跳间隔</h3>
|
||||
<div class="form-row">
|
||||
<label>间隔来源</label>
|
||||
<n-radio-group v-model:value="hbMode" size="small">
|
||||
<n-radio-button value="auto">自动获取</n-radio-button>
|
||||
<n-radio-button value="manual">手动设定</n-radio-button>
|
||||
</n-radio-group>
|
||||
</div>
|
||||
<template v-if="hbMode === 'manual'">
|
||||
<div class="form-row">
|
||||
<label for="hb-video">视频</label>
|
||||
<div class="setting-control">
|
||||
<n-input-number id="hb-video" v-model:value="hbVideo" button-placement="both" :min="10" :max="300" :precision="0" />
|
||||
<span class="setting-unit">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="hb-document">文档</label>
|
||||
<div class="setting-control">
|
||||
<n-input-number id="hb-document" v-model:value="hbDocument" button-placement="both" :min="30" :max="600" :precision="0" />
|
||||
<span class="setting-unit">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="hb-scorm">Scorm</label>
|
||||
<div class="setting-control">
|
||||
<n-input-number id="hb-scorm" v-model:value="hbScorm" button-placement="both" :min="30" :max="600" :precision="0" />
|
||||
<span class="setting-unit">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<p v-else class="form-hint">自动获取:每次自动学习时从课程播放页在线读取间隔</p>
|
||||
<h3 class="form-section">管理员</h3>
|
||||
<div class="form-row">
|
||||
<label for="admin-username">管理员用户名</label>
|
||||
<n-input id="admin-username" v-model:value="username" autocomplete="username" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-password">新密码</label>
|
||||
<n-input id="admin-password" v-model:value="password" type="password" show-password-on="click" autocomplete="new-password" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-password-again">再输入一次</label>
|
||||
<n-input id="admin-password-again" v-model:value="confirmPassword" type="password" show-password-on="click" autocomplete="new-password" />
|
||||
</div>
|
||||
</div>
|
||||
<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-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" />
|
||||
<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-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" />
|
||||
<span class="target-unit">次</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
</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="hbMode" size="small">
|
||||
<n-radio-button value="auto">自动获取</n-radio-button>
|
||||
<n-radio-button value="manual">手动设定</n-radio-button>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
<p v-if="hbMode === 'auto'" class="form-hint">每次自动学习时从课程播放页读取间隔</p>
|
||||
<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="10" :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="30" :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="30" :max="600" :precision="0" />
|
||||
<span class="target-unit">秒</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
</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-input v-model:value="username" autocomplete="username" />
|
||||
</n-form-item>
|
||||
<n-form-item label="新密码">
|
||||
<n-input v-model:value="password" type="password" show-password-on="click" placeholder="请输入" autocomplete="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-form-item>
|
||||
</n-form>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NCheckbox, NDropdown, NIcon, NInput, NInputNumber, NModal, NSelect, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
||||
import { HelpCircleOutline, SettingsOutline } from "@vicons/ionicons5";
|
||||
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";
|
||||
|
||||
interface UserRow {
|
||||
employee_id: string;
|
||||
@@ -10,6 +10,7 @@ interface UserRow {
|
||||
last_refresh_at: string | null;
|
||||
credential_valid: boolean | null;
|
||||
month_hours: string;
|
||||
monthly_target: number;
|
||||
has_proxy: boolean;
|
||||
proxy: string;
|
||||
study_start: string;
|
||||
@@ -18,6 +19,9 @@ interface UserRow {
|
||||
study_start_minute: number;
|
||||
study_start_second: number;
|
||||
course_workers: number;
|
||||
study_paused: boolean;
|
||||
study_ignore_window: boolean;
|
||||
study_started: boolean;
|
||||
}
|
||||
|
||||
interface SecretField {
|
||||
@@ -32,6 +36,7 @@ const users = ref<UserRow[]>([]);
|
||||
const liveResults = ref<Record<string, string>>({});
|
||||
const checkingId = ref("");
|
||||
const checkingAll = ref(false);
|
||||
const studyBusy = ref(false);
|
||||
const credentialOpen = ref(false);
|
||||
const credentialTitle = ref("凭据");
|
||||
const credentialLoading = ref(false);
|
||||
@@ -39,10 +44,16 @@ const credentialError = ref("");
|
||||
const credentialNote = ref("");
|
||||
const credentialFields = ref<SecretField[]>([]);
|
||||
const picked = ref<Record<string, boolean>>({});
|
||||
const proxyOpen = ref(false);
|
||||
const proxySaving = ref(false);
|
||||
const proxyError = ref("");
|
||||
const proxyIds = ref<string[]>([]);
|
||||
const settingsOpen = ref(false);
|
||||
const settingsSaving = ref(false);
|
||||
const settingsError = ref("");
|
||||
const settingsIds = ref<string[]>([]);
|
||||
const monthlyTarget = ref<number | null>(600);
|
||||
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 workersValue = ref<number | null>(1);
|
||||
const proxyScheme = ref("off");
|
||||
const proxyHost = ref("");
|
||||
const proxyPort = ref<number | null>(null);
|
||||
@@ -58,23 +69,14 @@ const proxyOptions = [
|
||||
{ label: "SOCKS4", value: "socks4" },
|
||||
{ label: "SOCKS5", value: "socks5" },
|
||||
];
|
||||
const startOpen = ref(false);
|
||||
const startSaving = ref(false);
|
||||
const startError = ref("");
|
||||
const startIds = ref<string[]>([]);
|
||||
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 workersOpen = ref(false);
|
||||
const workersSaving = ref(false);
|
||||
const workersError = ref("");
|
||||
const workersIds = ref<string[]>([]);
|
||||
const workersValue = ref<number | null>(1);
|
||||
|
||||
const pickedIds = computed(() => users.value.filter((row) => picked.value[row.employee_id]).map((row) => row.employee_id));
|
||||
const allPicked = computed(() => users.value.length > 0 && pickedIds.value.length === users.value.length);
|
||||
const somePicked = computed(() => pickedIds.value.length > 0 && !allPicked.value);
|
||||
const moreOptions = computed<DropdownOption[]>(() => [
|
||||
{ label: "检查全部", key: "check-all", disabled: checkingAll.value || checkingId.value !== "" || !users.value.length },
|
||||
{ label: "清除代理", key: "clear-proxy", disabled: !pickedIds.value.length },
|
||||
]);
|
||||
|
||||
const tokenFields: { label: string; key: string }[] = [
|
||||
{ label: "统一认证 token", key: "ucs_token" },
|
||||
@@ -85,6 +87,24 @@ const tokenFields: { label: string; key: string }[] = [
|
||||
{ label: "学习平台 token", key: "yxt_token" },
|
||||
];
|
||||
|
||||
function pad(value: number) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
|
||||
const startTime = computed({
|
||||
get() {
|
||||
return `${pad(startHour.value ?? 0)}:${pad(startMinute.value ?? 0)}:${pad(startSecond.value ?? 0)}`;
|
||||
},
|
||||
set(value: string | null) {
|
||||
if (!value) return;
|
||||
const [hour, minute, second] = value.split(":").map((part) => Number(part));
|
||||
if (![hour, minute, second].every((part) => Number.isInteger(part))) return;
|
||||
startHour.value = hour;
|
||||
startMinute.value = minute;
|
||||
startSecond.value = second;
|
||||
},
|
||||
});
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return !!value && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
@@ -113,6 +133,7 @@ function asUser(value: unknown): UserRow | null {
|
||||
last_refresh_at: typeof value.last_refresh_at === "string" && value.last_refresh_at ? value.last_refresh_at : null,
|
||||
credential_valid: readValid(value.credential_valid),
|
||||
month_hours: textOf(value.month_hours),
|
||||
monthly_target: typeof value.monthly_target === "number" ? value.monthly_target : 600,
|
||||
has_proxy: value.has_proxy === true,
|
||||
proxy: textOf(value.proxy),
|
||||
study_start: textOf(value.study_start),
|
||||
@@ -121,6 +142,9 @@ function asUser(value: unknown): UserRow | null {
|
||||
study_start_minute: typeof value.study_start_minute === "number" ? value.study_start_minute : 0,
|
||||
study_start_second: typeof value.study_start_second === "number" ? value.study_start_second : 0,
|
||||
course_workers: typeof value.course_workers === "number" ? value.course_workers : 1,
|
||||
study_paused: value.study_paused === true,
|
||||
study_ignore_window: value.study_ignore_window === true,
|
||||
study_started: value.study_started === true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -128,8 +152,8 @@ function formatRefreshTime(value: string | null) {
|
||||
if (!value) return "";
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value;
|
||||
const pad = (part: number) => String(part).padStart(2, "0");
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
||||
const padPart = (part: number) => String(part).padStart(2, "0");
|
||||
return `${date.getFullYear()}-${padPart(date.getMonth() + 1)}-${padPart(date.getDate())} ${padPart(date.getHours())}:${padPart(date.getMinutes())}:${padPart(date.getSeconds())}`;
|
||||
}
|
||||
|
||||
function checkLabel(payload: Record<string, unknown>) {
|
||||
@@ -154,6 +178,12 @@ 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 {
|
||||
@@ -351,22 +381,39 @@ function toggleAll(checked: boolean) {
|
||||
picked.value = next;
|
||||
}
|
||||
|
||||
function resetProxyForm() {
|
||||
function resetSettingsForm() {
|
||||
monthlyTarget.value = 600;
|
||||
startDay.value = 1;
|
||||
startHour.value = 0;
|
||||
startMinute.value = 0;
|
||||
startSecond.value = 0;
|
||||
workersValue.value = 1;
|
||||
proxyScheme.value = "off";
|
||||
proxyHost.value = "";
|
||||
proxyPort.value = null;
|
||||
proxyUser.value = "";
|
||||
proxyPassword.value = "";
|
||||
proxyHasPassword.value = false;
|
||||
proxyError.value = "";
|
||||
settingsError.value = "";
|
||||
}
|
||||
|
||||
async function openProxy(ids: string[]) {
|
||||
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;
|
||||
workersValue.value = row.course_workers;
|
||||
}
|
||||
|
||||
async function openSettings(ids: string[]) {
|
||||
if (!ids.length) return;
|
||||
proxyIds.value = ids;
|
||||
resetProxyForm();
|
||||
proxyOpen.value = true;
|
||||
settingsIds.value = ids;
|
||||
resetSettingsForm();
|
||||
settingsOpen.value = true;
|
||||
if (ids.length !== 1) 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(() => ({}));
|
||||
@@ -382,52 +429,93 @@ async function openProxy(ids: string[]) {
|
||||
function proxyPasswordPayload() {
|
||||
if (proxyPassword.value !== "") return proxyPassword.value;
|
||||
if (!proxyUser.value.trim()) return "";
|
||||
if (proxyIds.value.length === 1 && proxyHasPassword.value) return null;
|
||||
if (settingsIds.value.length === 1 && proxyHasPassword.value) return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
async function saveProxy() {
|
||||
if (proxySaving.value || !proxyIds.value.length) return;
|
||||
proxyError.value = "";
|
||||
async function saveSettings() {
|
||||
if (settingsSaving.value || !settingsIds.value.length) return;
|
||||
settingsError.value = "";
|
||||
if (monthlyTarget.value == null || !Number.isInteger(monthlyTarget.value) || monthlyTarget.value < 0 || monthlyTarget.value > 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)
|
||||
) {
|
||||
settingsError.value = "请填写完整的开始时刻";
|
||||
return;
|
||||
}
|
||||
if (workersValue.value == null || !Number.isInteger(workersValue.value) || workersValue.value < 1 || workersValue.value > 8) {
|
||||
settingsError.value = "同时学习课程数须为 1 到 8";
|
||||
return;
|
||||
}
|
||||
if (proxyManual.value) {
|
||||
if (!proxyHost.value.trim()) {
|
||||
proxyError.value = "请填写代理地址";
|
||||
settingsError.value = "请填写代理地址";
|
||||
return;
|
||||
}
|
||||
if (proxyPort.value == null || !Number.isInteger(proxyPort.value)) {
|
||||
proxyError.value = "请填写代理端口";
|
||||
settingsError.value = "请填写代理端口";
|
||||
return;
|
||||
}
|
||||
}
|
||||
proxySaving.value = true;
|
||||
settingsSaving.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/admin/users/proxy", {
|
||||
const response = await fetch("/api/admin/users/study-settings", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(
|
||||
proxyManual.value
|
||||
? {
|
||||
employee_ids: proxyIds.value,
|
||||
scheme: proxyScheme.value,
|
||||
host: proxyHost.value.trim(),
|
||||
port: proxyPort.value,
|
||||
username: proxyUser.value.trim(),
|
||||
password: proxyPasswordPayload(),
|
||||
}
|
||||
: { employee_ids: proxyIds.value, scheme: proxyScheme.value },
|
||||
),
|
||||
body: JSON.stringify({
|
||||
employee_ids: settingsIds.value,
|
||||
monthly_target: monthlyTarget.value,
|
||||
day: startDay.value,
|
||||
hour: startHour.value,
|
||||
minute: startMinute.value,
|
||||
second: startSecond.value,
|
||||
workers: workersValue.value,
|
||||
scheme: proxyScheme.value,
|
||||
host: proxyHost.value.trim(),
|
||||
port: proxyPort.value,
|
||||
username: proxyUser.value.trim(),
|
||||
password: proxyManual.value ? proxyPasswordPayload() : "",
|
||||
}),
|
||||
});
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
proxyError.value = detailOf(payload, "没有保存。");
|
||||
settingsError.value = detailOf(payload, "没有保存。");
|
||||
return;
|
||||
}
|
||||
proxyOpen.value = false;
|
||||
settingsOpen.value = false;
|
||||
await load();
|
||||
} catch {
|
||||
proxyError.value = "没有保存。";
|
||||
settingsError.value = "没有保存。";
|
||||
} finally {
|
||||
proxySaving.value = false;
|
||||
settingsSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function setStudy(ids: string[], action: "start" | "stop") {
|
||||
if (!ids.length || studyBusy.value) return;
|
||||
studyBusy.value = true;
|
||||
errorText.value = "";
|
||||
try {
|
||||
const response = await fetch("/api/admin/users/study", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ employee_ids: ids, action }),
|
||||
});
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
errorText.value = detailOf(payload, action === "start" ? "没有开始。" : "没有停止。");
|
||||
return;
|
||||
}
|
||||
await load();
|
||||
} catch {
|
||||
errorText.value = action === "start" ? "没有开始。" : "没有停止。";
|
||||
} finally {
|
||||
studyBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,133 +550,28 @@ function confirmClearProxy(ids: string[]) {
|
||||
});
|
||||
}
|
||||
|
||||
function resetStartForm() {
|
||||
startDay.value = 1;
|
||||
startHour.value = 0;
|
||||
startMinute.value = 0;
|
||||
startSecond.value = 0;
|
||||
startError.value = "";
|
||||
}
|
||||
|
||||
function openStart(ids: string[]) {
|
||||
if (!ids.length) return;
|
||||
startIds.value = ids;
|
||||
resetStartForm();
|
||||
if (ids.length === 1) {
|
||||
const row = users.value.find((item) => item.employee_id === ids[0]);
|
||||
if (row) {
|
||||
startDay.value = row.study_start_day;
|
||||
startHour.value = row.study_start_hour;
|
||||
startMinute.value = row.study_start_minute;
|
||||
startSecond.value = row.study_start_second;
|
||||
}
|
||||
}
|
||||
startOpen.value = true;
|
||||
}
|
||||
|
||||
async function saveStart() {
|
||||
if (startSaving.value || !startIds.value.length) return;
|
||||
startError.value = "";
|
||||
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)
|
||||
) {
|
||||
startError.value = "请填写完整的开始时刻";
|
||||
return;
|
||||
}
|
||||
startSaving.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/admin/users/study-start", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
employee_ids: startIds.value,
|
||||
day: startDay.value,
|
||||
hour: startHour.value,
|
||||
minute: startMinute.value,
|
||||
second: startSecond.value,
|
||||
}),
|
||||
});
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
startError.value = detailOf(payload, "没有保存。");
|
||||
return;
|
||||
}
|
||||
startOpen.value = false;
|
||||
await load();
|
||||
} catch {
|
||||
startError.value = "没有保存。";
|
||||
} finally {
|
||||
startSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openWorkers(ids: string[]) {
|
||||
if (!ids.length) return;
|
||||
workersIds.value = ids;
|
||||
workersError.value = "";
|
||||
workersValue.value = 1;
|
||||
if (ids.length === 1) {
|
||||
const row = users.value.find((item) => item.employee_id === ids[0]);
|
||||
if (row) workersValue.value = row.course_workers;
|
||||
}
|
||||
workersOpen.value = true;
|
||||
}
|
||||
|
||||
async function saveWorkers() {
|
||||
if (workersSaving.value || !workersIds.value.length) return;
|
||||
workersError.value = "";
|
||||
if (workersValue.value == null || !Number.isInteger(workersValue.value) || workersValue.value < 1 || workersValue.value > 8) {
|
||||
workersError.value = "同时学习课程数须为 1 到 8";
|
||||
return;
|
||||
}
|
||||
workersSaving.value = true;
|
||||
try {
|
||||
const response = await fetch("/api/admin/users/course-workers", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
employee_ids: workersIds.value,
|
||||
workers: workersValue.value,
|
||||
}),
|
||||
});
|
||||
const payload: unknown = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
workersError.value = detailOf(payload, "没有保存。");
|
||||
return;
|
||||
}
|
||||
workersOpen.value = false;
|
||||
await load();
|
||||
} catch {
|
||||
workersError.value = "没有保存。";
|
||||
} finally {
|
||||
workersSaving.value = false;
|
||||
}
|
||||
function onMore(key: string | number) {
|
||||
if (key === "check-all") void checkAll();
|
||||
else if (key === "clear-proxy") confirmClearProxy(pickedIds.value);
|
||||
}
|
||||
|
||||
function rowActions(row: UserRow): DropdownOption[] {
|
||||
const busy = checkingAll.value || checkingId.value !== "";
|
||||
const busy = checkingAll.value || checkingId.value !== "" || studyBusy.value;
|
||||
return [
|
||||
{ label: "学习设置", key: "settings" },
|
||||
{ label: row.study_started ? "停止任务" : "立即开始", key: "study", disabled: busy },
|
||||
{ label: "检查", key: "check", disabled: busy },
|
||||
{ label: "查看凭据", key: "credentials" },
|
||||
{ label: "设置代理", key: "proxy" },
|
||||
{ label: "清除代理", key: "proxy-clear" },
|
||||
{ label: "开始时刻", key: "start" },
|
||||
{ label: "同时课程", key: "workers" },
|
||||
{ label: row.refresh_paused ? "恢复自动刷新" : "停止自动刷新", key: "refresh" },
|
||||
{ label: "删除", key: "delete", props: { style: { color: "var(--danger)" } } },
|
||||
];
|
||||
}
|
||||
|
||||
function onRowAction(row: UserRow, key: string | number) {
|
||||
if (key === "check") void checkOne(row);
|
||||
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 === "check") void checkOne(row);
|
||||
else if (key === "credentials") void openCredentials(row);
|
||||
else if (key === "proxy") void openProxy([row.employee_id]);
|
||||
else if (key === "proxy-clear") confirmClearProxy([row.employee_id]);
|
||||
else if (key === "start") openStart([row.employee_id]);
|
||||
else if (key === "workers") openWorkers([row.employee_id]);
|
||||
else if (key === "refresh") confirmRefresh(row);
|
||||
else if (key === "delete") confirmDelete(row);
|
||||
}
|
||||
@@ -603,11 +586,40 @@ onMounted(() => {
|
||||
<header class="page-head">
|
||||
<h2>用户管理</h2>
|
||||
<div class="page-head-actions">
|
||||
<n-button :disabled="!pickedIds.length" @click="openProxy(pickedIds)">设置代理</n-button>
|
||||
<n-button :disabled="!pickedIds.length" @click="confirmClearProxy(pickedIds)">清除代理</n-button>
|
||||
<n-button :disabled="!pickedIds.length" @click="openStart(pickedIds)">开始时刻</n-button>
|
||||
<n-button :disabled="!pickedIds.length" @click="openWorkers(pickedIds)">同时课程</n-button>
|
||||
<n-button :loading="checkingAll" :disabled="checkingAll || checkingId !== '' || !users.length" @click="checkAll">检查全部</n-button>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button quaternary circle :disabled="!pickedIds.length" aria-label="学习设置" @click="openSettings(pickedIds)">
|
||||
<template #icon><n-icon><SettingsOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
学习设置
|
||||
</n-tooltip>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button quaternary circle :disabled="!pickedIds.length" :loading="studyBusy" aria-label="立即开始" @click="setStudy(pickedIds, 'start')">
|
||||
<template #icon><n-icon><PlayOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
立即开始
|
||||
</n-tooltip>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button quaternary circle :disabled="!pickedIds.length" :loading="studyBusy" aria-label="停止任务" @click="setStudy(pickedIds, 'stop')">
|
||||
<template #icon><n-icon><PauseOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
停止任务
|
||||
</n-tooltip>
|
||||
<n-dropdown trigger="click" placement="bottom-end" :options="moreOptions" @select="onMore">
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button quaternary circle aria-label="更多">
|
||||
<template #icon><n-icon><EllipsisHorizontalOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
更多
|
||||
</n-tooltip>
|
||||
</n-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
<n-alert v-if="errorText" class="admin-alert" type="error">{{ errorText }}</n-alert>
|
||||
@@ -621,10 +633,9 @@ onMounted(() => {
|
||||
</th>
|
||||
<th>工号</th>
|
||||
<th>凭证</th>
|
||||
<th>凭据是否有效</th>
|
||||
<th>有效</th>
|
||||
<th>本月学时</th>
|
||||
<th>开始时刻</th>
|
||||
<th>同时课程</th>
|
||||
<th>任务</th>
|
||||
<th>代理</th>
|
||||
<th>上次刷新时间</th>
|
||||
<th>自动刷新</th>
|
||||
@@ -640,16 +651,20 @@ onMounted(() => {
|
||||
<td>{{ row.has_credential ? "已保存凭证" : "未保存凭证" }}</td>
|
||||
<td :class="validityClass(validityText(row))">{{ validityText(row) }}</td>
|
||||
<td class="when">{{ row.month_hours || "—" }}</td>
|
||||
<td class="when">{{ row.study_start || "—" }}</td>
|
||||
<td class="when">{{ row.course_workers }}{{ row.course_workers === 1 ? "(推荐)" : "" }}</td>
|
||||
<td :class="row.study_started ? '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>
|
||||
<td>
|
||||
<n-dropdown trigger="click" placement="bottom-end" :options="rowActions(row)" @select="(key) => onRowAction(row, key)">
|
||||
<n-button size="small" quaternary circle :aria-label="`工号 ${row.employee_id} 的操作`">
|
||||
<template #icon><n-icon><SettingsOutline /></n-icon></template>
|
||||
</n-button>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button size="small" quaternary circle :aria-label="`工号 ${row.employee_id} 的操作`">
|
||||
<template #icon><n-icon><EllipsisVerticalOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
操作
|
||||
</n-tooltip>
|
||||
</n-dropdown>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -681,112 +696,75 @@ onMounted(() => {
|
||||
</template>
|
||||
</n-modal>
|
||||
<n-modal
|
||||
:show="proxyOpen"
|
||||
:show="settingsOpen"
|
||||
preset="card"
|
||||
:title="proxyIds.length === 1 ? `工号 ${proxyIds[0]} 的代理` : `已选 ${proxyIds.length} 个账号的代理`"
|
||||
:title="settingsIds.length === 1 ? `工号 ${settingsIds[0]} 的学习设置` : `已选 ${settingsIds.length} 个账号的学习设置`"
|
||||
:style="{ width: 'min(520px, calc(100vw - 32px))' }"
|
||||
@update:show="(show) => (proxyOpen = show)"
|
||||
:content-style="{ maxHeight: 'min(70vh, 560px)', overflow: 'auto' }"
|
||||
@update:show="(show) => (settingsOpen = show)"
|
||||
>
|
||||
<n-alert v-if="proxyError" class="admin-alert" type="error">{{ proxyError }}</n-alert>
|
||||
<form class="settings-form" @submit.prevent="saveProxy">
|
||||
<div class="form-row">
|
||||
<label for="admin-proxy-scheme">类型</label>
|
||||
<n-select id="admin-proxy-scheme" v-model:value="proxyScheme" :options="proxyOptions" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-proxy-host">地址</label>
|
||||
<n-input id="admin-proxy-host" v-model:value="proxyHost" placeholder="例如 127.0.0.1" :disabled="!proxyManual" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-proxy-port">端口</label>
|
||||
<n-input-number id="admin-proxy-port" v-model:value="proxyPort" button-placement="both" :min="1" :max="65535" :precision="0" :disabled="!proxyManual" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-proxy-user">账号</label>
|
||||
<n-input id="admin-proxy-user" v-model:value="proxyUser" placeholder="可不填" autocomplete="off" :disabled="!proxyManual" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-proxy-password">密码</label>
|
||||
<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-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="每月开始">
|
||||
<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-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>
|
||||
<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
|
||||
id="admin-proxy-password"
|
||||
v-model:value="proxyPassword"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="proxyIds.length === 1 && proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
:placeholder="settingsIds.length === 1 && proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
autocomplete="new-password"
|
||||
:disabled="!proxyManual"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</n-form-item>
|
||||
</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>
|
||||
<n-modal
|
||||
:show="startOpen"
|
||||
preset="card"
|
||||
:title="startIds.length === 1 ? `工号 ${startIds[0]} 的开始时刻` : `已选 ${startIds.length} 个账号的开始时刻`"
|
||||
:style="{ width: 'min(520px, calc(100vw - 32px))' }"
|
||||
@update:show="(show) => (startOpen = show)"
|
||||
>
|
||||
<n-alert v-if="startError" class="admin-alert" type="error">{{ startError }}</n-alert>
|
||||
<form class="settings-form" @submit.prevent="saveStart">
|
||||
<div class="form-row">
|
||||
<label for="admin-start-day">每月</label>
|
||||
<n-input-number id="admin-start-day" v-model:value="startDay" button-placement="both" :min="1" :max="31" :precision="0" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-start-hour">时</label>
|
||||
<n-input-number id="admin-start-hour" v-model:value="startHour" button-placement="both" :min="0" :max="23" :precision="0" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-start-minute">分</label>
|
||||
<n-input-number id="admin-start-minute" v-model:value="startMinute" button-placement="both" :min="0" :max="59" :precision="0" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="admin-start-second">秒</label>
|
||||
<n-input-number id="admin-start-second" v-model:value="startSecond" button-placement="both" :min="0" :max="59" :precision="0" />
|
||||
</div>
|
||||
</form>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
<n-button @click="startOpen = false">取消</n-button>
|
||||
<n-button type="primary" :loading="startSaving" @click="saveStart">保存</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
<n-modal
|
||||
:show="workersOpen"
|
||||
preset="card"
|
||||
:title="workersIds.length === 1 ? `工号 ${workersIds[0]} 的同时课程` : `已选 ${workersIds.length} 个账号的同时课程`"
|
||||
:style="{ width: 'min(520px, calc(100vw - 32px))' }"
|
||||
@update:show="(show) => (workersOpen = show)"
|
||||
>
|
||||
<n-alert v-if="workersError" class="admin-alert" type="error">{{ workersError }}</n-alert>
|
||||
<form class="settings-form" @submit.prevent="saveWorkers">
|
||||
<div class="form-row">
|
||||
<label class="field-title" for="admin-course-workers">
|
||||
<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>
|
||||
</label>
|
||||
<n-input-number id="admin-course-workers" v-model:value="workersValue" button-placement="both" :min="1" :max="8" :precision="0" />
|
||||
</div>
|
||||
<p v-if="workersValue === 1" class="form-hint">1 门为推荐</p>
|
||||
</form>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
<n-button @click="workersOpen = false">取消</n-button>
|
||||
<n-button type="primary" :loading="workersSaving" @click="saveWorkers">保存</n-button>
|
||||
<n-button @click="settingsOpen = false">取消</n-button>
|
||||
<n-button type="primary" :loading="settingsSaving" @click="saveSettings">保存</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
@@ -120,29 +120,29 @@ onMounted(refresh);
|
||||
|
||||
<template>
|
||||
<section class="page list-page">
|
||||
<header class="page-head">
|
||||
<h2 id="exam-heading">我的考试</h2>
|
||||
<span class="board-tools">
|
||||
<span v-if="state === 'loading'" class="spin" role="status" aria-label="正在获取"></span>
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
<n-button
|
||||
class="home-refresh"
|
||||
quaternary
|
||||
circle
|
||||
size="small"
|
||||
aria-label="刷新"
|
||||
:loading="refreshing"
|
||||
@click="refresh"
|
||||
>
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
刷新
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</header>
|
||||
<section class="board" aria-labelledby="exam-heading" :aria-busy="state === 'loading'">
|
||||
<h3>
|
||||
<span id="exam-heading">我的考试</span>
|
||||
<span class="board-tools">
|
||||
<span v-if="state === 'loading'" class="spin" role="status" aria-label="正在获取"></span>
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
<n-button
|
||||
class="home-refresh"
|
||||
quaternary
|
||||
circle
|
||||
size="small"
|
||||
aria-label="刷新数据"
|
||||
:loading="refreshing"
|
||||
@click="refresh"
|
||||
>
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
刷新数据
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</h3>
|
||||
<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>
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NDataTable, NIcon, NPagination, NTooltip, type DataTableColumns } from "naive-ui";
|
||||
import { RefreshOutline } from "@vicons/ionicons5";
|
||||
|
||||
interface HistoryItem {
|
||||
title: string;
|
||||
minutes: number | null;
|
||||
studied_at: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
type SectionState = "loading" | "ready" | "error";
|
||||
|
||||
const items = ref<HistoryItem[] | null>(null);
|
||||
const state = ref<SectionState>("loading");
|
||||
const errorText = ref("");
|
||||
const refreshing = ref(false);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(20);
|
||||
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>;
|
||||
const title = typeof row.title === "string" ? row.title : "";
|
||||
const studied = typeof row.studied_at === "string" ? row.studied_at : "";
|
||||
if (!title && !studied) return null;
|
||||
return {
|
||||
title,
|
||||
minutes: typeof row.minutes === "number" ? row.minutes : null,
|
||||
studied_at: studied,
|
||||
path: typeof row.path === "string" ? row.path : "",
|
||||
};
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
const hadData = items.value !== null;
|
||||
if (!hadData) state.value = "loading";
|
||||
try {
|
||||
const response = await fetch("/api/home/history");
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
if (!hadData) {
|
||||
errorText.value = failureText(payload, "学时历史没有获取到。");
|
||||
state.value = "error";
|
||||
}
|
||||
return;
|
||||
}
|
||||
const rows: unknown[] = Array.isArray(payload.items) ? payload.items : [];
|
||||
const parsed: HistoryItem[] = [];
|
||||
for (const row of rows) {
|
||||
const item = asItem(row);
|
||||
if (item) parsed.push(item);
|
||||
}
|
||||
items.value = parsed;
|
||||
errorText.value = "";
|
||||
state.value = "ready";
|
||||
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";
|
||||
}
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
if (refreshRunning) return;
|
||||
refreshRunning = true;
|
||||
refreshing.value = true;
|
||||
void load().finally(() => {
|
||||
refreshRunning = false;
|
||||
refreshing.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
const paged = computed(() => {
|
||||
const rows = items.value ?? [];
|
||||
const start = (page.value - 1) * pageSize.value;
|
||||
return rows.slice(start, start + pageSize.value);
|
||||
});
|
||||
|
||||
const columns: DataTableColumns<HistoryItem> = [
|
||||
{
|
||||
title: "来源",
|
||||
key: "title",
|
||||
ellipsis: { tooltip: true },
|
||||
render(row) {
|
||||
return h("span", { class: "history-title", title: row.title }, row.title || "—");
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "获得学时(分钟)",
|
||||
key: "minutes",
|
||||
width: 160,
|
||||
align: "right",
|
||||
render(row) {
|
||||
return row.minutes == null ? "—" : String(row.minutes);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "日期",
|
||||
key: "studied_at",
|
||||
width: 180,
|
||||
render(row) {
|
||||
return row.studied_at || "—";
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
function goPage(next: number) {
|
||||
page.value = next;
|
||||
}
|
||||
|
||||
function changeSize(size: number) {
|
||||
pageSize.value = size;
|
||||
page.value = 1;
|
||||
}
|
||||
|
||||
onMounted(refresh);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page list-page history-page">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<h2>学时历史</h2>
|
||||
<p v-if="items">共 {{ items.length }} 条</p>
|
||||
</div>
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
<n-button
|
||||
class="home-refresh"
|
||||
quaternary
|
||||
circle
|
||||
size="small"
|
||||
aria-label="刷新"
|
||||
:loading="refreshing"
|
||||
@click="refresh"
|
||||
>
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
刷新
|
||||
</n-tooltip>
|
||||
</header>
|
||||
<n-alert v-if="state === 'error'" class="admin-alert" type="error">{{ errorText }}</n-alert>
|
||||
<div class="history-table">
|
||||
<n-data-table
|
||||
v-if="state !== 'error'"
|
||||
:columns="columns"
|
||||
:data="state === 'loading' ? [] : paged"
|
||||
:loading="state === '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>
|
||||
</div>
|
||||
<n-pagination
|
||||
v-if="items && items.length"
|
||||
class="course-pager"
|
||||
:page="page"
|
||||
:page-size="pageSize"
|
||||
:item-count="items.length"
|
||||
:page-sizes="pageSizes"
|
||||
show-size-picker
|
||||
show-quick-jumper
|
||||
@update:page="goPage"
|
||||
@update:page-size="changeSize"
|
||||
>
|
||||
<template #prefix="{ itemCount }">共 {{ itemCount }} 条</template>
|
||||
</n-pagination>
|
||||
</section>
|
||||
</template>
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { NAlert, NButton, NIcon, NInput, NInputNumber, NSelect, NTooltip } from "naive-ui";
|
||||
import { HelpCircleOutline, RefreshOutline } from "@vicons/ionicons5";
|
||||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInput, NInputNumber, NSelect, NTimePicker, NTooltip } from "naive-ui";
|
||||
import { HelpCircleOutline, PlayOutline, RefreshOutline, StopOutline } from "@vicons/ionicons5";
|
||||
|
||||
interface HomeSummary {
|
||||
name: string;
|
||||
@@ -41,12 +41,39 @@ const studyStatus = ref<{
|
||||
message: string;
|
||||
} | null>(null);
|
||||
|
||||
const studyControl = ref({
|
||||
started: false,
|
||||
paused: false,
|
||||
ignore_window: false,
|
||||
window_open: false,
|
||||
active: false,
|
||||
state: "",
|
||||
course: "",
|
||||
});
|
||||
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;
|
||||
if (state === "已达标") return "本月目标已达到";
|
||||
if (state === "已停止" || studyControl.value.paused) return "任务已停止";
|
||||
if (studyControl.value.active || live) {
|
||||
return `正在学习:${course || state || "准备中"}`;
|
||||
}
|
||||
if (studyControl.value.started) return "任务已开始,等待执行";
|
||||
if (studyStatus.value?.message) return studyStatus.value.message;
|
||||
if (studyStatus.value?.running) return "自动学习进行中";
|
||||
return "未到开始时间";
|
||||
});
|
||||
|
||||
function amount(value: string | number | null | undefined) {
|
||||
if (value === null || value === undefined || value === "") return "—";
|
||||
const numeric = Number(value);
|
||||
@@ -71,6 +98,10 @@ function failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
return typeof payload.detail === "string" ? payload.detail : fallback;
|
||||
}
|
||||
|
||||
function pad(value: number) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
|
||||
async function loadSummary() {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
@@ -103,7 +134,7 @@ function refresh() {
|
||||
if (refreshRunning) return;
|
||||
refreshRunning = true;
|
||||
refreshing.value = true;
|
||||
void loadSummary().finally(() => {
|
||||
void Promise.all([loadSummary(), loadStudyStatus(), loadStudyControl()]).finally(() => {
|
||||
refreshRunning = false;
|
||||
refreshing.value = false;
|
||||
});
|
||||
@@ -143,6 +174,20 @@ const startMinute = ref<number | null>(0);
|
||||
const startSecond = ref<number | null>(0);
|
||||
let startSaveTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const startTime = computed({
|
||||
get() {
|
||||
return `${pad(startHour.value ?? 0)}:${pad(startMinute.value ?? 0)}:${pad(startSecond.value ?? 0)}`;
|
||||
},
|
||||
set(value: string | null) {
|
||||
if (!value) return;
|
||||
const [hour, minute, second] = value.split(":").map((part) => Number(part));
|
||||
if (![hour, minute, second].every((part) => Number.isInteger(part))) return;
|
||||
startHour.value = hour;
|
||||
startMinute.value = minute;
|
||||
startSecond.value = second;
|
||||
},
|
||||
});
|
||||
|
||||
async function loadStart() {
|
||||
try {
|
||||
const res = await fetch("/api/settings/study-start");
|
||||
@@ -308,13 +353,64 @@ async function loadStudyStatus() {
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
onMounted(() => { refresh(); loadTarget(); loadStart(); loadWorkers(); loadProxy(); loadStudyStatus(); });
|
||||
function applyStudyControl(payload: Record<string, unknown>) {
|
||||
studyControl.value = {
|
||||
started: payload.started === true,
|
||||
paused: payload.paused === true,
|
||||
ignore_window: payload.ignore_window === true,
|
||||
window_open: payload.window_open === true,
|
||||
active: payload.active === true,
|
||||
state: typeof payload.state === "string" ? payload.state : "",
|
||||
course: typeof payload.course === "string" ? payload.course : "",
|
||||
};
|
||||
}
|
||||
|
||||
async function loadStudyControl() {
|
||||
try {
|
||||
const res = await fetch("/api/settings/study-control");
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (res.ok) applyStudyControl(data);
|
||||
} catch { /* 静默 */ }
|
||||
}
|
||||
|
||||
async function toggleStudy() {
|
||||
if (studyBusy.value) return;
|
||||
studyBusy.value = true;
|
||||
studyError.value = "";
|
||||
const action = studyControl.value.started ? "stop" : "start";
|
||||
try {
|
||||
const res = await fetch("/api/settings/study-control", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ action }),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
studyError.value = failureText(data, action === "start" ? "没有开始。" : "没有停止。");
|
||||
return;
|
||||
}
|
||||
applyStudyControl(data);
|
||||
await loadStudyStatus();
|
||||
} catch {
|
||||
studyError.value = action === "start" ? "没有开始。" : "没有停止。";
|
||||
} finally {
|
||||
studyBusy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
refresh();
|
||||
loadTarget();
|
||||
loadStart();
|
||||
loadWorkers();
|
||||
loadProxy();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page home-page">
|
||||
<div class="home">
|
||||
<div class="home-summary" :aria-busy="summaryState === 'loading'">
|
||||
<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>
|
||||
@@ -363,104 +459,113 @@ onMounted(() => { refresh(); loadTarget(); loadStart(); loadWorkers(); loadProxy
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
<div v-if="targetLoaded" class="home-target">
|
||||
<label for="monthly-target">每月自动学习目标</label>
|
||||
<div class="target-control">
|
||||
<n-input-number
|
||||
id="monthly-target"
|
||||
v-model:value="monthlyTarget"
|
||||
button-placement="both"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
:precision="0"
|
||||
</section>
|
||||
|
||||
<section class="panel-card">
|
||||
<header class="panel-card-head">
|
||||
<h3>自动学习</h3>
|
||||
<n-button
|
||||
:type="studyControl.started ? 'error' : 'primary'"
|
||||
size="small"
|
||||
/>
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="startLoaded" class="home-target home-start">
|
||||
<label for="study-start-day">每月开始学习</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-input-number v-model:value="startHour" button-placement="both" :min="0" :max="23" :precision="0" size="small" />
|
||||
<span class="target-unit">:</span>
|
||||
<n-input-number v-model:value="startMinute" button-placement="both" :min="0" :max="59" :precision="0" size="small" />
|
||||
<span class="target-unit">:</span>
|
||||
<n-input-number v-model:value="startSecond" button-placement="both" :min="0" :max="59" :precision="0" size="small" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="workersLoaded" class="home-target">
|
||||
<label class="field-title" for="course-workers">
|
||||
<span>同时学习课程</span>
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
<button type="button" class="hint-icon" aria-label="说明">
|
||||
<n-icon><HelpCircleOutline /></n-icon>
|
||||
</button>
|
||||
:loading="studyBusy"
|
||||
@click="toggleStudy"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon><StopOutline v-if="studyControl.started" /><PlayOutline v-else /></n-icon>
|
||||
</template>
|
||||
速度较慢,但是稳定且不容易触发风控,最大可设置8
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<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>
|
||||
{{ studyControl.started ? "停止" : "立即开始" }}
|
||||
</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-item v-if="targetLoaded" label="每月目标">
|
||||
<div class="target-control">
|
||||
<n-input-number
|
||||
id="monthly-target"
|
||||
v-model:value="monthlyTarget"
|
||||
button-placement="both"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
:precision="0"
|
||||
size="small"
|
||||
/>
|
||||
<span class="target-unit">分钟</span>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="startLoaded" label="每月开始">
|
||||
<div class="target-control start-control">
|
||||
<n-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-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>
|
||||
</n-form>
|
||||
<div class="home-study-status">
|
||||
<span class="study-indicator" :class="{ active: studyControl.started || studyControl.active }"></span>
|
||||
<span class="study-text" :class="{ muted: !studyControl.active }">{{ studyLabel }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<form v-if="proxyLoaded" class="home-proxy" @submit.prevent="saveProxy">
|
||||
<n-alert v-if="proxyError" class="summary-error" type="error">{{ proxyError }}</n-alert>
|
||||
<div class="form-row">
|
||||
<label for="proxy-scheme">代理类型</label>
|
||||
<n-select id="proxy-scheme" v-model:value="proxyScheme" size="small" :options="proxyOptions" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="proxy-host">代理地址</label>
|
||||
<n-input id="proxy-host" v-model:value="proxyHost" size="small" placeholder="例如 127.0.0.1" :disabled="!proxyManual" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="proxy-port">代理端口</label>
|
||||
<n-input-number id="proxy-port" v-model:value="proxyPort" size="small" button-placement="both" :min="1" :max="65535" :precision="0" :disabled="!proxyManual" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="proxy-user">代理账号</label>
|
||||
<n-input id="proxy-user" v-model:value="proxyUser" size="small" placeholder="可不填" autocomplete="off" :disabled="!proxyManual" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="proxy-password">代理密码</label>
|
||||
<n-input
|
||||
id="proxy-password"
|
||||
v-model:value="proxyPassword"
|
||||
size="small"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
autocomplete="new-password"
|
||||
:disabled="!proxyManual"
|
||||
/>
|
||||
</div>
|
||||
<div class="home-proxy-actions">
|
||||
</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>
|
||||
</div>
|
||||
</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>
|
||||
<n-form-item label="地址">
|
||||
<n-input v-model:value="proxyHost" size="small" placeholder="例如 127.0.0.1" :disabled="!proxyManual" />
|
||||
</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-form-item>
|
||||
<n-form-item label="账号">
|
||||
<n-input v-model:value="proxyUser" size="small" placeholder="可不填" autocomplete="off" :disabled="!proxyManual" />
|
||||
</n-form-item>
|
||||
<n-form-item label="密码">
|
||||
<n-input
|
||||
v-model:value="proxyPassword"
|
||||
size="small"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
autocomplete="new-password"
|
||||
:disabled="!proxyManual"
|
||||
/>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</form>
|
||||
<div v-if="studyStatus" class="home-study-status">
|
||||
<span class="study-indicator" :class="{ active: Boolean(myStudy) || studyStatus.running }"></span>
|
||||
<span v-if="myStudy" class="study-text">
|
||||
{{ myStudy.state === "已达标" ? "本月目标已达到" : `正在学习:${myStudy.course || myStudy.state || "准备中"}` }}
|
||||
</span>
|
||||
<span v-else-if="studyStatus.running" class="study-text muted">自动学习进行中</span>
|
||||
<span v-else-if="studyStatus.message" class="study-text muted">{{ studyStatus.message }}</span>
|
||||
<span v-else class="study-text muted">自动学习未运行</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -136,29 +136,29 @@ onMounted(refresh);
|
||||
|
||||
<template>
|
||||
<section class="page list-page">
|
||||
<header class="page-head">
|
||||
<h2 id="training-heading">线上培训</h2>
|
||||
<span class="board-tools">
|
||||
<span v-if="state === 'loading'" class="spin" role="status" aria-label="正在获取"></span>
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
<n-button
|
||||
class="home-refresh"
|
||||
quaternary
|
||||
circle
|
||||
size="small"
|
||||
aria-label="刷新"
|
||||
:loading="refreshing"
|
||||
@click="refresh"
|
||||
>
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
刷新
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</header>
|
||||
<section class="board" aria-labelledby="training-heading" :aria-busy="state === 'loading'">
|
||||
<h3>
|
||||
<span id="training-heading">线上培训</span>
|
||||
<span class="board-tools">
|
||||
<span v-if="state === 'loading'" class="spin" role="status" aria-label="正在获取"></span>
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
<n-button
|
||||
class="home-refresh"
|
||||
quaternary
|
||||
circle
|
||||
size="small"
|
||||
aria-label="刷新数据"
|
||||
:loading="refreshing"
|
||||
@click="refresh"
|
||||
>
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
刷新数据
|
||||
</n-tooltip>
|
||||
</span>
|
||||
</h3>
|
||||
<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>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons
|
||||
import { isDark, toggleTheme } from "../shared/theme";
|
||||
import { navOptions, type PageKey } from "./navigation";
|
||||
import HomeView from "../features/home/HomeView.vue";
|
||||
import HoursHistoryView from "../features/history/HoursHistoryView.vue";
|
||||
import ExamsView from "../features/exams/ExamsView.vue";
|
||||
import TrainingsView from "../features/trainings/TrainingsView.vue";
|
||||
|
||||
@@ -15,7 +16,7 @@ const collapsed = ref(window.innerWidth < 800);
|
||||
|
||||
function pageFromHash(): PageKey {
|
||||
const name = window.location.hash.replace(/^#\/?/, "");
|
||||
if (name === "exams" || name === "trainings" || name === "home") return name;
|
||||
if (name === "exams" || name === "trainings" || name === "history" || name === "home") return name;
|
||||
return "home";
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ const logoutOptions = [
|
||||
];
|
||||
|
||||
function onMenu(key: string) {
|
||||
if (key === "home" || key === "exams" || key === "trainings") {
|
||||
if (key === "home" || key === "history" || key === "exams" || key === "trainings") {
|
||||
page.value = key;
|
||||
remember(key);
|
||||
}
|
||||
@@ -111,6 +112,7 @@ function onLogout(key: string) {
|
||||
</n-layout-sider>
|
||||
<n-layout class="content" :native-scrollbar="false" content-style="height: 100%; min-height: 0; overflow: hidden; display: flex; flex-direction: column;">
|
||||
<HomeView v-if="page === 'home'" :employee-id="props.employeeId" />
|
||||
<HoursHistoryView v-else-if="page === 'history'" />
|
||||
<ExamsView v-else-if="page === 'exams'" />
|
||||
<TrainingsView v-else />
|
||||
</n-layout>
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import type { Component } from "vue";
|
||||
import { h } from "vue";
|
||||
import { NIcon } from "naive-ui";
|
||||
import { HomeOutline, ReaderOutline, SchoolOutline } from "@vicons/ionicons5";
|
||||
import { HomeOutline, ReaderOutline, SchoolOutline, TimeOutline } from "@vicons/ionicons5";
|
||||
|
||||
function renderIcon(icon: Component) {
|
||||
return () => h(NIcon, null, { default: () => h(icon) });
|
||||
}
|
||||
|
||||
export type PageKey = "home" | "exams" | "trainings";
|
||||
export type PageKey = "home" | "history" | "exams" | "trainings";
|
||||
|
||||
export const navOptions = [
|
||||
{ label: "首页", key: "home" as const, icon: renderIcon(HomeOutline) },
|
||||
{ label: "学时历史", key: "history" as const, icon: renderIcon(TimeOutline) },
|
||||
{ label: "我的考试", key: "exams" as const, icon: renderIcon(ReaderOutline) },
|
||||
{ label: "线上培训", key: "trainings" as const, icon: renderIcon(SchoolOutline) },
|
||||
];
|
||||
|
||||
+127
-44
@@ -327,9 +327,14 @@ select {
|
||||
|
||||
.page-head {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
.page-head h2 {
|
||||
@@ -360,6 +365,102 @@ select {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.panel-card {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 4px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.panel-card > h3 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 650;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.panel-card-head h3 {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
font-weight: 650;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.panel-card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.compact-form,
|
||||
.compact-nform {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
max-width: 560px;
|
||||
}
|
||||
|
||||
.compact-nform.n-form {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.compact-nform .n-form-item {
|
||||
margin: 0;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.compact-nform .n-form-item-label {
|
||||
white-space: nowrap;
|
||||
padding-right: 12px !important;
|
||||
}
|
||||
|
||||
.compact-nform .n-form-item-blank {
|
||||
min-height: 32px;
|
||||
}
|
||||
|
||||
.compact-nform .n-form-item-feedback-wrapper {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.compact-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.compact-row > label,
|
||||
.compact-row > .field-title,
|
||||
.field-title {
|
||||
flex: none;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.compact-row > .n-select,
|
||||
.compact-row > .n-input,
|
||||
.compact-row > .n-input-number,
|
||||
.compact-row > .n-time-picker {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.settings-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
max-width: 640px;
|
||||
}
|
||||
|
||||
.settings-stack .form-hint {
|
||||
margin: 0 0 4px 188px;
|
||||
}
|
||||
|
||||
.list-page {
|
||||
@@ -376,10 +477,6 @@ select {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding: 16px;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.home-summary .facts {
|
||||
@@ -461,50 +558,21 @@ select {
|
||||
width: 88px;
|
||||
}
|
||||
|
||||
.start-control .n-time-picker {
|
||||
width: 148px;
|
||||
}
|
||||
|
||||
.target-unit {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.home-proxy {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding-top: 16px;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.home-proxy .form-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.home-proxy .form-row label {
|
||||
flex: none;
|
||||
width: 84px;
|
||||
font-size: 13px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.home-proxy .form-row .n-select,
|
||||
.home-proxy .form-row .n-input,
|
||||
.home-proxy .form-row .n-input-number {
|
||||
flex: 1;
|
||||
max-width: 320px;
|
||||
}
|
||||
|
||||
.home-proxy-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding-left: 96px;
|
||||
}
|
||||
|
||||
.home-study-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding-top: 12px;
|
||||
padding-top: 8px;
|
||||
margin-top: 4px;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
|
||||
@@ -1056,13 +1124,13 @@ select {
|
||||
}
|
||||
|
||||
.settings-form .form-row {
|
||||
grid-template-columns: max-content minmax(160px, 280px);
|
||||
grid-template-columns: 7.5em minmax(160px, 280px);
|
||||
justify-content: start;
|
||||
}
|
||||
|
||||
.settings-form .form-row label {
|
||||
min-width: 15em;
|
||||
white-space: nowrap;
|
||||
min-width: 0;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
@@ -1093,11 +1161,26 @@ select {
|
||||
|
||||
.form-hint {
|
||||
margin: 0;
|
||||
padding: 2px 0 0 160px;
|
||||
padding: 2px 0 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.history-table {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.history-title {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.n-data-table {
|
||||
--n-merged-th-color: transparent;
|
||||
--n-merged-td-color: transparent;
|
||||
}
|
||||
|
||||
.page-head-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
Reference in New Issue
Block a user