diff --git a/web/index.html b/web/index.html index 6ff828b..b8045f4 100644 --- a/web/index.html +++ b/web/index.html @@ -3,7 +3,18 @@ + EunivTools + +
diff --git a/web/src/App.vue b/web/src/App.vue index a05bd1f..7d20af9 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -1,6 +1,6 @@ @@ -65,10 +98,22 @@ function onLogin(next: AppSession) { -
+
+
+

暂时无法确认登录状态

+
+ 重试 +
+
+
+
+
+

暂时无法确认登录状态

+ 重试 +
- +
diff --git a/web/src/features/admin/CoursesView.vue b/web/src/features/admin/CoursesView.vue index 554e651..3687522 100644 --- a/web/src/features/admin/CoursesView.vue +++ b/web/src/features/admin/CoursesView.vue @@ -11,7 +11,6 @@ interface CourseRow { learners: string; released_on: string; updated_on: string; - comments: string; } interface KindOption { @@ -54,10 +53,19 @@ function asCourse(value: unknown): CourseRow | null { learners: textOf(value.learners), released_on: textOf(value.released_on), updated_on: textOf(value.updated_on), - comments: textOf(value.comments), }; } +function setError(next: string) { + if (errorText.value !== next) errorText.value = next; +} + +function courseKey(row: CourseRow, index: number) { + const base = row.url || row.title || "course"; + const first = items.value.findIndex((item) => (item.url || item.title || "course") === base); + return first === index ? base : `${base}#${index}`; +} + function formatTime(value: string | null) { if (!value) return ""; const date = new Date(value); @@ -66,9 +74,8 @@ function formatTime(value: string | null) { return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`; } -async function load() { - loading.value = items.value.length === 0; - errorText.value = ""; +async function load(clamp = true) { + if (items.value.length === 0) loading.value = true; try { const params = new URLSearchParams({ q: appliedQuery.value, @@ -79,11 +86,11 @@ async function load() { const response = await fetch(`/api/admin/courses?${params}`); const payload = await response.json().catch(() => ({})); if (!response.ok) { - errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "课程清单没有获取到。"; + setError("课程清单没有获取到。"); return; } if (!isRecord(payload) || !Array.isArray(payload.items)) { - errorText.value = "课程清单没有获取到。"; + setError("数据异常"); return; } items.value = payload.items.map(asCourse).filter((item): item is CourseRow => item !== null); @@ -91,11 +98,17 @@ async function load() { syncedAt.value = typeof payload.synced_at === "string" ? payload.synced_at : null; kinds.value = Array.isArray(payload.kinds) ? payload.kinds.flatMap(asKind) : []; fetching.value = payload.running === true; - if (typeof payload.message === "string" && payload.message) errorText.value = payload.message; + const message = typeof payload.message === "string" ? payload.message : ""; + setError(message); if (fetching.value) startPoll(); else stopPoll(); + const maxPage = Math.max(1, Math.ceil(total.value / pageSize.value)); + if (clamp && page.value > maxPage) { + page.value = maxPage; + await load(false); + } } catch { - errorText.value = "课程清单没有获取到。"; + setError("课程清单没有获取到。"); } finally { loading.value = false; } @@ -112,20 +125,20 @@ function stopPoll() { } async function loadCourses() { - errorText.value = ""; + setError(""); fetching.value = true; try { const response = await fetch("/api/admin/courses/load", { method: "POST" }); - const payload = await response.json().catch(() => ({})); + await response.json().catch(() => ({})); if (!response.ok) { fetching.value = false; - errorText.value = isRecord(payload) && typeof payload.detail === "string" ? payload.detail : "课程清单没有获取到。"; + setError("课程清单没有获取到。"); return; } - startPoll(); + await load(); } catch { fetching.value = false; - errorText.value = "课程清单没有获取到。"; + setError("课程清单没有获取到。"); } } @@ -173,11 +186,11 @@ onUnmounted(() => stopPoll());