fix: 补上未进子任务的首页、课程筛选和客户端构造
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NInput, NPagination, NTooltip } from "naive-ui";
|
||||
import { DownloadOutline } from "@vicons/ionicons5";
|
||||
import { formatTime, isRecord, textOf } from "../../shared/text";
|
||||
|
||||
interface CourseRow {
|
||||
title: string;
|
||||
@@ -35,14 +36,6 @@ const kindTotal = computed(() => kinds.value.reduce((sum, item) => sum + item.co
|
||||
const fetching = ref(false);
|
||||
let poll = 0;
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return !!value && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function textOf(value: unknown) {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function asCourse(value: unknown): CourseRow | null {
|
||||
if (!isRecord(value) || typeof value.title !== "string") return null;
|
||||
return {
|
||||
@@ -66,14 +59,6 @@ function courseKey(row: CourseRow, index: number) {
|
||||
return first === index ? base : `${base}#${index}`;
|
||||
}
|
||||
|
||||
function formatTime(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())}`;
|
||||
}
|
||||
|
||||
async function load(clamp = true) {
|
||||
if (items.value.length === 0) loading.value = true;
|
||||
try {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NInput, NPagination, NSpin, NTooltip } from "naive-ui";
|
||||
import { RefreshOutline } from "@vicons/ionicons5";
|
||||
import { formatTime, isRecord, textOf } from "../../shared/text";
|
||||
|
||||
interface ProxyRow {
|
||||
id: number;
|
||||
@@ -51,14 +52,6 @@ const kinds = computed<StatusOption[]>(() => [
|
||||
const kindTotal = computed(() => alive.value + dead.value + pending.value);
|
||||
const probeScope = computed(() => (appliedQuery.value || status.value ? "当前筛选" : "全部"));
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return !!value && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function textOf(value: unknown) {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function asRow(value: unknown): ProxyRow | null {
|
||||
if (!isRecord(value) || typeof value.id !== "number" || typeof value.host !== "string") return null;
|
||||
return {
|
||||
@@ -77,14 +70,6 @@ function asRow(value: unknown): ProxyRow | null {
|
||||
};
|
||||
}
|
||||
|
||||
function formatTime(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())}`;
|
||||
}
|
||||
|
||||
function formatLatency(value: number | null) {
|
||||
if (value == null) return "—";
|
||||
return `${value} ms`;
|
||||
@@ -323,7 +308,7 @@ onUnmounted(() => stopPoll());
|
||||
<header class="page-head">
|
||||
<p v-if="!loading">
|
||||
可用 {{ alive }} · 失效 {{ dead }}
|
||||
<template v-if="fetchedAt"> · 更新于 {{ formatTime(fetchedAt) }}</template>
|
||||
<template v-if="fetchedAt"> · 更新于 {{ formatTime(fetchedAt, true) }}</template>
|
||||
</p>
|
||||
<form class="course-search" @submit.prevent="search">
|
||||
<n-tooltip>
|
||||
@@ -393,7 +378,7 @@ onUnmounted(() => stopPoll());
|
||||
<td :class="statusClass(row)" :title="row.note || undefined">
|
||||
{{ row.status_text }}<template v-if="row.note"> · {{ row.note }}</template>
|
||||
</td>
|
||||
<td class="when">{{ formatTime(row.last_checked_at) || "—" }}</td>
|
||||
<td class="when">{{ formatTime(row.last_checked_at, true) || "—" }}</td>
|
||||
<td>
|
||||
<n-button
|
||||
size="tiny"
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NCheckbox, NDropdown, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NRadioButton, NRadioGroup, NSelect, NTimePicker, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
||||
import { NAlert, NButton, NCheckbox, NDropdown, NForm, NFormItem, NIcon, NInputNumber, NModal, NRadioButton, NRadioGroup, NSelect, NTimePicker, NTooltip, useDialog, type DropdownOption } from "naive-ui";
|
||||
import { EllipsisHorizontalOutline, EllipsisVerticalOutline, PauseOutline, PlayOutline, SettingsOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import ProxyFields from "../../shared/ProxyFields.vue";
|
||||
import { dayOptions, workerOptions } from "../../shared/studyFields";
|
||||
import { isRecord, textOf } from "../../shared/text";
|
||||
|
||||
interface UserRow {
|
||||
employee_id: string;
|
||||
@@ -69,8 +71,6 @@ const proxyPassword = ref("");
|
||||
const proxyHasPassword = ref(false);
|
||||
const proxyManual = computed(() => proxyScheme.value !== "off" && proxyScheme.value !== "pool" && proxyScheme.value !== "keep");
|
||||
const scheduleTimeDisabled = computed(() => scheduleChoice.value === "off");
|
||||
const proxyAccountProps = { autocomplete: "off", name: "proxy-account" };
|
||||
const proxyPasswordProps = { autocomplete: "new-password", name: "proxy-password" };
|
||||
const proxyOptions = [
|
||||
{ label: "保持不变", value: "keep" },
|
||||
{ label: "关闭", value: "off" },
|
||||
@@ -139,19 +139,11 @@ const startTime = computed({
|
||||
},
|
||||
});
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return !!value && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function detailOf(payload: unknown, fallback: string) {
|
||||
if (isRecord(payload) && typeof payload.detail === "string" && payload.detail) return payload.detail;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function textOf(value: unknown) {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
function readValid(value: unknown): boolean | null {
|
||||
if (value === true) return true;
|
||||
if (value === false) return false;
|
||||
@@ -926,29 +918,17 @@ onMounted(() => {
|
||||
<n-form-item label="同时学习课程数">
|
||||
<n-select class="worker-select" v-model:value="workersValue" :options="workerOptions" placeholder="保持不变" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理类型">
|
||||
<n-select v-model:value="proxyScheme" :options="proxyOptions" />
|
||||
</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="可不填" :input-props="proxyAccountProps" />
|
||||
</n-form-item>
|
||||
<n-form-item label="代理密码">
|
||||
<n-input
|
||||
v-model:value="proxyPassword"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="settingsIds.length === 1 && proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
:input-props="proxyPasswordProps"
|
||||
/>
|
||||
</n-form-item>
|
||||
</template>
|
||||
<ProxyFields
|
||||
v-model:scheme="proxyScheme"
|
||||
v-model:host="proxyHost"
|
||||
v-model:port="proxyPort"
|
||||
v-model:username="proxyUser"
|
||||
v-model:password="proxyPassword"
|
||||
:options="proxyOptions"
|
||||
:manual="proxyManual"
|
||||
label-prefix="代理"
|
||||
:password-placeholder="settingsIds.length === 1 && proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
/>
|
||||
<div class="modal-actions">
|
||||
<n-button attr-type="button" @click="settingsOpen = false">取消</n-button>
|
||||
<n-button attr-type="submit" type="primary" :loading="settingsSaving" :disabled="!settingsReady">保存</n-button>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NModal, NTooltip } from "naive-ui";
|
||||
import { RefreshOutline } from "@vicons/ionicons5";
|
||||
import { failureText } from "../../shared/text";
|
||||
|
||||
interface ExamItem {
|
||||
name: string;
|
||||
@@ -45,13 +46,6 @@ let detailRequest = 0;
|
||||
let refreshRunning = false;
|
||||
let busy = false;
|
||||
|
||||
function failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
const detail = payload.detail;
|
||||
if (typeof detail !== "string" || !detail.trim()) return fallback;
|
||||
if (/traceback|exception|sqlite|httpx|errno|timeout|error:/i.test(detail)) return fallback;
|
||||
return detail;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInput, NInputNumber, NModal, NProgress, NSelect, NSwitch, NTimePicker, NTooltip } from "naive-ui";
|
||||
import { NAlert, NButton, NForm, NFormItem, NIcon, NInputNumber, NModal, NProgress, NSelect, NSwitch, NTimePicker, NTooltip } from "naive-ui";
|
||||
import { GlobeOutline, PlayOutline, RefreshOutline, StopOutline, WarningOutline } from "@vicons/ionicons5";
|
||||
import ProxyFields from "../../shared/ProxyFields.vue";
|
||||
import { dayOptions, workerOptions } from "../../shared/studyFields";
|
||||
import { failureText } from "../../shared/text";
|
||||
|
||||
interface HomeSummary {
|
||||
name: string;
|
||||
@@ -105,7 +107,6 @@ const studyLabel = computed(() => {
|
||||
if (state === "学习中") return "正在领取课程";
|
||||
if (studyControl.value.active || studyControl.value.started) return "正在启动学习任务";
|
||||
if (!studyControl.value.schedule_enabled) return "未开启定时自动学习";
|
||||
if (message && !message.startsWith("下一次") && !message.startsWith("运行中")) return message;
|
||||
return "未到开始时间";
|
||||
});
|
||||
|
||||
@@ -143,13 +144,6 @@ const facts = computed(() => {
|
||||
];
|
||||
});
|
||||
|
||||
function failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
const detail = payload.detail;
|
||||
if (typeof detail !== "string" || !detail.trim()) return fallback;
|
||||
if (/traceback|exception|sqlite|httpx|errno|timeout|error:/i.test(detail)) return fallback;
|
||||
return detail;
|
||||
}
|
||||
|
||||
function asSummary(value: unknown): HomeSummary | null {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
||||
const row = value as Record<string, unknown>;
|
||||
@@ -429,8 +423,6 @@ function restoreProxy() {
|
||||
proxyHasPassword.value = savedProxy.hasPassword;
|
||||
proxyError.value = "";
|
||||
}
|
||||
const proxyAccountProps = { autocomplete: "off", name: "proxy-account" };
|
||||
const proxyPasswordProps = { autocomplete: "new-password", name: "proxy-password" };
|
||||
const proxyOptions = [
|
||||
{ label: "关闭", value: "off" },
|
||||
{ label: "自动", value: "pool" },
|
||||
@@ -928,30 +920,17 @@ onUnmounted(() => {
|
||||
>
|
||||
<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" />
|
||||
</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" placeholder="请输入" />
|
||||
</n-form-item>
|
||||
<n-form-item label="账号">
|
||||
<n-input v-model:value="proxyUser" size="small" placeholder="可不填" :input-props="proxyAccountProps" />
|
||||
</n-form-item>
|
||||
<n-form-item label="密码">
|
||||
<n-input
|
||||
v-model:value="proxyPassword"
|
||||
size="small"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
:input-props="proxyPasswordProps"
|
||||
/>
|
||||
</n-form-item>
|
||||
</template>
|
||||
<ProxyFields
|
||||
v-model:scheme="proxyScheme"
|
||||
v-model:host="proxyHost"
|
||||
v-model:port="proxyPort"
|
||||
v-model:username="proxyUser"
|
||||
v-model:password="proxyPassword"
|
||||
:options="proxyOptions"
|
||||
:manual="proxyManual"
|
||||
size="small"
|
||||
:password-placeholder="proxyHasPassword ? '已保存,留空则保持' : '可不填'"
|
||||
/>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<div class="modal-actions">
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NModal, NTooltip } from "naive-ui";
|
||||
import { RefreshOutline } from "@vicons/ionicons5";
|
||||
import { failureText } from "../../shared/text";
|
||||
|
||||
interface TrainingItem {
|
||||
name: string;
|
||||
@@ -61,13 +62,6 @@ function trainingMeta(item: TrainingItem) {
|
||||
return parts.join(" · ");
|
||||
}
|
||||
|
||||
function failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
const detail = payload.detail;
|
||||
if (typeof detail !== "string" || !detail.trim()) return fallback;
|
||||
if (/traceback|exception|sqlite|httpx|errno|timeout|error:/i.test(detail)) return fallback;
|
||||
return detail;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (busy) return;
|
||||
busy = true;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import { NFormItem, NInput, NInputNumber, NSelect } from "naive-ui";
|
||||
|
||||
const scheme = defineModel<string>("scheme", { required: true });
|
||||
const host = defineModel<string>("host", { required: true });
|
||||
const port = defineModel<number | null>("port", { required: true });
|
||||
const username = defineModel<string>("username", { required: true });
|
||||
const password = defineModel<string>("password", { required: true });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
options: { label: string; value: string }[];
|
||||
manual: boolean;
|
||||
size?: "small" | "medium";
|
||||
labelPrefix?: string;
|
||||
passwordPlaceholder: string;
|
||||
}>(),
|
||||
{ size: "medium", labelPrefix: "" },
|
||||
);
|
||||
|
||||
const accountProps = { autocomplete: "off", name: "proxy-account" };
|
||||
const passwordProps = { autocomplete: "new-password", name: "proxy-password" };
|
||||
|
||||
function label(name: string) {
|
||||
return `${props.labelPrefix}${name}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-form-item :label="label('类型')">
|
||||
<n-select v-model:value="scheme" :size="size" :options="options" />
|
||||
</n-form-item>
|
||||
<template v-if="manual">
|
||||
<n-form-item :label="label('地址')">
|
||||
<n-input v-model:value="host" :size="size" placeholder="例如 127.0.0.1" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="label('端口')">
|
||||
<n-input-number v-model:value="port" :size="size" button-placement="both" :min="1" :max="65535" :precision="0" placeholder="请输入" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="label('账号')">
|
||||
<n-input v-model:value="username" :size="size" placeholder="可不填" :input-props="accountProps" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="label('密码')">
|
||||
<n-input
|
||||
v-model:value="password"
|
||||
:size="size"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:placeholder="passwordPlaceholder"
|
||||
:input-props="passwordProps"
|
||||
/>
|
||||
</n-form-item>
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
export function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return !!value && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
export function textOf(value: unknown) {
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
|
||||
export function failureText(payload: { detail?: unknown }, fallback: string) {
|
||||
const detail = payload.detail;
|
||||
if (typeof detail !== "string" || !detail.trim()) return fallback;
|
||||
if (/traceback|exception|sqlite|httpx|errno|timeout|error:/i.test(detail)) return fallback;
|
||||
return detail;
|
||||
}
|
||||
|
||||
export function formatTime(value: string | null, withSeconds = false) {
|
||||
if (!value) return "";
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value;
|
||||
const pad = (part: number) => String(part).padStart(2, "0");
|
||||
const clock = `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||
const seconds = withSeconds ? `:${pad(date.getSeconds())}` : "";
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${clock}${seconds}`;
|
||||
}
|
||||
Reference in New Issue
Block a user