From a7aa4f63ac29b8630e902e1f9bfb6f2d92061cf0 Mon Sep 17 00:00:00 2001
From: yuetsh <517252939@qq.com>
Date: Mon, 9 Mar 2026 20:00:11 +0800
Subject: [PATCH] add leaderboard
---
components.d.ts | 1 +
src/api.ts | 17 ++++++++++
src/components/Challenge.vue | 25 ++++++++++++--
src/components/Task.vue | 10 +++++-
src/pages/Leaderboard.vue | 46 ++++++++++++++++++++++++++
src/pages/MyScores.vue | 64 ++++++++++++++++++++++++++++++++++++
src/pages/Submissions.vue | 2 ++
src/router.ts | 11 +++++++
8 files changed, 173 insertions(+), 3 deletions(-)
create mode 100644 src/pages/Leaderboard.vue
create mode 100644 src/pages/MyScores.vue
diff --git a/components.d.ts b/components.d.ts
index f1b6e92..80e9452 100644
--- a/components.d.ts
+++ b/components.d.ts
@@ -37,6 +37,7 @@ declare module 'vue' {
NPagination: typeof import('naive-ui')['NPagination']
NPopover: typeof import('naive-ui')['NPopover']
NRate: typeof import('naive-ui')['NRate']
+ NSelect: typeof import('naive-ui')['NSelect']
NSpin: typeof import('naive-ui')['NSpin']
NSplit: typeof import('naive-ui')['NSplit']
NTab: typeof import('naive-ui')['NTab']
diff --git a/src/api.ts b/src/api.ts
index 2e4e8ce..ab9255f 100644
--- a/src/api.ts
+++ b/src/api.ts
@@ -67,6 +67,11 @@ export const Account = {
const res = await http.post("/account/batch", payload)
return res.data
},
+
+ async leaderboard() {
+ const res = await http.get("/account/leaderboard")
+ return res.data as { rank: number; username: string; total_score: number }[]
+ },
}
export const Tutorial = {
@@ -172,6 +177,18 @@ export const Submission = {
const res = await http.put(`/submission/${id}/flag`, { flag })
return res.data
},
+
+ async myScores() {
+ const res = await http.get("/submission/my-scores")
+ return res.data as {
+ task_id: number
+ task_display: number
+ task_title: string
+ score: number
+ created: string
+ }[]
+ },
+
}
export const Prompt = {
diff --git a/src/components/Challenge.vue b/src/components/Challenge.vue
index bd3bc85..908065b 100644
--- a/src/components/Challenge.vue
+++ b/src/components/Challenge.vue
@@ -19,6 +19,14 @@
{{ item.score }}分
+
+ 得分 {{ myScoreMap.get(item.display)!.toFixed(1) }}
+
@@ -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([])
const currentChallenge = ref(null)
const content = ref("")
+const myScoreMap = ref