优化调整
This commit is contained in:
@@ -31,9 +31,6 @@
|
||||
</div>
|
||||
|
||||
<div class="header-right">
|
||||
<a-button type="text" @click="testAPI" class="action-btn" style="margin-right: 8px;">
|
||||
测试API
|
||||
</a-button>
|
||||
<a-button type="text" @click="openHistoryDrawer" class="action-btn">
|
||||
<HistoryOutlined />
|
||||
</a-button>
|
||||
@@ -444,7 +441,8 @@
|
||||
showEmotionSummaryResult(result)
|
||||
|
||||
} catch (error) {
|
||||
console.error('生成情绪记录时发生错误:', error)
|
||||
const err = error as any;
|
||||
console.error('生成情绪记录时发生错误:', err)
|
||||
alert('生成情绪记录失败,请检查网络连接')
|
||||
} finally {
|
||||
emotionSummaryLoading.value = false
|
||||
@@ -497,39 +495,7 @@
|
||||
loadHistoryMessages(1)
|
||||
}
|
||||
|
||||
// 测试API调用
|
||||
const testAPI = async () => {
|
||||
console.log('=== 开始测试API ===')
|
||||
|
||||
try {
|
||||
// 测试原始API调用
|
||||
console.log('1. 测试原始axios调用...')
|
||||
const token = localStorage.getItem('token')
|
||||
console.log('Token:', token ? `${token.substring(0, 20)}...` : 'null')
|
||||
|
||||
const response = await fetch('/api/message/user/page?current=1&size=5', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
console.log('原始响应状态:', response.status)
|
||||
const rawData = await response.json()
|
||||
console.log('原始响应数据:', rawData)
|
||||
|
||||
// 测试封装的API调用
|
||||
console.log('2. 测试封装的API调用...')
|
||||
const apiData = await messageApi.getUserMessages(1, 5)
|
||||
console.log('封装API返回数据:', apiData)
|
||||
|
||||
} catch (error) {
|
||||
console.error('API测试失败:', error)
|
||||
}
|
||||
|
||||
console.log('=== API测试完成 ===')
|
||||
}
|
||||
|
||||
// 加载历史记录
|
||||
const loadHistoryMessages = async (page = 1) => {
|
||||
@@ -577,22 +543,23 @@
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载历史记录时发生错误:', error)
|
||||
const err = error as any;
|
||||
console.error('加载历史记录时发生错误:', err)
|
||||
console.error('错误详情:', {
|
||||
message: error.message,
|
||||
response: error.response,
|
||||
status: error.response?.status,
|
||||
data: error.response?.data
|
||||
message: err.message,
|
||||
response: err.response,
|
||||
status: err.response?.status,
|
||||
data: err.response?.data
|
||||
})
|
||||
|
||||
// 显示用户友好的错误信息
|
||||
if (error.response?.status === 401) {
|
||||
if (err.response?.status === 401) {
|
||||
console.log('认证失败,可能需要重新登录')
|
||||
// 可以在这里添加跳转到登录页的逻辑
|
||||
} else if (error.response?.status === 500) {
|
||||
} else if (err.response?.status === 500) {
|
||||
console.log('服务器错误,请稍后重试')
|
||||
} else {
|
||||
console.log('未知错误:', error.message)
|
||||
console.log('未知错误:', err.message)
|
||||
}
|
||||
} finally {
|
||||
console.log('加载历史记录完成,设置 loading 为 false')
|
||||
@@ -625,10 +592,11 @@
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error('搜索历史记录时发生错误:', error)
|
||||
const err = error as any;
|
||||
console.error('搜索历史记录时发生错误:', err)
|
||||
|
||||
// 显示用户友好的错误信息
|
||||
if (error.response?.status === 401) {
|
||||
if (err.response?.status === 401) {
|
||||
console.log('认证失败,搜索功能需要登录')
|
||||
}
|
||||
} finally {
|
||||
@@ -677,7 +645,7 @@
|
||||
// 将最近的消息添加到聊天记录中
|
||||
if (recentMessages && recentMessages.length > 0) {
|
||||
// 转换为聊天消息格式
|
||||
const chatMessages = recentMessages.map(msg => ({
|
||||
const chatMessages = recentMessages.map((msg: any) => ({
|
||||
id: msg.id,
|
||||
content: msg.content,
|
||||
sender: msg.sender === 'user' ? 'user' : 'ai',
|
||||
@@ -686,7 +654,7 @@
|
||||
}))
|
||||
|
||||
// 按时间顺序排列(最新的在最后)
|
||||
chatMessages.sort((a, b) => a.timestamp - b.timestamp)
|
||||
chatMessages.sort((a: any, b: any) => a.timestamp - b.timestamp)
|
||||
|
||||
// 添加到消息列表
|
||||
chatStore.messages.push(...chatMessages)
|
||||
@@ -694,7 +662,8 @@
|
||||
console.log('加载最近聊天记录成功:', chatMessages.length, '条')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载最近聊天记录失败:', error)
|
||||
const err = error as any;
|
||||
console.error('加载最近聊天记录失败:', err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -716,6 +685,7 @@
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@use "@/assets/styles/variables.scss" as *;
|
||||
.chat-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
Reference in New Issue
Block a user