problem list.
This commit is contained in:
@@ -29,3 +29,15 @@ export async function getProblemList(
|
|||||||
total: res.data.total,
|
total: res.data.total,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deleteProblem(id: number) {
|
||||||
|
return http.delete("admin/problem", { params: { id } })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function editProblem(problem: Problem) {
|
||||||
|
return http.put("admin/problem", problem)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getProblem(id: number) {
|
||||||
|
return http.get("admin/problem", { params: { id } })
|
||||||
|
}
|
||||||
|
|||||||
24
src/admin/problem/components/DeleteProblem.vue
Normal file
24
src/admin/problem/components/DeleteProblem.vue
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { deleteProblem } from "~/admin/api"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
problemID: number
|
||||||
|
}
|
||||||
|
const props = defineProps<Props>()
|
||||||
|
const emit = defineEmits(["deleted"])
|
||||||
|
const message = useMessage()
|
||||||
|
|
||||||
|
async function handleDeleteProblem(problemID: number) {
|
||||||
|
await deleteProblem(problemID)
|
||||||
|
message.success("删除成功")
|
||||||
|
emit("deleted")
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<n-popconfirm @positive-click="() => handleDeleteProblem(props.problemID)">
|
||||||
|
<template #trigger>
|
||||||
|
<n-button tertiary size="small" type="error">删除</n-button>
|
||||||
|
</template>
|
||||||
|
确定删除这道题目吗?相关的提交也会被相应删除哦 😯
|
||||||
|
</n-popconfirm>
|
||||||
|
</template>
|
||||||
15
src/admin/problem/components/DownloadTestcases.vue
Normal file
15
src/admin/problem/components/DownloadTestcases.vue
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
const props = defineProps<{ problemID: number }>()
|
||||||
|
|
||||||
|
function download() {
|
||||||
|
console.log(props.problemID)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<n-tooltip>
|
||||||
|
<template #trigger>
|
||||||
|
<n-button size="small" tertiary @click="download">下载</n-button>
|
||||||
|
</template>
|
||||||
|
下载测试用例
|
||||||
|
</n-tooltip>
|
||||||
|
</template>
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getProblemList } from "../api"
|
import { getProblemList, getProblem, editProblem } from "../api"
|
||||||
import Pagination from "~/shared/Pagination.vue"
|
import Pagination from "~/shared/Pagination.vue"
|
||||||
import { DataTableColumn, NButton, NSwitch } from "naive-ui"
|
import { DataTableColumn, NButton, NSwitch } from "naive-ui"
|
||||||
import { AdminProblemFiltered } from "~/utils/types"
|
import { AdminProblemFiltered } from "~/utils/types"
|
||||||
import { parseTime } from "~/utils/functions"
|
import { parseTime } from "~/utils/functions"
|
||||||
|
import DownloadTestcases from "./components/DownloadTestcases.vue"
|
||||||
|
import DeleteProblem from "./components/DeleteProblem.vue"
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const problems = ref([])
|
const problems = ref<AdminProblemFiltered[]>([])
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
limit: 10,
|
limit: 10,
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -14,10 +18,10 @@ const query = reactive({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const columns: DataTableColumn<AdminProblemFiltered>[] = [
|
const columns: DataTableColumn<AdminProblemFiltered>[] = [
|
||||||
{ title: "ID", key: "id", width: 100 },
|
{ title: "ID", key: "id", width: 80 },
|
||||||
{ title: "显示编号", key: "_id", width: 100 },
|
{ title: "显示编号", key: "_id", width: 100 },
|
||||||
{ title: "标题", key: "title", minWidth: 300 },
|
{ title: "标题", key: "title", minWidth: 300 },
|
||||||
{ title: "出题人", key: "username", width: 100 },
|
{ title: "出题人", key: "username", width: 120 },
|
||||||
{
|
{
|
||||||
title: "创建时间",
|
title: "创建时间",
|
||||||
key: "create_time",
|
key: "create_time",
|
||||||
@@ -27,30 +31,40 @@ const columns: DataTableColumn<AdminProblemFiltered>[] = [
|
|||||||
{
|
{
|
||||||
title: "可见",
|
title: "可见",
|
||||||
key: "visible",
|
key: "visible",
|
||||||
render: (row) => h(NSwitch, { value: row.visible }),
|
render: (row) =>
|
||||||
|
h(NSwitch, {
|
||||||
|
value: row.visible,
|
||||||
|
size: "small",
|
||||||
|
rubberBand: false,
|
||||||
|
onUpdateValue: () => toggleVisible(row.id),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "edit",
|
key: "edit",
|
||||||
render: () =>
|
render: (row) =>
|
||||||
h(
|
h(
|
||||||
NButton,
|
NButton,
|
||||||
{ type: "primary", size: "small", tertiary: true },
|
{
|
||||||
|
type: "primary",
|
||||||
|
size: "small",
|
||||||
|
tertiary: true,
|
||||||
|
onClick: () =>
|
||||||
|
router.push({
|
||||||
|
name: "problem edit",
|
||||||
|
params: { problemID: row.id },
|
||||||
|
}),
|
||||||
|
},
|
||||||
{ default: () => "编辑" }
|
{ default: () => "编辑" }
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "delete",
|
key: "delete",
|
||||||
render: () =>
|
render: (row) =>
|
||||||
h(
|
h(DeleteProblem, { problemID: row.id, onDeleted: listProblems }),
|
||||||
NButton,
|
|
||||||
{ type: "error", size: "small", tertiary: true },
|
|
||||||
{ default: () => "删除" }
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "download",
|
key: "download",
|
||||||
render: () =>
|
render: (row) => h(DownloadTestcases, { problemID: row.id }),
|
||||||
h(NButton, { size: "small", tertiary: true }, { default: () => "下载" }),
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -63,15 +77,26 @@ async function listProblems() {
|
|||||||
problems.value = res.results
|
problems.value = res.results
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(listProblems)
|
// 这里比较傻逼,因为我传进来的时候 filter 了而且只有 edit problem 一个接口,所以只能先 get 再 edit
|
||||||
|
async function toggleVisible(problemID: number) {
|
||||||
|
const res = await getProblem(problemID)
|
||||||
|
await editProblem({ ...res.data, visible: !res.data.visible })
|
||||||
|
problems.value = problems.value.map((it) => {
|
||||||
|
if (it.id === problemID) {
|
||||||
|
it.visible = !it.visible
|
||||||
|
}
|
||||||
|
return it
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(listProblems)
|
||||||
watch(query, listProblems, { deep: true })
|
watch(query, listProblems, { deep: true })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-form inline label-placement="left">
|
<n-form inline label-placement="left">
|
||||||
<n-form-item label="标题">
|
<n-form-item>
|
||||||
<n-input v-model:value="query.keyword" />
|
<n-input v-model:value="query.keyword" placeholder="输入标题关键字" />
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
</n-form>
|
</n-form>
|
||||||
<n-data-table striped size="small" :columns="columns" :data="problems" />
|
<n-data-table striped size="small" :columns="columns" :data="problems" />
|
||||||
|
|||||||
37
src/components.d.ts
vendored
37
src/components.d.ts
vendored
@@ -9,29 +9,31 @@ export {}
|
|||||||
|
|
||||||
declare module '@vue/runtime-core' {
|
declare module '@vue/runtime-core' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
IEpBell: typeof import('~icons/ep/bell')['default']
|
IEpBell: typeof import("~icons/ep/bell")["default"]
|
||||||
IEpCaretRight: typeof import('~icons/ep/caret-right')['default']
|
IEpCaretRight: typeof import("~icons/ep/caret-right")["default"]
|
||||||
IEpLoading: typeof import('~icons/ep/loading')['default']
|
IEpLoading: typeof import("~icons/ep/loading")["default"]
|
||||||
IEpLock: typeof import('~icons/ep/lock')['default']
|
IEpLock: typeof import("~icons/ep/lock")["default"]
|
||||||
IEpMenu: typeof import('~icons/ep/menu')['default']
|
IEpMenu: typeof import('~icons/ep/menu')['default']
|
||||||
IEpMoon: typeof import('~icons/ep/moon')['default']
|
IEpMoon: typeof import('~icons/ep/moon')['default']
|
||||||
IEpMoreFilled: typeof import('~icons/ep/more-filled')['default']
|
IEpMoreFilled: typeof import("~icons/ep/more-filled")["default"]
|
||||||
IEpSunny: typeof import('~icons/ep/sunny')['default']
|
IEpSunny: typeof import('~icons/ep/sunny')['default']
|
||||||
NAlert: typeof import('naive-ui')['NAlert']
|
NAlert: typeof import('naive-ui')['NAlert']
|
||||||
NAvatar: typeof import("naive-ui")["NAvatar"]
|
NAvatar: typeof import("naive-ui")["NAvatar"]
|
||||||
|
NBreadcrumb: typeof import('naive-ui')['NBreadcrumb']
|
||||||
|
NBreadcrumbItem: typeof import('naive-ui')['NBreadcrumbItem']
|
||||||
NButton: typeof import('naive-ui')['NButton']
|
NButton: typeof import('naive-ui')['NButton']
|
||||||
NCard: typeof import('naive-ui')['NCard']
|
NCard: typeof import("naive-ui")["NCard"]
|
||||||
NCode: typeof import("naive-ui")["NCode"]
|
NCode: typeof import("naive-ui")["NCode"]
|
||||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NDataTable: typeof import('naive-ui')['NDataTable']
|
NDataTable: typeof import('naive-ui')['NDataTable']
|
||||||
NDescriptions: typeof import('naive-ui')['NDescriptions']
|
NDescriptions: typeof import("naive-ui")["NDescriptions"]
|
||||||
NDescriptionsItem: typeof import('naive-ui')['NDescriptionsItem']
|
NDescriptionsItem: typeof import("naive-ui")["NDescriptionsItem"]
|
||||||
NDropdown: typeof import('naive-ui')['NDropdown']
|
NDropdown: typeof import('naive-ui')['NDropdown']
|
||||||
NEmpty: typeof import('naive-ui')['NEmpty']
|
NEmpty: typeof import("naive-ui")["NEmpty"]
|
||||||
NForm: typeof import('naive-ui')['NForm']
|
NForm: typeof import('naive-ui')['NForm']
|
||||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||||
NGi: typeof import('naive-ui')['NGi']
|
NGi: typeof import("naive-ui")["NGi"]
|
||||||
NGrid: typeof import('naive-ui')['NGrid']
|
NGrid: typeof import("naive-ui")["NGrid"]
|
||||||
NIcon: typeof import('naive-ui')['NIcon']
|
NIcon: typeof import('naive-ui')['NIcon']
|
||||||
NInput: typeof import('naive-ui')['NInput']
|
NInput: typeof import('naive-ui')['NInput']
|
||||||
NLayout: typeof import('naive-ui')['NLayout']
|
NLayout: typeof import('naive-ui')['NLayout']
|
||||||
@@ -42,14 +44,15 @@ declare module '@vue/runtime-core' {
|
|||||||
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
|
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
|
||||||
NModal: typeof import('naive-ui')['NModal']
|
NModal: typeof import('naive-ui')['NModal']
|
||||||
NPagination: typeof import('naive-ui')['NPagination']
|
NPagination: typeof import('naive-ui')['NPagination']
|
||||||
NPopover: typeof import('naive-ui')['NPopover']
|
NPopconfirm: typeof import('naive-ui')['NPopconfirm']
|
||||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
NPopover: typeof import("naive-ui")["NPopover"]
|
||||||
|
NScrollbar: typeof import("naive-ui")["NScrollbar"]
|
||||||
NSelect: typeof import('naive-ui')['NSelect']
|
NSelect: typeof import('naive-ui')['NSelect']
|
||||||
NSpace: typeof import('naive-ui')['NSpace']
|
NSpace: typeof import('naive-ui')['NSpace']
|
||||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
NSwitch: typeof import("naive-ui")["NSwitch"]
|
||||||
NTabPane: typeof import('naive-ui')['NTabPane']
|
NTabPane: typeof import("naive-ui")["NTabPane"]
|
||||||
NTabs: typeof import('naive-ui')['NTabs']
|
NTabs: typeof import("naive-ui")["NTabs"]
|
||||||
NTag: typeof import('naive-ui')['NTag']
|
NTag: typeof import("naive-ui")["NTag"]
|
||||||
NTooltip: typeof import('naive-ui')['NTooltip']
|
NTooltip: typeof import('naive-ui')['NTooltip']
|
||||||
NUpload: typeof import("naive-ui")["NUpload"]
|
NUpload: typeof import("naive-ui")["NUpload"]
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export const routes: RouteRecordRaw[] = [
|
|||||||
component: () => import("admin/problem/detail.vue"),
|
component: () => import("admin/problem/detail.vue"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "problem/:problemID/edit",
|
path: "problem/edit/:problemID",
|
||||||
name: "problem edit",
|
name: "problem edit",
|
||||||
component: () => import("admin/problem/detail.vue"),
|
component: () => import("admin/problem/detail.vue"),
|
||||||
props: true,
|
props: true,
|
||||||
@@ -156,7 +156,7 @@ export const routes: RouteRecordRaw[] = [
|
|||||||
component: () => import("admin/contest/detail.vue"),
|
component: () => import("admin/contest/detail.vue"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "contest/:contestID/edit",
|
path: "contest/edit/:contestID",
|
||||||
name: "contest edit",
|
name: "contest edit",
|
||||||
component: () => import("admin/contest/detail.vue"),
|
component: () => import("admin/contest/detail.vue"),
|
||||||
props: true,
|
props: true,
|
||||||
@@ -174,7 +174,7 @@ export const routes: RouteRecordRaw[] = [
|
|||||||
props: true,
|
props: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "contest/:contestID/problem/:problemID/edit",
|
path: "contest/:contestID/problem/edit/:problemID",
|
||||||
name: "contest problem edit",
|
name: "contest problem edit",
|
||||||
component: () => import("admin/problem/detail.vue"),
|
component: () => import("admin/problem/detail.vue"),
|
||||||
props: true,
|
props: true,
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ const active = computed(() => (route.name as string) || "home")
|
|||||||
<n-layout-sider bordered :native-scrollbar="false">
|
<n-layout-sider bordered :native-scrollbar="false">
|
||||||
<n-menu :options="options" :value="active" />
|
<n-menu :options="options" :value="active" />
|
||||||
</n-layout-sider>
|
</n-layout-sider>
|
||||||
<n-layout-content :native-scrollbar="false" content-style="padding: 16px">
|
<n-layout-content content-style="padding: 16px">
|
||||||
<router-view></router-view>
|
<router-view></router-view>
|
||||||
</n-layout-content>
|
</n-layout-content>
|
||||||
</n-layout>
|
</n-layout>
|
||||||
|
|||||||
Reference in New Issue
Block a user