fix: 修复API认证问题,统一使用request工具
- 修复JWT拦截器配置,添加情绪记录和消息API到公开接口列表 - 统一前端API调用,使用services/api.ts中的request工具替代直接fetch - 确保所有API请求都能正确携带认证token - 修复401未授权错误问题
This commit is contained in:
@@ -113,4 +113,49 @@ export const uploadFile = (file: File, onProgress?: (progress: number) => void):
|
||||
}).then(res => res.data.data.url)
|
||||
}
|
||||
|
||||
// 消息相关API
|
||||
export const messageApi = {
|
||||
// 获取用户消息分页
|
||||
getUserMessages: (userId: string, current: number = 1, size: number = 20) =>
|
||||
request.get(`/message/user/${userId}/page`, { params: { current, size } }),
|
||||
|
||||
// 搜索用户消息
|
||||
searchUserMessages: (userId: string, keyword: string, limit: number = 50) =>
|
||||
request.get(`/message/user/${userId}/search`, { params: { keyword, limit } }),
|
||||
|
||||
// 获取消息详情
|
||||
getMessageById: (id: string) =>
|
||||
request.get(`/message/${id}`)
|
||||
}
|
||||
|
||||
// 情绪记录相关API
|
||||
export const emotionRecordApi = {
|
||||
// 获取用户情绪记录分页
|
||||
getUserEmotionRecords: (userId: string, current: number = 1, size: number = 10) =>
|
||||
request.get(`/emotion-records/user/${userId}`, { params: { current, size } }),
|
||||
|
||||
// 获取用户最近情绪记录
|
||||
getUserRecentEmotionRecords: (userId: string, limit: number = 5) =>
|
||||
request.get(`/emotion-records/user/${userId}/recent`, { params: { limit } }),
|
||||
|
||||
// 获取情绪记录详情
|
||||
getEmotionRecordById: (id: string) =>
|
||||
request.get(`/emotion-records/${id}`),
|
||||
|
||||
// 删除情绪记录
|
||||
deleteEmotionRecord: (id: string) =>
|
||||
request.delete(`/emotion-records/${id}`)
|
||||
}
|
||||
|
||||
// 情绪总结相关API
|
||||
export const emotionSummaryApi = {
|
||||
// 生成情绪记录总结
|
||||
generateEmotionSummary: (userId: string) =>
|
||||
request.post(`/emotion-summary/generate/${userId}`),
|
||||
|
||||
// 获取情绪记录总结状态
|
||||
getEmotionSummaryStatus: (userId: string) =>
|
||||
request.get(`/emotion-summary/status/${userId}`)
|
||||
}
|
||||
|
||||
export default api
|
||||
|
||||
Reference in New Issue
Block a user