From c61a106373aea15e12d24a45836cfbce792325d4 Mon Sep 17 00:00:00 2001 From: mamamiyear Date: Wed, 12 Nov 2025 11:35:31 +0800 Subject: [PATCH] refactor: adapt to api changes of web service --- src/apis/README.md | 15 +++++++++++++++ src/apis/config.ts | 9 ++++++--- src/apis/people.ts | 16 ++++++++++++++-- src/apis/upload.ts | 3 ++- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/apis/README.md b/src/apis/README.md index 80a7610..d9469b9 100644 --- a/src/apis/README.md +++ b/src/apis/README.md @@ -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); + } +}; ``` ## 错误处理 diff --git a/src/apis/config.ts b/src/apis/config.ts index 20f8397..d16a397 100644 --- a/src/apis/config.ts +++ b/src/apis/config.ts @@ -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; \ No newline at end of file diff --git a/src/apis/people.ts b/src/apis/people.ts index d4a9e73..1155989 100644 --- a/src/apis/people.ts +++ b/src/apis/people.ts @@ -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 { const requestData: PostPeopleRequest = { people }; console.log('创建人员请求数据:', requestData); - return post(API_ENDPOINTS.PEOPLES, requestData); + // 创建接口改为 /people + return post(API_ENDPOINTS.PEOPLE, requestData); } /** @@ -109,6 +110,17 @@ export async function deletePeople(peopleId: string): Promise { return del(API_ENDPOINTS.PEOPLE_BY_ID(peopleId)); } +/** + * 更新人员信息 + * @param peopleId 人员ID + * @param people 人员信息对象 + * @returns Promise + */ +export async function updatePeople(peopleId: string, people: People): Promise { + const requestData: PostPeopleRequest = { people }; + return put(API_ENDPOINTS.PEOPLE_BY_ID(peopleId), requestData); +} + /** * 批量创建人员信息 * @param peopleList 人员信息数组 diff --git a/src/apis/upload.ts b/src/apis/upload.ts index cfc2bfc..2d61f49 100644 --- a/src/apis/upload.ts +++ b/src/apis/upload.ts @@ -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();