fix(后台列表): 加载失败有提示、慢的时候表格转圈、旧请求晚回来不再盖掉新结果
Deploy / deploy (push) Canceled after 0s

后台八个列表(题目、比赛、用户、公告、题单、AI 报告、从题库加题、标签下的题)原来是
`const res = await getXxx(); rows.value = res.results`:接口 500 或断网时什么都不提示,
表格停在旧数据上;关键词防抖和翻页一交错,先发的晚回来会把新结果盖掉。

shared/composables/listLoader.ts 的 track() 把请求包一层:带请求序号、出错按后端文案提示
(登录过期、没权限这几种全局拦截器已经提示过,不弹第二遍)、表格挂 loading。

实跑:六个列表各 10 行正常;拦掉题目列表的接口再翻页,弹「网络异常,请检查网络后重试」
(原来没有任何反应)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-16 15:07:10 +08:00
1 parent 4dfd14f95b
commit d4aadc7722
10 files changed
+122 -27

No files matched your search

+11 -2
View File
@@ -7,6 +7,7 @@ import type { AdminProblemSet } from "utils/types"
import { getProblemSetList, toggleProblemSetVisible } from "../api"
import { NButton, NSwitch, NTag, useThemeVars } from "naive-ui"
import { useBreakpoints } from "shared/composables/breakpoints"
import { useListLoader } from "shared/composables/listLoader"
/**
* 后台题单列表。难度、状态两列和筛选拿掉了(线上全是简单 / 活跃,「状态 + 可见」合成了「公开」),
@@ -115,10 +116,12 @@ const desktopColumns: DataTableColumn<AdminProblemSet>[] = [
const columns = computed(() => (isMobile.value ? mobileColumns : desktopColumns))
const { loading, track } = useListLoader()
async function listProblemSets() {
if (query.page < 1) query.page = 1
const offset = (query.page - 1) * query.limit
const res = await getProblemSetList(offset, query.limit, query.keyword)
const res = await track(getProblemSetList(offset, query.limit, query.keyword))
if (!res) return
total.value = res.total
problemSets.value = res.results
}
@@ -150,7 +153,13 @@ watch(() => [query.page, query.limit], listProblemSets)
/>
</template>
</PageHeader>
<n-data-table striped class="set-table" :columns="columns" :data="problemSets" />
<n-data-table
:loading="loading"
striped
class="set-table"
:columns="columns"
:data="problemSets"
/>
<Pagination :total="total" v-model:limit="query.limit" v-model:page="query.page" />
</template>