add submissions.

This commit is contained in:
2023-01-15 17:12:07 +08:00
parent a62f744a9a
commit eaa5a8516e
34 changed files with 1652 additions and 1592 deletions

View File

@@ -7,7 +7,7 @@
"start": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview",
"fmt": "prettier --write src *.d.ts *.ts"
"fmt": "prettier --write src *.ts"
},
"dependencies": {
"@element-plus/icons-vue": "^2.0.10",

1
src/components.d.ts vendored
View File

@@ -8,7 +8,6 @@ export {}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
ElAlert: typeof import('element-plus/es')['ElAlert']
ElAside: typeof import('element-plus/es')['ElAside']
ElButton: typeof import('element-plus/es')['ElButton']
ElCard: typeof import('element-plus/es')['ElCard']
ElCol: typeof import('element-plus/es')['ElCol']

View File

@@ -2,7 +2,12 @@ import { useAxios } from "@vueuse/integrations/useAxios"
import http from "utils/http"
import { getACRate } from "utils/functions"
import { DIFFICULTY } from "utils/constants"
import { Problem, SubmitCodePayload, Submission } from "utils/types"
import {
Problem,
SubmitCodePayload,
Submission,
SubmissionListPayload,
} from "utils/types"
function filterResult(result: Problem) {
const newResult: any = {
@@ -14,11 +19,11 @@ function filterResult(result: Problem) {
rate: getACRate(result.accepted_number, result.submission_number),
}
if (result.my_status === null || result.my_status === undefined) {
newResult.status = "none"
newResult.status = "not_test"
} else if (result.my_status === 0) {
newResult.status = "done"
newResult.status = "passed"
} else {
newResult.status = "tried"
newResult.status = "failed"
}
return newResult
}
@@ -78,15 +83,6 @@ export function submitCode(data: SubmitCodePayload) {
return http.post("submission", data)
}
export function listSubmissions(params: {
myself: "1" | "0"
result: string
username: string
page: number
contest_id: string
problem_id: string
limit: number
offset: number
}) {
return useAxios("submissions", { params }, http)
export function listSubmissions(params: SubmissionListPayload) {
return useAxios("submissions", { params }, http, { immediate: false })
}

View File

@@ -9,7 +9,7 @@ defineProps<Props>()
</script>
<template>
<el-tag :type="(JUDGE_STATUS[result]['type'] as any)" disable-transitions>
<el-tag :type="JUDGE_STATUS[result]['type']" disable-transitions>
{{ JUDGE_STATUS[result]["name"] }}
</el-tag>
</template>

View File

@@ -5,8 +5,8 @@ import { Problem } from "utils/types"
import Monaco from "~/shared/Monaco/index.vue"
import { useCodeStore } from "oj/store/code"
import SubmitPanel from "./SubmitPanel.vue"
import TestcasePanel from "./TestcasePanel.vue"
const SubmitPanel = defineAsyncComponent(() => import("./SubmitPanel.vue"))
const TestcasePanel = defineAsyncComponent(() => import("./TestcasePanel.vue"))
interface Props {
problem: Problem
@@ -51,7 +51,7 @@ function onTab(pane: TabsPaneContext) {
</el-form-item>
<el-form-item>
<el-button @click="reset">重置</el-button>
<el-button @click="$router.push(`/status?problem=${problem.id}`)">
<el-button @click="$router.push(`/status?problem=${problem._id}`)">
提交信息
</el-button>
</el-form-item>

View File

@@ -3,7 +3,7 @@ import { Flag, CloseBold, Select, CopyDocument } from "@element-plus/icons-vue"
import copy from "copy-text-to-clipboard"
import { useCodeStore } from "oj/store/code"
import { SOURCES } from "utils/constants"
import { Problem } from "utils/types"
import { Problem, ProblemStatus } from "utils/types"
import { createTestSubmission } from "utils/judge"
import { submissionExists } from "oj/api"
@@ -13,7 +13,7 @@ interface Props {
type Sample = Problem["samples"][number] & {
id: number
msg: string
status: "passed" | "failed" | "not_test"
status: ProblemStatus
loading: boolean
}

View File

@@ -29,10 +29,7 @@ defineProps<Props>()
{{ problem.memory_limit }}MB
</el-descriptions-item>
<el-descriptions-item label="难度">
<el-tag
disable-transitions
:type="(getTagColor(problem.difficulty) as any)"
>
<el-tag disable-transitions :type="getTagColor(problem.difficulty)">
{{ DIFFICULTY[problem.difficulty] }}
</el-tag>
</el-descriptions-item>

View File

@@ -184,7 +184,7 @@ defineExpose({ submit })
<el-alert
v-if="submission"
:closable="false"
:type="(JUDGE_STATUS[submission.result]['alertType'] as any)"
:type="JUDGE_STATUS[submission.result]['alertType']"
:title="JUDGE_STATUS[submission.result]['name']"
>
</el-alert>

View File

@@ -1,10 +1,14 @@
<script setup lang="ts">
import Editor from "./components/Editor.vue"
import ProblemContent from "./components/ProblemContent.vue"
import ProblemInfo from "./components/ProblemInfo.vue"
import { getProblem } from "oj/api"
import { isDesktop, isMobile } from "~/shared/composables/breakpoints"
import { TabsPaneContext } from "element-plus"
const Editor = defineAsyncComponent(() => import("./components/Editor.vue"))
const ProblemContent = defineAsyncComponent(
() => import("./components/ProblemContent.vue")
)
const ProblemInfo = defineAsyncComponent(
() => import("./components/ProblemInfo.vue")
)
interface Props {
problemID: string

View File

@@ -140,12 +140,12 @@ onMounted(listProblems)
<el-table-column v-if="isDesktop" label="状态" :width="80">
<template #default="scope">
<el-icon
v-if="scope.row.status === 'done'"
v-if="scope.row.status === 'passed'"
color="var(--el-color-success)"
><i-ep-select
/></el-icon>
<el-icon
v-if="scope.row.status === 'tried'"
v-if="scope.row.status === 'failed'"
color="var(--el-color-error)"
><i-ep-semi-select
/></el-icon>
@@ -155,10 +155,7 @@ onMounted(listProblems)
<el-table-column prop="title" label="标题" />
<el-table-column label="难度" width="100">
<template #default="scope">
<el-tag
disable-transitions
:type="(getTagColor(scope.row.difficulty) as any)"
>
<el-tag disable-transitions :type="getTagColor(scope.row.difficulty)">
{{ scope.row.difficulty }}
</el-tag>
</template>

View File

@@ -1,16 +1,67 @@
<script setup lang="ts">
import Pagination from "~/shared/Pagination/index.vue"
import { SubmissionListPayload } from "utils/types"
import {
submissionMemoryFormat,
submissionTimeFormat,
parseTime,
} from "utils/functions"
import { listSubmissions } from "oj/api"
import SubmissionResultTag from "oj/components/SubmissionResultTag.vue"
const query = reactive({
const route = useRoute()
const problemID = <string>route.query.problem
const contestID = <string>route.query.contest
const query = reactive<SubmissionListPayload>({
page: 1,
limit: 10,
offset: 0,
username: "",
myself: "0",
problem_id: problemID,
contest_id: contestID,
})
const { data, isLoading, isFinished, execute } = listSubmissions(query)
onMounted(() => {
execute()
})
const total = ref(100)
</script>
<template>
<el-table max-height="calc(100vh - 171px)"></el-table>
<el-table v-if="isFinished" :loading="isLoading" :data="data.results">
<el-table-column label="提交时间" prop="create_time">
<template #default="scope">
{{ parseTime(scope.row.create_time, "YYYY-M-D hh:mm:ss") }}
</template>
</el-table-column>
<el-table-column label="编号">
<template #default="scope">
{{ scope.row.id.slice(0, 12) }}
</template>
</el-table-column>
<el-table-column label="状态" prop="result">
<template #default="scope">
<SubmissionResultTag :result="scope.row.result" />
</template>
</el-table-column>
<el-table-column label="题目" prop="problem"></el-table-column>
<el-table-column label="执行耗时">
<template #default="scope">
{{ submissionTimeFormat(scope.row.statistic_info.time_cost) }}
</template>
</el-table-column>
<el-table-column label="占用内存">
<template #default="scope">
{{ submissionMemoryFormat(scope.row.statistic_info.memory_cost) }}
</template>
</el-table-column>
<el-table-column label="语言" prop="language"></el-table-column>
<el-table-column label="提交者" prop="username"></el-table-column>
</el-table>
<Pagination
:total="total"
v-if="isFinished"
:total="data.total"
v-model:limit="query.limit"
v-model:page="query.page"
/>

7
src/shims.d.ts vendored
View File

@@ -1,5 +1,3 @@
import type * as Monaco from "monaco-editor"
declare module "element-plus/dist/locale/zh-cn.mjs"
declare module "*.md" {
@@ -9,7 +7,12 @@ declare module "*.md" {
}
declare global {
let monaco: Monaco
interface Window {
monaco: Monaco
}
}
interface Window {
monaco: Monaco
}

View File

@@ -9,6 +9,8 @@ export type LANGUAGE =
export type SUBMISSION_RESULT = -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
export type ProblemStatus = "passed" | "failed" | "not_test"
export interface Problem {
_id: string
id: number
@@ -100,3 +102,14 @@ export interface Submission {
problem: number
can_unshare: boolean
}
export interface SubmissionListPayload {
myself?: "1" | "0"
result?: SUBMISSION_RESULT
username?: string
contest_id?: string
problem_id?: string
page: number
limit: number
offset: number
}