From 7b0163885afa851164ffc8883fd7bb2f1851982e Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Tue, 31 Jan 2023 16:29:58 +0800 Subject: [PATCH] fix. --- src/oj/contest/detail.vue | 119 ++++++++++-------------------- src/oj/contest/pages/problems.vue | 7 +- src/oj/store/contest.ts | 69 +++++++++++++++++ 3 files changed, 113 insertions(+), 82 deletions(-) create mode 100644 src/oj/store/contest.ts diff --git a/src/oj/contest/detail.vue b/src/oj/contest/detail.vue index 0072462..d874da6 100644 --- a/src/oj/contest/detail.vue +++ b/src/oj/contest/detail.vue @@ -1,82 +1,35 @@ @@ -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, + } +})