1 parent
af63b05d4b
commit
bde387e8bc
3 files changed
+20
-3
No files matched your search
@@ -384,7 +384,13 @@ adminProblemRoutes.get("/problems", requireProblemPermission, async (c) => {
|
|||||||
const offset = queryInteger(c.req.query("offset"), 0, { min: 0 })
|
const offset = queryInteger(c.req.query("offset"), 0, { min: 0 })
|
||||||
const user = c.get("user")!
|
const user = c.get("user")!
|
||||||
const filters = [isNull(schema.problem.contestId)]
|
const filters = [isNull(schema.problem.contestId)]
|
||||||
if (!canManageAll(user)) filters.push(eq(schema.problem.createdById, user.id))
|
// library=1 是比赛的「从题库中选择」:要列的是 from-public 实际放行的范围 —— 所有可见的
|
||||||
|
// 公开题,加上自己能改的。只按 created_by 过滤的话,「仅管理自己创建」的老师一道题都看不到
|
||||||
|
const library = c.req.query("library") === "1"
|
||||||
|
if (!canManageAll(user)) {
|
||||||
|
const own = eq(schema.problem.createdById, user.id)
|
||||||
|
filters.push(library ? or(eq(schema.problem.visible, true), own)! : own)
|
||||||
|
}
|
||||||
const author = c.req.query("author")?.trim()
|
const author = c.req.query("author")?.trim()
|
||||||
const keyword = c.req.query("keyword")?.trim()
|
const keyword = c.req.query("keyword")?.trim()
|
||||||
const tagId = c.req.query("tagId")?.trim()
|
const tagId = c.req.query("tagId")?.trim()
|
||||||
|
|||||||
@@ -74,6 +74,17 @@ export async function getProblemList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 比赛「从题库中选择」用:列所有可见的公开题,不只是自己创建的
|
||||||
|
export async function getLibraryProblemList(offset = 0, limit = 10, keyword: string) {
|
||||||
|
const res = await api.get<AdminProblemList>("admin/problems", {
|
||||||
|
params: { offset, limit, keyword, library: 1 },
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
results: res.results.map(toAdminProblemRow),
|
||||||
|
total: res.total,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function deleteProblem(id: number) {
|
export function deleteProblem(id: number) {
|
||||||
return api.delete(`admin/problems/${id}`)
|
return api.delete(`admin/problems/${id}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { getProblemList } from "admin/api"
|
import { getLibraryProblemList } from "admin/api"
|
||||||
import Pagination from "shared/components/Pagination.vue"
|
import Pagination from "shared/components/Pagination.vue"
|
||||||
import type { AdminProblemRow } from "utils/types"
|
import type { AdminProblemRow } from "utils/types"
|
||||||
import AddButton from "./AddButton.vue"
|
import AddButton from "./AddButton.vue"
|
||||||
@@ -44,7 +44,7 @@ const columns: DataTableColumn<AdminProblemRow>[] = [
|
|||||||
|
|
||||||
async function getList() {
|
async function getList() {
|
||||||
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 getLibraryProblemList(offset, query.limit, query.keyword)
|
||||||
total.value = res.total
|
total.value = res.total
|
||||||
problems.value = res.results
|
problems.value = res.results
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user