monaco-editor-lsp-next/src/api/user.ts
liguang 6bd06929a7 feat(admin): 新增管理员管理功能
- 新增管理员管理页面和相关 API
- 实现管理员用户的增删改查功能
- 添加用户管理相关的 API 和页面组件
- 更新 VSCode 设置,添加数据库连接配置
2025-06-18 17:52:42 +08:00

40 lines
1.3 KiB
TypeScript

import type { UserBase } from "@/types/user";
// 获取所有用户
export async function getUsers(userType: string): Promise<UserBase[]> {
const res = await fetch(`/api/${userType}`);
if (!res.ok) throw new Error("获取用户失败");
return res.json();
}
// 新建用户
export async function createUser(userType: string, data: Partial<UserBase>): Promise<UserBase> {
const res = await fetch(`/api/${userType}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!res.ok) throw new Error("新建用户失败");
return res.json();
}
// 更新用户
export async function updateUser(userType: string, data: Partial<UserBase>): Promise<UserBase> {
const res = await fetch(`/api/${userType}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!res.ok) throw new Error("更新用户失败");
return res.json();
}
// 删除用户
export async function deleteUser(userType: string, id: string): Promise<void> {
const res = await fetch(`/api/${userType}`, {
method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id }),
});
if (!res.ok) throw new Error("删除用户失败");
}