feat: 立即开始停止学习并整理学时历史与界面

This commit is contained in:
2026-11-15 04:16:40 +08:00
parent ce2d6e08dd
commit f0a2bdd854
25 changed files with 1748 additions and 580 deletions
+86 -2
View File
@@ -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>