From efbc21ba18bb10c4ac2d4e9ce59efda797e4dc96 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Mon, 20 Mar 2023 13:53:18 +0800 Subject: [PATCH] edit user. --- src/admin/api.ts | 10 +- src/admin/problem/components/Actions.vue | 6 +- src/admin/user/components/Actions.vue | 37 +++++- src/admin/user/{import.vue => importing.vue} | 0 src/admin/user/list.vue | 126 ++++++++++++++++++- src/components.d.ts | 1 + src/routes.ts | 2 +- src/shared/Login.vue | 18 +-- src/utils/types.ts | 1 + 9 files changed, 181 insertions(+), 20 deletions(-) rename src/admin/user/{import.vue => importing.vue} (100%) diff --git a/src/admin/api.ts b/src/admin/api.ts index df84220..ebaf74a 100644 --- a/src/admin/api.ts +++ b/src/admin/api.ts @@ -1,5 +1,5 @@ import http from "utils/http" -import { Problem } from "~/utils/types" +import { Problem, User } from "~/utils/types" export async function getProblemList(offset = 0, limit = 10, keyword: string) { const res = await http.get("admin/problem", { @@ -35,3 +35,11 @@ export function getUserList(offset = 0, limit = 10, keyword: string) { params: { paging: true, offset, limit, keyword }, }) } + +export function deleteUsers(userIDs: number[]) { + return http.delete("admin/user", { params: { id: userIDs.join(",") } }) +} + +export function editUser(user: User & { password: string }) { + return http.put("admin/user", user) +} diff --git a/src/admin/problem/components/Actions.vue b/src/admin/problem/components/Actions.vue index 8ea043e..1e6fbc6 100644 --- a/src/admin/problem/components/Actions.vue +++ b/src/admin/problem/components/Actions.vue @@ -10,8 +10,8 @@ const emit = defineEmits(["deleted"]) const router = useRouter() const message = useMessage() -async function handleDeleteProblem(problemID: number) { - await deleteProblem(problemID) +async function handleDeleteProblem() { + await deleteProblem(props.problemID) message.success("删除成功") emit("deleted") } @@ -32,7 +32,7 @@ function goEdit() { 编辑 - + diff --git a/src/admin/user/components/Actions.vue b/src/admin/user/components/Actions.vue index 251e991..f871262 100644 --- a/src/admin/user/components/Actions.vue +++ b/src/admin/user/components/Actions.vue @@ -1,15 +1,46 @@ diff --git a/src/admin/user/import.vue b/src/admin/user/importing.vue similarity index 100% rename from src/admin/user/import.vue rename to src/admin/user/importing.vue diff --git a/src/admin/user/list.vue b/src/admin/user/list.vue index 43a8e8b..349f89f 100644 --- a/src/admin/user/list.vue +++ b/src/admin/user/list.vue @@ -1,26 +1,39 @@ @@ -63,13 +129,63 @@ watch(query, listUsers, { deep: true }) + + + + 确定删除这个用户吗?删除后无法恢复! + + - + + + + + + + + + + + + + + + + + + + + + 封号 + + + + 取消 + 保存 + + + diff --git a/src/components.d.ts b/src/components.d.ts index defb5ef..3a0c7f9 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -32,6 +32,7 @@ declare module '@vue/runtime-core' { NEmpty: typeof import('naive-ui')['NEmpty'] NForm: typeof import('naive-ui')['NForm'] NFormItem: typeof import('naive-ui')['NFormItem'] + NFormItemGi: typeof import('naive-ui')['NFormItemGi'] NGi: typeof import('naive-ui')['NGi'] NGrid: typeof import('naive-ui')['NGrid'] NIcon: typeof import('naive-ui')['NIcon'] diff --git a/src/routes.ts b/src/routes.ts index 8dd4f9a..182e783 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -127,7 +127,7 @@ export const routes: RouteRecordRaw[] = [ { path: "user/importing", name: "admin user importing", - component: () => import("admin/user/import.vue"), + component: () => import("~/admin/user/importing.vue"), }, { path: "problem/list", diff --git a/src/shared/Login.vue b/src/shared/Login.vue index 9b41765..0fd6f80 100644 --- a/src/shared/Login.vue +++ b/src/shared/Login.vue @@ -7,7 +7,7 @@ import type { FormRules } from "naive-ui" const userStore = useUserStore() const loginRef = ref() const [isLoading] = useToggle() -const error = ref() +const msg = ref("") const form = reactive({ username: "", password: "", @@ -20,21 +20,25 @@ const rules: FormRules = { ], } -const msg = computed(() => error.value && "用户名或密码不正确") - async function submit() { loginRef.value?.validate(async (errors: FormRules | undefined) => { if (!errors) { try { - error.value = null + msg.value = "" isLoading.value = true await login(form) - } catch (err) { - error.value = err + } catch (err: any) { + if (err.data === "Your account has been disabled") { + msg.value = "此账号已被封禁" + } else if (err.data === "Invalid username or password") { + msg.value = "用户名或密码不正确" + } else { + msg.value = "无法登录" + } } finally { isLoading.value = false } - if (!error.value) { + if (!msg.value) { toggleLogin(false) userStore.getMyProfile() } diff --git a/src/utils/types.ts b/src/utils/types.ts index 9491ff2..01590d9 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -36,6 +36,7 @@ export interface Profile { export interface User { id: number username: string + real_name: string email: string admin_type: "Regular User" | "Super Admin" | "Admin" problem_permission: string