fix admin.
This commit is contained in:
47
src/admin/api.ts
Normal file
47
src/admin/api.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import http from "utils/http"
|
||||
import { DIFFICULTY } from "~/utils/constants"
|
||||
import { getACRate } from "~/utils/functions"
|
||||
import { Problem } from "~/utils/types"
|
||||
|
||||
function filterResult(result: Problem) {
|
||||
const newResult = {
|
||||
id: result.id,
|
||||
_id: result._id,
|
||||
title: result.title,
|
||||
difficulty: DIFFICULTY[result.difficulty],
|
||||
tags: result.tags,
|
||||
submission: result.submission_number,
|
||||
rate: getACRate(result.accepted_number, result.submission_number),
|
||||
status: "",
|
||||
}
|
||||
if (result.my_status === null || result.my_status === undefined) {
|
||||
newResult.status = "not_test"
|
||||
} else if (result.my_status === 0) {
|
||||
newResult.status = "passed"
|
||||
} else {
|
||||
newResult.status = "failed"
|
||||
}
|
||||
return newResult
|
||||
}
|
||||
|
||||
export async function getProblemList(
|
||||
offset = 0,
|
||||
limit = 10,
|
||||
searchParams: any = {}
|
||||
) {
|
||||
let params: any = {
|
||||
paging: true,
|
||||
offset,
|
||||
limit,
|
||||
}
|
||||
Object.keys(searchParams).forEach((element) => {
|
||||
if (searchParams[element]) {
|
||||
params[element] = searchParams[element]
|
||||
}
|
||||
})
|
||||
const res = await http.get("admin/problem", { params })
|
||||
return {
|
||||
results: res.data.results.map(filterResult),
|
||||
total: res.data.total,
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<script setup lang="ts"></script>
|
||||
|
||||
<template>
|
||||
<div class="container">1213</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
height: 200vh;
|
||||
}
|
||||
</style>
|
||||
@@ -1,7 +1,40 @@
|
||||
<script setup lang="ts"></script>
|
||||
<script setup lang="ts">
|
||||
import { getProblemList } from "../api"
|
||||
import Pagination from "~/shared/Pagination.vue"
|
||||
import { DataTableColumn } from "naive-ui"
|
||||
import { ProblemFiltered } from "~/utils/types"
|
||||
|
||||
const total = ref(0)
|
||||
const problems = ref([])
|
||||
const query = reactive({
|
||||
limit: 10,
|
||||
page: 1,
|
||||
keyword: "",
|
||||
})
|
||||
|
||||
const columns: DataTableColumn<ProblemFiltered>[] = [
|
||||
{ title: "编号", key: "_id", width: 100 },
|
||||
]
|
||||
|
||||
async function listProblems() {
|
||||
const offset = (query.page - 1) * query.limit
|
||||
const res = await getProblemList(offset, query.limit, {
|
||||
keyword: query.keyword,
|
||||
})
|
||||
total.value = res.total
|
||||
problems.value = res.results
|
||||
}
|
||||
|
||||
onMounted(listProblems)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>problem list</div>
|
||||
<n-data-table :columns="columns" :data="problems" />
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:limit="query.limit"
|
||||
v-model:page="query.page"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
|
||||
7
src/admin/setting/home.vue
Normal file
7
src/admin/setting/home.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<script setup lang="ts"></script>
|
||||
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
Reference in New Issue
Block a user