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 @@ - + - + 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>(() => [