refactor: adapt to api changes of web service

This commit is contained in:
2025-11-12 11:35:31 +08:00
parent 86ad54cccb
commit c61a106373
4 changed files with 37 additions and 6 deletions

View File

@@ -91,6 +91,7 @@ import {
getPeoples,
searchPeoples,
deletePeople,
updatePeople,
getPeoplesPaginated
} from '@/apis';
@@ -154,6 +155,20 @@ const removePeople = async (peopleId: string) => {
console.error('删除失败:', error);
}
};
// 更新人员
const updateOnePeople = async (peopleId: string) => {
const peopleData = {
name: '李四',
age: 28,
};
try {
const response = await updatePeople(peopleId, peopleData);
console.log('更新成功:', response);
} catch (error) {
console.error('更新失败:', error);
}
};
```
## 错误处理

View File

@@ -10,8 +10,11 @@ export const API_CONFIG = {
// API 端点
export const API_ENDPOINTS = {
INPUT: '/input',
INPUT_IMAGE: '/input_image',
INPUT: '/recognition/input',
INPUT_IMAGE: '/recognition/image',
// 人员列表查询仍为 /peoples
PEOPLES: '/peoples',
PEOPLE_BY_ID: (id: string) => `/peoples/${id}`,
// 新增单个资源路径 /people
PEOPLE: '/people',
PEOPLE_BY_ID: (id: string) => `/people/${id}`,
} as const;

View File

@@ -1,6 +1,6 @@
// 人员管理相关 API
import { get, post, del } from './request';
import { get, post, del, put } from './request';
import { API_ENDPOINTS } from './config';
import type {
PostPeopleRequest,
@@ -18,7 +18,8 @@ import type {
export async function createPeople(people: People): Promise<ApiResponse> {
const requestData: PostPeopleRequest = { people };
console.log('创建人员请求数据:', requestData);
return post<ApiResponse>(API_ENDPOINTS.PEOPLES, requestData);
// 创建接口改为 /people
return post<ApiResponse>(API_ENDPOINTS.PEOPLE, requestData);
}
/**
@@ -109,6 +110,17 @@ export async function deletePeople(peopleId: string): Promise<ApiResponse> {
return del<ApiResponse>(API_ENDPOINTS.PEOPLE_BY_ID(peopleId));
}
/**
* 更新人员信息
* @param peopleId 人员ID
* @param people 人员信息对象
* @returns Promise<ApiResponse>
*/
export async function updatePeople(peopleId: string, people: People): Promise<ApiResponse> {
const requestData: PostPeopleRequest = { people };
return put<ApiResponse>(API_ENDPOINTS.PEOPLE_BY_ID(peopleId), requestData);
}
/**
* 批量创建人员信息
* @param peopleList 人员信息数组

View File

@@ -34,7 +34,8 @@ export async function postInputImageWithProgress(
}
const formData = new FormData();
formData.append('file', file);
// 后端要求字段名为 image
formData.append('image', file);
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();