contest problem list.
This commit is contained in:
@@ -1,9 +1,15 @@
|
|||||||
import http from "utils/http"
|
import http from "utils/http"
|
||||||
import { Problem, User } from "~/utils/types"
|
import { Problem, User } from "~/utils/types"
|
||||||
|
|
||||||
export async function getProblemList(offset = 0, limit = 10, keyword: string) {
|
export async function getProblemList(
|
||||||
const res = await http.get("admin/problem", {
|
offset = 0,
|
||||||
params: { paging: true, offset, limit, keyword },
|
limit = 10,
|
||||||
|
keyword: string,
|
||||||
|
contestID?: string
|
||||||
|
) {
|
||||||
|
const endpoint = !!contestID ? "admin/contest/problem" : "admin/problem"
|
||||||
|
const res = await http.get(endpoint, {
|
||||||
|
params: { paging: true, offset, limit, keyword, contest_id: contestID },
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
results: res.data.results.map((result: Problem) => ({
|
results: res.data.results.map((result: Problem) => ({
|
||||||
@@ -22,14 +28,26 @@ export function deleteProblem(id: number) {
|
|||||||
return http.delete("admin/problem", { params: { id } })
|
return http.delete("admin/problem", { params: { id } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deleteContestProblem(id: number) {
|
||||||
|
return http.delete("admin/contest/problem", { params: { id } })
|
||||||
|
}
|
||||||
|
|
||||||
export function editProblem(problem: Problem) {
|
export function editProblem(problem: Problem) {
|
||||||
return http.put("admin/problem", problem)
|
return http.put("admin/problem", problem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function editContestProblem(problem: Problem) {
|
||||||
|
return http.put("admin/contest/problem", problem)
|
||||||
|
}
|
||||||
|
|
||||||
export function getProblem(id: number) {
|
export function getProblem(id: number) {
|
||||||
return http.get("admin/problem", { params: { id } })
|
return http.get("admin/problem", { params: { id } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getContestProblem(id: number) {
|
||||||
|
return http.get("admin/contest/problem", { params: { id } })
|
||||||
|
}
|
||||||
|
|
||||||
export function getUserList(offset = 0, limit = 10, keyword: string) {
|
export function getUserList(offset = 0, limit = 10, keyword: string) {
|
||||||
return http.get("admin/user", {
|
return http.get("admin/user", {
|
||||||
params: { paging: true, offset, limit, keyword },
|
params: { paging: true, offset, limit, keyword },
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function goEdit() {
|
|||||||
|
|
||||||
function goEditProblems() {
|
function goEditProblems() {
|
||||||
router.push({
|
router.push({
|
||||||
name: "admin contest problems",
|
name: "admin contest problem list",
|
||||||
params: { contestID: props.contest.id },
|
params: { contestID: props.contest.id },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<script setup lang="ts"></script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div>contest problem list</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { deleteProblem } from "~/admin/api"
|
import { deleteContestProblem, deleteProblem } from "~/admin/api"
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
problemID: number
|
problemID: number
|
||||||
@@ -7,13 +7,26 @@ interface Props {
|
|||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
const emit = defineEmits(["deleted"])
|
const emit = defineEmits(["deleted"])
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
|
|
||||||
async function handleDeleteProblem() {
|
async function handleDeleteProblem() {
|
||||||
|
try {
|
||||||
|
if (route.name === "admin contest problem list") {
|
||||||
|
await deleteContestProblem(props.problemID)
|
||||||
|
} else {
|
||||||
await deleteProblem(props.problemID)
|
await deleteProblem(props.problemID)
|
||||||
|
}
|
||||||
message.success("删除成功")
|
message.success("删除成功")
|
||||||
emit("deleted")
|
emit("deleted")
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.data === "Can't delete the problem as it has submissions") {
|
||||||
|
message.error("这道题有提交之后,就不能被删除")
|
||||||
|
} else {
|
||||||
|
message.error("删除失败")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function download() {
|
function download() {
|
||||||
@@ -21,10 +34,8 @@ function download() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function goEdit() {
|
function goEdit() {
|
||||||
router.push({
|
const name = route.name!.toString().replace("list", "edit")
|
||||||
name: "problem edit",
|
router.push({ name, params: { problemID: props.problemID } })
|
||||||
params: { problemID: props.problemID },
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ import { AdminProblemFiltered } from "~/utils/types"
|
|||||||
import { parseTime } from "~/utils/functions"
|
import { parseTime } from "~/utils/functions"
|
||||||
import Actions from "./components/Actions.vue"
|
import Actions from "./components/Actions.vue"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
contestID?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<Props>()
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const problems = ref<AdminProblemFiltered[]>([])
|
const problems = ref<AdminProblemFiltered[]>([])
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
@@ -40,13 +45,22 @@ const columns: DataTableColumn<AdminProblemFiltered>[] = [
|
|||||||
title: "选项",
|
title: "选项",
|
||||||
key: "actions",
|
key: "actions",
|
||||||
width: 200,
|
width: 200,
|
||||||
render: (row) => h(Actions, { problemID: row.id, onDeleted: listProblems }),
|
render: (row) =>
|
||||||
|
h(Actions, {
|
||||||
|
problemID: row.id,
|
||||||
|
onDeleted: listProblems,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
async function listProblems() {
|
async function listProblems() {
|
||||||
const offset = (query.page - 1) * query.limit
|
const offset = (query.page - 1) * query.limit
|
||||||
const res = await getProblemList(offset, query.limit, query.keyword)
|
const res = await getProblemList(
|
||||||
|
offset,
|
||||||
|
query.limit,
|
||||||
|
query.keyword,
|
||||||
|
props.contestID
|
||||||
|
)
|
||||||
total.value = res.total
|
total.value = res.total
|
||||||
problems.value = res.results
|
problems.value = res.results
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,9 +162,9 @@ export const routes: RouteRecordRaw[] = [
|
|||||||
props: true,
|
props: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "contest/:contestID/problems",
|
path: "contest/:contestID/problem/list",
|
||||||
name: "admin contest problems",
|
name: "admin contest problem list",
|
||||||
component: () => import("admin/contest/detail.vue"),
|
component: () => import("admin/problem/list.vue"),
|
||||||
props: true,
|
props: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user