add leaderboard
Some checks failed
Deploy / deploy (build, debian, 22) (push) Has been cancelled
Deploy / deploy (build:staging, school, 8822) (push) Has been cancelled

This commit is contained in:
2026-03-09 20:00:11 +08:00
parent 9c577f9bc1
commit a7aa4f63ac
8 changed files with 173 additions and 3 deletions

View File

@@ -19,6 +19,14 @@
</template>
<template #header-extra>
<n-tag type="warning" size="small">{{ item.score }}</n-tag>
<n-tag
v-if="myScoreMap.get(item.display)"
type="success"
size="small"
style="margin-left: 4px"
>
得分 {{ myScoreMap.get(item.display)!.toFixed(1) }}
</n-tag>
</template>
</n-card>
</n-gi>
@@ -31,7 +39,7 @@ import { ref, onMounted } from "vue"
import { Icon } from "@iconify/vue"
import { marked } from "marked"
import { useRouter } from "vue-router"
import { Challenge } from "../api"
import { Challenge, Submission } from "../api"
import { taskTab, taskId, challengeDisplay } from "../store/task"
import { TASK_TYPE } from "../utils/const"
import type { ChallengeSlim } from "../utils/type"
@@ -40,6 +48,16 @@ const router = useRouter()
const challenges = ref<ChallengeSlim[]>([])
const currentChallenge = ref<ChallengeSlim | null>(null)
const content = ref("")
const myScoreMap = ref<Map<number, number>>(new Map())
async function loadMyScores() {
try {
const scores = await Submission.myScores()
myScoreMap.value = new Map(scores.map((s) => [s.task_display, s.score]))
} catch {
// 未登录时忽略
}
}
async function loadList() {
challenges.value = await Challenge.listDisplay()
@@ -72,7 +90,10 @@ function back() {
router.push({ name: "home-challenge-list" })
}
onMounted(loadList)
onMounted(async () => {
await loadList()
await loadMyScores()
})
</script>
<style scoped>
.container {