完整API模块结构:
client/admin/api/ ├── auth.ts (认证API) ├── users.ts (用户API) ├── files.ts (文件API) ├── theme.ts (主题API) ├── charts.ts (图表API) ├── messages.ts (消息API) ├── sys.ts (系统API) ├── know_info.ts (知识库API) ├── maps.ts (地图API) └── index.ts (统一入口)
This commit is contained in:
81
client/admin/api/users.ts
Normal file
81
client/admin/api/users.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import axios from 'axios';
|
||||
import type { User } from '../../share/types.ts';
|
||||
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
interface UsersResponse {
|
||||
data: User[];
|
||||
pagination: {
|
||||
total: number;
|
||||
current: number;
|
||||
pageSize: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface UserResponse {
|
||||
data: User;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
interface UserCreateResponse {
|
||||
message: string;
|
||||
data: User;
|
||||
}
|
||||
|
||||
interface UserUpdateResponse {
|
||||
message: string;
|
||||
data: User;
|
||||
}
|
||||
|
||||
interface UserDeleteResponse {
|
||||
message: string;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export const UserAPI = {
|
||||
getUsers: async (params?: { page?: number, limit?: number, search?: string }): Promise<UsersResponse> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/users`, { params });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
getUser: async (userId: number): Promise<UserResponse> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/users/${userId}`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
createUser: async (userData: Partial<User>): Promise<UserCreateResponse> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/users`, userData);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
updateUser: async (userId: number, userData: Partial<User>): Promise<UserUpdateResponse> => {
|
||||
try {
|
||||
const response = await axios.put(`${API_BASE_URL}/users/${userId}`, userData);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
deleteUser: async (userId: number): Promise<UserDeleteResponse> => {
|
||||
try {
|
||||
const response = await axios.delete(`${API_BASE_URL}/users/${userId}`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user