This commit is contained in:
@@ -12,6 +12,11 @@ const problemSetId = computed(() => Number(route.params.problemSetId))
|
|||||||
const progress = ref<ProblemSetProgress[]>([])
|
const progress = ref<ProblemSetProgress[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
|
const statistics = ref<{
|
||||||
|
total: number
|
||||||
|
completed: number
|
||||||
|
avg_progress: number
|
||||||
|
} | null>(null)
|
||||||
|
|
||||||
// 使用分页 composable
|
// 使用分页 composable
|
||||||
const { query } = usePagination({}, { defaultLimit: 10 })
|
const { query } = usePagination({}, { defaultLimit: 10 })
|
||||||
@@ -27,25 +32,30 @@ async function loadUserProgress() {
|
|||||||
|
|
||||||
progress.value = res.data.results
|
progress.value = res.data.results
|
||||||
total.value = res.data.total
|
total.value = res.data.total
|
||||||
|
// 使用后端返回的统计数据(基于所有数据)
|
||||||
|
if (res.data.statistics) {
|
||||||
|
statistics.value = res.data.statistics
|
||||||
|
}
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听分页参数变化
|
// 监听分页参数变化
|
||||||
watch([() => query.page, () => query.limit], loadUserProgress)
|
watch([() => query.page, () => query.limit], loadUserProgress)
|
||||||
|
|
||||||
// 计算统计数据
|
// 使用后端返回的统计数据
|
||||||
const stats = computed(() => {
|
const stats = computed(() => {
|
||||||
const completed = progress.value.filter((p) => p.is_completed).length
|
if (statistics.value) {
|
||||||
const avgProgress =
|
return {
|
||||||
progress.value.length > 0
|
total: statistics.value.total,
|
||||||
? progress.value.reduce((sum, p) => sum + p.progress_percentage, 0) /
|
completed: statistics.value.completed,
|
||||||
progress.value.length
|
avgProgress: Math.round(statistics.value.avg_progress),
|
||||||
: 0
|
}
|
||||||
|
}
|
||||||
|
// 如果后端还没有返回统计数据,使用默认值
|
||||||
return {
|
return {
|
||||||
total: total.value,
|
total: total.value,
|
||||||
completed,
|
completed: 0,
|
||||||
avgProgress: Math.round(avgProgress),
|
avgProgress: 0,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user