优化处理

This commit is contained in:
2025-10-26 16:59:50 +08:00
parent fdac026720
commit 2e243c7671
45 changed files with 346 additions and 3757 deletions
+20 -19
View File
@@ -52,7 +52,8 @@ export class ChatApiService {
async createSession(userId: string, title?: string): Promise<ChatSession> {
try {
console.log('📝 创建会话API调用:', { userId, title })
const response = await http.post<ConversationResponse>('/conversation', {
// backend-single: POST /conversation/create
const response = await http.post<ConversationResponse>('/conversation/create', {
userId,
title: title || `对话${Date.now()}`
})
@@ -88,25 +89,23 @@ export class ChatApiService {
async getUserSessions(userId: string): Promise<ChatSession[]> {
try {
console.log('📂 获取用户会话API调用:', { userId })
const response = await http.get<ConversationResponse[]>(`/conversation/user/${userId}`)
// backend-single: GET /conversation/page?userId=xxx
const response = await http.get<any>('/conversation/page', { params: { userId, current: 1, size: 100 } })
console.log('📂 获取用户会话API响应:', response)
// 处理HTTP响应的data字段
const data = (response as any).data || response
// 处理HTTP响应的data字段PageResult
const pageData = (response as any).data || response
const records = pageData.records || []
// 后端返回ConversationResponse数组,需要转换为ChatSession格式
if (Array.isArray(data)) {
return data.map((conv: any) => ({
id: conv.id,
title: conv.title,
userId: conv.userId || conv.user_id, // 兼容不同的字段名
createTime: conv.createTime || conv.create_time,
updateTime: conv.updateTime || conv.update_time,
messageCount: conv.messageCount || conv.message_count || 0
}))
}
return []
// 转换为ChatSession数组
return records.map((conv: any) => ({
id: conv.id,
title: conv.title,
userId: conv.userId || conv.user_id,
createTime: conv.createTime || conv.create_time,
updateTime: conv.updateTime || conv.update_time,
messageCount: conv.messageCount || conv.message_count || 0
}))
} catch (error) {
console.error('❌ 获取用户会话失败:', error)
return []
@@ -133,7 +132,8 @@ export class ChatApiService {
async deleteSession(sessionId: string): Promise<void> {
try {
console.log('🗑️ 删除会话API调用:', { sessionId })
await http.delete(`/conversation/${sessionId}`)
// backend-single: DELETE /conversation/delete?id=xxx
await http.delete('/conversation/delete', { params: { id: sessionId } })
console.log('✅ 删除会话成功')
} catch (error) {
console.error('❌ 删除会话失败:', error)
@@ -147,7 +147,8 @@ export class ChatApiService {
async updateSessionTitle(sessionId: string, title: string): Promise<void> {
try {
console.log('✏️ 更新会话标题API调用:', { sessionId, title })
await http.put(`/conversation/${sessionId}`, { title })
// backend-single: PUT /conversation/update 传id和title
await http.put('/conversation/update', { id: sessionId, title })
console.log('✅ 更新会话标题成功')
} catch (error) {
console.error('❌ 更新会话标题失败:', error)