Skip to content

Commit

Permalink
Feat: unset admin
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyCreeper committed Nov 16, 2023
1 parent f0b754a commit 0457d9d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
16 changes: 15 additions & 1 deletion src/services/apis/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@ export const addAdminApi = useDefineApi<
method: "POST"
});

// TODO: 取消管理员身份
// 取消管理员身份
export const delAdminApi = useDefineApi<
{
headers: {
Authorization: string;
};
data: {
id: string;
};
},
any
>({
url: "/api/admin/admin/delete",
method: "POST"
});

// 获取用户列表
export const userListApi = useDefineApi<
Expand Down
25 changes: 14 additions & 11 deletions src/views/admin/settings/UserManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
import { onMounted, ref } from "vue";
import { ElNotification, ElMessage } from "element-plus";
import { userStore } from "@/stores/user";
import { userListApi, banUserApi, unBanUserApi, addAdminApi } from "@/services/apis/admin";
import {
userListApi,
banUserApi,
unBanUserApi,
addAdminApi,
delAdminApi
} from "@/services/apis/admin";
import { ROLE, role } from "@/types/User";
const props = defineProps<{
Expand Down Expand Up @@ -102,18 +108,18 @@ const unBanUser = async (id: string) => {
}
};
// 设为管理
const setAdmin = async (id: string) => {
const { execute } = addAdminApi();
// 设管理
const setAdmin = async (id: string, is: boolean) => {
try {
await execute({
const config = {
headers: {
Authorization: token.value
},
data: {
id: id
}
});
};
is ? await addAdminApi().execute(config) : await delAdminApi().execute(config);
ElNotification({
title: "设置成功",
type: "success"
Expand All @@ -129,9 +135,6 @@ const setAdmin = async (id: string) => {
}
};
// 取消管理身份
const unsetAdmin = async (id: string) => {};
onMounted(async () => {
await getUserListApi();
});
Expand Down Expand Up @@ -170,10 +173,10 @@ onMounted(async () => {
<el-dropdown-item v-else @click="unBanUser(scope.row.id)">解封</el-dropdown-item>
<el-dropdown-item
v-if="scope.row.role < ROLE.Admin"
@click="setAdmin(scope.row.id)"
@click="setAdmin(scope.row.id, true)"
>设为管理</el-dropdown-item
>
<el-dropdown-item v-else @click="unsetAdmin(scope.row.id)"
<el-dropdown-item v-else @click="setAdmin(scope.row.id, false)"
>取消管理身份</el-dropdown-item
>
</el-dropdown-menu>
Expand Down

0 comments on commit 0457d9d

Please sign in to comment.