From 91e2f8bf05240cb89d9aeee58fcc36472ee89734 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Mon, 24 Nov 2025 20:40:03 +0800 Subject: [PATCH] fix problemset stats --- .../components/UserProgressView.vue | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/oj/problemset/components/UserProgressView.vue b/src/oj/problemset/components/UserProgressView.vue index 8fc3193..0651455 100644 --- a/src/oj/problemset/components/UserProgressView.vue +++ b/src/oj/problemset/components/UserProgressView.vue @@ -12,6 +12,11 @@ const problemSetId = computed(() => Number(route.params.problemSetId)) const progress = ref([]) const loading = ref(false) const total = ref(0) +const statistics = ref<{ + total: number + completed: number + avg_progress: number +} | null>(null) // 使用分页 composable const { query } = usePagination({}, { defaultLimit: 10 }) @@ -27,25 +32,30 @@ async function loadUserProgress() { progress.value = res.data.results total.value = res.data.total + // 使用后端返回的统计数据(基于所有数据) + if (res.data.statistics) { + statistics.value = res.data.statistics + } loading.value = false } // 监听分页参数变化 watch([() => query.page, () => query.limit], loadUserProgress) -// 计算统计数据 +// 使用后端返回的统计数据 const stats = computed(() => { - const completed = progress.value.filter((p) => p.is_completed).length - const avgProgress = - progress.value.length > 0 - ? progress.value.reduce((sum, p) => sum + p.progress_percentage, 0) / - progress.value.length - : 0 - + if (statistics.value) { + return { + total: statistics.value.total, + completed: statistics.value.completed, + avgProgress: Math.round(statistics.value.avg_progress), + } + } + // 如果后端还没有返回统计数据,使用默认值 return { total: total.value, - completed, - avgProgress: Math.round(avgProgress), + completed: 0, + avgProgress: 0, } })