submission list.

This commit is contained in:
2023-01-15 21:32:04 +08:00
parent eaa5a8516e
commit 5d0f34c144
6 changed files with 110 additions and 37 deletions

2
src/components.d.ts vendored
View File

@@ -24,6 +24,7 @@ declare module '@vue/runtime-core' {
ElHeader: typeof import('element-plus/es')['ElHeader'] ElHeader: typeof import('element-plus/es')['ElHeader']
ElIcon: typeof import('element-plus/es')['ElIcon'] ElIcon: typeof import('element-plus/es')['ElIcon']
ElInput: typeof import('element-plus/es')['ElInput'] ElInput: typeof import('element-plus/es')['ElInput']
ElLink: typeof import('element-plus/es')['ElLink']
ElMain: typeof import('element-plus/es')['ElMain'] ElMain: typeof import('element-plus/es')['ElMain']
ElMenu: typeof import('element-plus/es')['ElMenu'] ElMenu: typeof import('element-plus/es')['ElMenu']
ElMenuItem: typeof import('element-plus/es')['ElMenuItem'] ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
@@ -33,6 +34,7 @@ declare module '@vue/runtime-core' {
ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
ElSelect: typeof import('element-plus/es')['ElSelect'] ElSelect: typeof import('element-plus/es')['ElSelect']
ElSpace: typeof import('element-plus/es')['ElSpace'] ElSpace: typeof import('element-plus/es')['ElSpace']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
ElTable: typeof import('element-plus/es')['ElTable'] ElTable: typeof import('element-plus/es')['ElTable']
ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
ElTabPane: typeof import('element-plus/es')['ElTabPane'] ElTabPane: typeof import('element-plus/es')['ElTabPane']

View File

@@ -83,6 +83,6 @@ export function submitCode(data: SubmitCodePayload) {
return http.post("submission", data) return http.post("submission", data)
} }
export function listSubmissions(params: SubmissionListPayload) { export function getSubmissions(params: SubmissionListPayload) {
return useAxios("submissions", { params }, http, { immediate: false }) return http.get("submissions", { params })
} }

View File

@@ -90,7 +90,6 @@ const type = (status: Sample["status"]) =>
:closable="false" :closable="false"
center center
title="🎉 本 题 已 经 被 你 解 决 啦" title="🎉 本 题 已 经 被 你 解 决 啦"
effect="dark"
> >
</el-alert> </el-alert>

View File

@@ -47,16 +47,16 @@ async function listProblems() {
problems.value = res.results problems.value = res.results
} }
function routePush() { function routerPush() {
router.push({ router.push({
path: "/", path: route.path,
query: filterEmptyValue(query), query: filterEmptyValue(query),
}) })
} }
function search() { function search() {
query.page = 1 query.page = 1
routePush() routerPush()
} }
function clear() { function clear() {
@@ -64,7 +64,7 @@ function clear() {
query.tag = "" query.tag = ""
query.difficulty = "" query.difficulty = ""
query.page = 1 query.page = 1
routePush() routerPush()
} }
async function getRandom() { async function getRandom() {
@@ -76,13 +76,13 @@ function goProblem(row: any) {
router.push("/problem/" + row._id) router.push("/problem/" + row._id)
} }
watch(() => query.page, routePush) watch(() => query.page, routerPush)
watch( watch(
() => [query.tag, query.difficulty, query.limit], () => [query.tag, query.difficulty, query.limit],
() => { () => {
query.page = 1 query.page = 1
routePush() routerPush()
} }
) )

View File

@@ -1,43 +1,102 @@
<script setup lang="ts"> <script setup lang="ts">
import Pagination from "~/shared/Pagination/index.vue" import Pagination from "~/shared/Pagination/index.vue"
import { SubmissionListPayload } from "utils/types"
import { import {
submissionMemoryFormat, submissionMemoryFormat,
submissionTimeFormat, submissionTimeFormat,
parseTime, parseTime,
filterEmptyValue,
} from "utils/functions" } from "utils/functions"
import { listSubmissions } from "oj/api" import { getSubmissions } from "oj/api"
import { isDesktop } from "~/shared/composables/breakpoints"
import SubmissionResultTag from "oj/components/SubmissionResultTag.vue" import SubmissionResultTag from "oj/components/SubmissionResultTag.vue"
const route = useRoute() const route = useRoute()
const problemID = <string>route.query.problem const router = useRouter()
const contestID = <string>route.query.contest const problemID = <string>route.query.problem ?? ""
const query = reactive<SubmissionListPayload>({ const contestID = <string>route.query.contest ?? ""
page: 1, const submissions = ref([])
limit: 10, const total = ref(0)
offset: 0, const query = reactive({
username: "", page: parseInt(<string>route.query.page) || 1,
myself: "0", limit: parseInt(<string>route.query.limit) || 10,
username: <string>route.query.username ?? "",
myself: <"1" | "0">route.query.myself,
})
async function listSubmissions() {
query.page = parseInt(<string>route.query.page) || 1
query.limit = parseInt(<string>route.query.limit) || 10
query.username = <string>route.query.username ?? ""
query.myself = <"1" | "0">route.query.myself
if (query.page < 1) query.page = 1
const offset = query.limit * (query.page - 1)
const res = await getSubmissions({
...query,
offset,
problem_id: problemID, problem_id: problemID,
contest_id: contestID, contest_id: contestID,
}) })
submissions.value = res.data.results
total.value = res.data.total
}
const { data, isLoading, isFinished, execute } = listSubmissions(query) onMounted(listSubmissions)
onMounted(() => { function routerPush() {
execute() router.push({
path: route.path,
query: filterEmptyValue(query),
}) })
}
watch(() => query.page, routerPush)
watch(
() => [query.limit, query.myself, query.username],
() => {
query.page = 1
routerPush()
}
)
watch(
() => route.path === "/status" && route.query,
(newVal) => {
if (newVal) listSubmissions()
}
)
</script> </script>
<template> <template>
<el-table v-if="isFinished" :loading="isLoading" :data="data.results"> <el-form inline>
<el-table-column label="提交时间" prop="create_time"> <el-form-item label="提交状态">
<el-select></el-select>
</el-form-item>
<el-form-item label="查看自己">
<el-switch></el-switch>
</el-form-item>
<el-form-item label="搜索提交者">
<el-input></el-input>
</el-form-item>
</el-form>
<el-table :data="submissions" stripe>
<el-table-column
label="提交时间"
prop="create_time"
:width="isDesktop ? 200 : 120"
>
<template #default="scope"> <template #default="scope">
{{ parseTime(scope.row.create_time, "YYYY-M-D hh:mm:ss") }} {{
parseTime(
scope.row.create_time,
isDesktop ? "YYYY-M-D hh:mm:ss" : "M-D hh:mm"
)
}}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="编号"> <el-table-column label="编号" min-width="140">
<template #default="scope"> <template #default="scope">
{{ scope.row.id.slice(0, 12) }} <el-link type="primary">{{ scope.row.id.slice(0, 12) }}</el-link>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="状态" prop="result"> <el-table-column label="状态" prop="result">
@@ -45,23 +104,35 @@ onMounted(() => {
<SubmissionResultTag :result="scope.row.result" /> <SubmissionResultTag :result="scope.row.result" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="题目" prop="problem"></el-table-column> <el-table-column label="题目" width="90">
<el-table-column label="执行耗时"> <template #default="scope">
<el-link
type="primary"
@click="$router.push(`/problem/${scope.row.problem}`)"
>
{{ scope.row.problem }}
</el-link>
</template>
</el-table-column>
<el-table-column v-if="isDesktop" label="执行耗时" width="100">
<template #default="scope"> <template #default="scope">
{{ submissionTimeFormat(scope.row.statistic_info.time_cost) }} {{ submissionTimeFormat(scope.row.statistic_info.time_cost) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="占用内存"> <el-table-column v-if="isDesktop" label="占用内存" width="100">
<template #default="scope"> <template #default="scope">
{{ submissionMemoryFormat(scope.row.statistic_info.memory_cost) }} {{ submissionMemoryFormat(scope.row.statistic_info.memory_cost) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="语言" prop="language"></el-table-column> <el-table-column label="语言" prop="language" width="100"></el-table-column>
<el-table-column label="提交者" prop="username"></el-table-column> <el-table-column label="提交者" min-width="120">
<template #default="scope">
<el-link type="primary">{{ scope.row.username }}</el-link>
</template>
</el-table-column>
</el-table> </el-table>
<Pagination <Pagination
v-if="isFinished" :total="total"
:total="data.total"
v-model:limit="query.limit" v-model:limit="query.limit"
v-model:page="query.page" v-model:page="query.page"
/> />

View File

@@ -22,6 +22,7 @@ watch(page, () => emit("update:page", page))
<template> <template>
<el-pagination <el-pagination
v-if="props.total"
class="right margin" class="right margin"
:layout="isDesktop ? 'prev,pager,next,sizes' : 'prev,next,sizes'" :layout="isDesktop ? 'prev,pager,next,sizes' : 'prev,next,sizes'"
background background