|
@@ -1,60 +1,68 @@
|
|
|
// src/services/api.ts
|
|
|
|
|
|
-import http from './http';
|
|
|
+import http from './http'
|
|
|
|
|
|
// 定义接口类型
|
|
|
interface User {
|
|
|
- id: number;
|
|
|
- name: string;
|
|
|
- email: string;
|
|
|
+ id: number
|
|
|
+ name: string
|
|
|
+ email: string
|
|
|
}
|
|
|
|
|
|
// 登陆
|
|
|
export const loginUser = async (params): Promise<User[]> => {
|
|
|
- const response = await http.post<User[]>('/api/v1/login', params);
|
|
|
- return response.data;
|
|
|
-};
|
|
|
+ const response = await http.post<User[]>('/api/v1/login', params)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
// 获取用户列表
|
|
|
export const getUserInfo = async (): Promise<User[]> => {
|
|
|
- const response = await http.post<User[]>('/api/v1/auth/user_info');
|
|
|
- return response.data;
|
|
|
-};
|
|
|
+ const response = await http.post<User[]>('/api/v1/auth/user_info')
|
|
|
+ return response.data
|
|
|
+}
|
|
|
|
|
|
// 获取单个用户
|
|
|
export const fetchUserById = async (id: number): Promise<User> => {
|
|
|
- const response = await http.get<User>(`/users/${id}`);
|
|
|
- return response.data;
|
|
|
-};
|
|
|
+ const response = await http.get<User>(`/users/${id}`)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
|
|
|
// 创建新用户
|
|
|
export const createUser = async (user: Omit<User, 'id'>): Promise<User> => {
|
|
|
- const response = await http.post<User>('/users', user);
|
|
|
- return response.data;
|
|
|
-};
|
|
|
+ const response = await http.post<User>('/users', user)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
|
|
|
// 更新用户
|
|
|
-export const updateUser = async (id: number, user: Partial<User>): Promise<User> => {
|
|
|
- const response = await http.put<User>(`/users/${id}`, user);
|
|
|
- return response.data;
|
|
|
-};
|
|
|
+export const updateUser = async (
|
|
|
+ id: number,
|
|
|
+ user: Partial<User>
|
|
|
+): Promise<User> => {
|
|
|
+ const response = await http.put<User>(`/users/${id}`, user)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
|
|
|
// 删除用户
|
|
|
export const deleteUser = async (id: number): Promise<void> => {
|
|
|
- await http.delete(`/users/${id}`);
|
|
|
-};
|
|
|
+ await http.delete(`/users/${id}`)
|
|
|
+}
|
|
|
|
|
|
// 上传文件
|
|
|
-export const uploadFile = async (sampleFile:File): Promise<void> => {
|
|
|
+export const uploadFile = async (sampleFile: File): Promise<void> => {
|
|
|
return await http.put(`/api/v1/files/`, sampleFile, {
|
|
|
headers: {
|
|
|
- 'Content-Type': 'multipart/form-data',
|
|
|
- },
|
|
|
- });
|
|
|
-};
|
|
|
+ 'Content-Type': 'multipart/form-data'
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
+// 获取所有账本
|
|
|
+export const getAllBook = async (id: number): Promise<User> => {
|
|
|
+ const response = await http.get<User>(`/api/v1/books`)
|
|
|
+ return response.data
|
|
|
+}
|
|
|
|
|
|
// 获取账本数据
|
|
|
export const getBookInfo = async (id: number): Promise<User> => {
|
|
|
- const response = await http.get<User>(`/api/v1/books/${id}`);
|
|
|
- return response.data;
|
|
|
-};
|
|
|
+ const response = await http.get<User>(`/api/v1/books/${id}`)
|
|
|
+ return response.data
|
|
|
+}
|