From 7def5a4d83a12fe1b9e2bf0da6e88eee018bd304 Mon Sep 17 00:00:00 2001
From: yuetsh <517252939@qq.com>
Date: Mon, 23 Jan 2023 22:56:50 +0800
Subject: [PATCH] add contest detail.
---
src/components.d.ts | 1 +
src/oj/api.ts | 13 ++++
src/oj/contest/components/ContestTitle.vue | 3 +-
src/oj/contest/detail.vue | 78 +++++++++++++++++++++-
src/oj/contest/list.vue | 4 +-
src/shared/Header.vue | 11 ++-
src/utils/constants.ts | 13 +++-
src/utils/types.ts | 6 +-
8 files changed, 118 insertions(+), 11 deletions(-)
diff --git a/src/components.d.ts b/src/components.d.ts
index 37cd397..fa14842 100644
--- a/src/components.d.ts
+++ b/src/components.d.ts
@@ -16,6 +16,7 @@ declare module '@vue/runtime-core' {
NCard: typeof import('naive-ui')['NCard']
NCode: typeof import('naive-ui')['NCode']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
+ NCountdown: typeof import('naive-ui')['NCountdown']
NDataTable: typeof import('naive-ui')['NDataTable']
NDescriptions: typeof import('naive-ui')['NDescriptions']
NDescriptionsItem: typeof import('naive-ui')['NDescriptionsItem']
diff --git a/src/oj/api.ts b/src/oj/api.ts
index 705b037..2e06be7 100644
--- a/src/oj/api.ts
+++ b/src/oj/api.ts
@@ -105,3 +105,16 @@ export function getContestList(query: {
export function getContest(id: string) {
return http.get("contest", { params: { id } })
}
+
+export function getContestAccess(id: string) {
+ return http.get("contest/access", { params: { contest_id: id } })
+}
+
+export function checkContestPassword(contestID: string, password: string) {
+ return http.post("contest/password", {
+ data: {
+ contest_id: contestID,
+ password,
+ },
+ })
+}
diff --git a/src/oj/contest/components/ContestTitle.vue b/src/oj/contest/components/ContestTitle.vue
index 82d38a4..1bf8b50 100644
--- a/src/oj/contest/components/ContestTitle.vue
+++ b/src/oj/contest/components/ContestTitle.vue
@@ -1,5 +1,6 @@
@@ -8,7 +9,7 @@ defineProps<{ contest: Contest }>()
{{ contest.title }}
diff --git a/src/oj/contest/detail.vue b/src/oj/contest/detail.vue
index d37ed58..b087b2a 100644
--- a/src/oj/contest/detail.vue
+++ b/src/oj/contest/detail.vue
@@ -1,7 +1,79 @@
-
+
+
+
+
+
+ {{ CONTEST_STATUS[contest.status]["name"] }}
+
+ {{ contest.title }}
+
+
+
+
+
+
+
+
+
+
+ 距离比赛开始还有
+
+
+ 距离比赛结束还有
+
+
+
+
+
+
+
+
+
+ {{ parseTime(contest.start_time, "YYYY年M月D日 hh:mm:ss") }}
+
+
+ {{ parseTime(contest.end_time, "YYYY年M月D日 hh:mm:ss") }}
+
+
+ {{ contest.contest_type === ContestType.private ? "需要密码" : "公开" }}
+
+
+ {{ contest.created_by.username }}
+
+
+
+
-
+
diff --git a/src/oj/contest/list.vue b/src/oj/contest/list.vue
index 6a23db8..b9cc4ed 100644
--- a/src/oj/contest/list.vue
+++ b/src/oj/contest/list.vue
@@ -4,7 +4,7 @@ import { getContestList } from "oj/api"
import Pagination from "~/shared/Pagination.vue"
import { filterEmptyValue, parseTime, duration } from "utils/functions"
import { Contest } from "utils/types"
-import { CONTEST_STATUS } from "~/utils/constants"
+import { ContestType, CONTEST_STATUS } from "~/utils/constants"
import ContestTitle from "./components/ContestTitle.vue"
import { useUserStore } from "~/shared/store/user"
import { toggleLogin } from "~/shared/composables/modal"
@@ -108,7 +108,7 @@ function rowProps(row: Contest) {
return {
style: "cursor: pointer",
onClick() {
- if (!userStore.isAuthed && row.contest_type === "Password Protected") {
+ if (!userStore.isAuthed && row.contest_type === ContestType.private) {
toggleLogin(true)
} else {
router.push("/contest/" + row.id)
diff --git a/src/shared/Header.vue b/src/shared/Header.vue
index 90ed952..773980b 100644
--- a/src/shared/Header.vue
+++ b/src/shared/Header.vue
@@ -12,6 +12,7 @@ import type {
import { RouterLink } from "vue-router"
const userStore = useUserStore()
+const route = useRoute()
const router = useRouter()
async function handleLogout() {
@@ -30,6 +31,8 @@ function handleDropdown(key: string) {
onMounted(userStore.getMyProfile)
+const defaultValue = computed(() => route.path.split("/")[1] || "problem")
+
const menus: MenuOption[] = [
{
label: () =>
@@ -47,7 +50,7 @@ const menus: MenuOption[] = [
{
label: () =>
h(RouterLink, { to: "/submission" }, { default: () => "提交" }),
- key: "status",
+ key: "submission",
},
{
label: () => h(RouterLink, { to: "/rank" }, { default: () => "排名" }),
@@ -67,7 +70,11 @@ const options = computed>(() => [
-
+
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index 2f57c86..1fa5114 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -14,6 +14,17 @@ export enum SubmissionStatus {
submitting = 9,
}
+export enum ContestStatus {
+ not_started = "1",
+ underway = "0",
+ finished = "-1",
+}
+
+export enum ContestType {
+ public = "Public",
+ private = "Password Protected",
+}
+
export const JUDGE_STATUS: {
[key in SUBMISSION_RESULT]: {
name: string
@@ -71,7 +82,7 @@ export const JUDGE_STATUS: {
}
export const CONTEST_STATUS: {
- [key in "1" | "-1" | "0"]: {
+ [key in ContestStatus]: {
name: string
type: "error" | "success" | "warning"
}
diff --git a/src/utils/types.ts b/src/utils/types.ts
index ccdee53..43b33cd 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -1,3 +1,5 @@
+import { ContestStatus, ContestType } from "./constants"
+
export interface Profile {
id: number
user: User
@@ -206,8 +208,8 @@ export interface Contest {
username: string
real_name: null
}
- status: "-1" | "0" | "1"
- contest_type: "Password Protected" | "Public"
+ status: ContestStatus
+ contest_type: ContestType
title: string
description: string
real_time_rank: boolean