update
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
2025-09-25 20:48:09 +08:00
parent f7b8ef8978
commit 4ff5822ef8
3 changed files with 35 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { USER_TYPE } from "~/utils/constants" import { PROBLEM_PERMISSION, USER_TYPE } from "~/utils/constants"
import { getUserRole } from "~/utils/functions" import { getUserRole } from "~/utils/functions"
import { User } from "~/utils/types" import { User } from "~/utils/types"
@@ -21,7 +21,14 @@ const isNotRegularUser = computed(
:type="getUserRole(props.user.admin_type).type" :type="getUserRole(props.user.admin_type).type"
size="small" size="small"
> >
{{ getUserRole(props.user.admin_type).tagString }} {{ getUserRole(props.user.admin_type).label }}
</n-tag>
<n-tag size="small" v-if="props.user.admin_type === USER_TYPE.ADMIN">
{{
props.user.problem_permission === PROBLEM_PERMISSION.ALL
? "全部"
: "仅自己"
}}
</n-tag> </n-tag>
{{ props.user.username }} {{ props.user.username }}
</n-flex> </n-flex>

View File

@@ -12,7 +12,7 @@ import {
} from "../api" } from "../api"
import Actions from "./components/Actions.vue" import Actions from "./components/Actions.vue"
import Name from "./components/Name.vue" import Name from "./components/Name.vue"
import { USER_TYPE } from "~/utils/constants" import { PROBLEM_PERMISSION, USER_TYPE } from "~/utils/constants"
const message = useMessage() const message = useMessage()
const router = useRouter() const router = useRouter()
@@ -41,11 +41,11 @@ const rowKey = (row: User) => row.id
const columns: DataTableColumn<User>[] = [ const columns: DataTableColumn<User>[] = [
{ type: "selection" }, { type: "selection" },
{ title: "ID", key: "id", width: 100 }, { title: "ID", key: "id", width: 80 },
{ {
title: "用户名", title: "用户名",
key: "username", key: "username",
width: 200, width: 220,
render: (row) => h(Name, { user: row }), render: (row) => h(Name, { user: row }),
}, },
{ {
@@ -91,6 +91,12 @@ const options: SelectOption[] = [
{ label: "超级管理员", value: USER_TYPE.SUPER_ADMIN }, { label: "超级管理员", value: USER_TYPE.SUPER_ADMIN },
] ]
const problemPermissionOptions: SelectOption[] = [
{ label: "无权限", value: PROBLEM_PERMISSION.NONE },
{ label: "仅管理自己创建", value: PROBLEM_PERMISSION.OWN },
{ label: "管理全部题目", value: PROBLEM_PERMISSION.ALL },
]
function routerPush() { function routerPush() {
router.push({ router.push({
path: route.path, path: route.path,
@@ -147,8 +153,8 @@ function createNewUser() {
username: "", username: "",
real_name: "", real_name: "",
email: "", email: "",
admin_type: "Super Admin", admin_type: "Admin",
problem_permission: "", problem_permission: "None",
create_time: new Date(), create_time: new Date(),
last_login: new Date(), last_login: new Date(),
two_factor_auth: false, two_factor_auth: false,
@@ -294,6 +300,17 @@ watch(
<n-form-item-gi v-if="!create" :span="1" label="类型"> <n-form-item-gi v-if="!create" :span="1" label="类型">
<n-select v-model:value="userEditing.admin_type" :options="options" /> <n-select v-model:value="userEditing.admin_type" :options="options" />
</n-form-item-gi> </n-form-item-gi>
<n-form-item-gi
v-if="!create && userEditing.admin_type === USER_TYPE.ADMIN"
:span="1"
label="出题权限"
>
<n-select
v-model:value="userEditing.problem_permission"
:options="problemPermissionOptions"
/>
</n-form-item-gi>
<n-form-item-gi v-if="!create" :span="1" label="是否封禁"> <n-form-item-gi v-if="!create" :span="1" label="是否封禁">
<n-switch v-model:value="userEditing.is_disabled">封号</n-switch> <n-switch v-model:value="userEditing.is_disabled">封号</n-switch>
</n-form-item-gi> </n-form-item-gi>

View File

@@ -131,17 +131,17 @@ export function debounce<T extends (...args: any[]) => any>(
export function getUserRole(role: User["admin_type"]): { export function getUserRole(role: User["admin_type"]): {
type: "default" | "info" | "error" type: "default" | "info" | "error"
tagString: "普通" | "管理员" | "超管" label: "普通" | "管理员" | "超管"
} { } {
const roleMap = { const roleMap = {
[USER_TYPE.REGULAR_USER]: { [USER_TYPE.REGULAR_USER]: {
type: "default" as const, type: "default" as const,
tagString: "普通" as const, label: "普通" as const,
}, },
[USER_TYPE.ADMIN]: { type: "info" as const, tagString: "管理员" as const }, [USER_TYPE.ADMIN]: { type: "info" as const, label: "管理员" as const },
[USER_TYPE.SUPER_ADMIN]: { [USER_TYPE.SUPER_ADMIN]: {
type: "error" as const, type: "error" as const,
tagString: "超管" as const, label: "超管" as const,
}, },
} }