+
-
- {{ CONTEST_STATUS[contest.status]["name"] }}
+
+ {{ CONTEST_STATUS[contestStore.contest.status]["name"] }}
- {{ contest.title }}
+ {{ contestStore.contest.title }}
-
+
- 确认
+
+ 确认
+
@@ -137,39 +94,43 @@ function getCurrentType(name: string): "primary" | "default" {
-
+
-
+
距离比赛开始还有
-
+
距离比赛结束还有
-
+
- {{ parseTime(contest.start_time, "YYYY年M月D日 hh:mm:ss") }}
+ {{
+ parseTime(contestStore.contest.start_time, "YYYY年M月D日 hh:mm:ss")
+ }}
- {{ parseTime(contest.end_time, "YYYY年M月D日 hh:mm:ss") }}
+ {{ parseTime(contestStore.contest.end_time, "YYYY年M月D日 hh:mm:ss") }}
-
+
- {{ contest.created_by.username }}
+ {{ contestStore.contest.created_by.username }}
-
+
@@ -182,7 +143,7 @@ function getCurrentType(name: string): "primary" | "default" {
transform: translateY(2px);
}
-.margin {
+.bottom {
margin-bottom: 24px;
}
diff --git a/src/oj/contest/pages/problems.vue b/src/oj/contest/pages/problems.vue
index ecc6192..d3cd830 100644
--- a/src/oj/contest/pages/problems.vue
+++ b/src/oj/contest/pages/problems.vue
@@ -2,13 +2,14 @@
import { DataTableColumn } from "naive-ui"
import { ProblemFiltered } from "utils/types"
import ProblemStatus from "~/oj/problem/components/ProblemStatus.vue"
+import { useContestStore } from "~/oj/store/contest"
const props = defineProps<{
contestID: string
- problems: ProblemFiltered[]
}>()
const router = useRouter()
+const contestStore = useContestStore()
const problemsColumns: DataTableColumn
[] = [
{
title: "状态",
@@ -37,10 +38,10 @@ function rowProps(row: ProblemFiltered) {
striped
size="small"
class="problems"
- :data="problems"
+ :data="contestStore.problems"
:columns="problemsColumns"
:row-props="rowProps"
- v-if="problems?.length"
+ v-if="contestStore.problems?.length"
/>
diff --git a/src/oj/store/contest.ts b/src/oj/store/contest.ts
new file mode 100644
index 0000000..53fa7ac
--- /dev/null
+++ b/src/oj/store/contest.ts
@@ -0,0 +1,69 @@
+import { useUserStore } from "~/shared/store/user"
+import { ContestType } from "~/utils/constants"
+import { Contest, Problem } from "~/utils/types"
+import {
+ getContest,
+ getContestAccess,
+ getContestProblem,
+ checkContestPassword,
+} from "../api"
+
+export const useContestStore = defineStore("contest", () => {
+ const userStore = useUserStore()
+ const contest = ref()
+ const [access, toggleAccsess] = useToggle()
+ const problems = ref([])
+ const message = useMessage()
+
+ const contestStatus = computed(() => {
+ return false
+ })
+
+ const isContestAdmin = computed(
+ () =>
+ userStore.isSuperAdmin ||
+ (userStore.isAuthed && contest.value?.created_by.id === userStore.user.id)
+ )
+
+ async function init(contestID: string) {
+ const res = await getContest(contestID)
+ contest.value = res.data
+ if (contest.value?.contest_type === ContestType.private) {
+ const res = await getContestAccess(contestID)
+ toggleAccsess(res.data.access)
+ }
+ _getProblems(contestID)
+ }
+
+ async function checkPassword(contestID: string, password: string) {
+ try {
+ const res = await checkContestPassword(contestID, password)
+ toggleAccsess(res.data)
+ if (res.data) {
+ _getProblems(contestID)
+ }
+ } catch (err) {
+ toggleAccsess(false)
+ message.error("密码错误")
+ }
+ }
+
+ async function _getProblems(contestID: string) {
+ try {
+ problems.value = await getContestProblem(contestID)
+ } catch (err) {
+ problems.value = []
+ toggleAccsess(false)
+ }
+ }
+
+ return {
+ contest,
+ contestStatus,
+ isContestAdmin,
+ access,
+ problems,
+ init,
+ checkPassword,
+ }
+})