feat: 修复
This commit is contained in:
@@ -203,7 +203,6 @@ import FullWidthLayout from '@/layouts/components/FullWidthLayout.vue'
|
||||
import ChatDrawer from '@/components/agents/ChatDrawer.vue'
|
||||
import HistoryPanel from '@/components/agents/HistoryPanel.vue'
|
||||
import { getAgentList, addFavorite, removeFavorite } from '@/api/agent'
|
||||
import tokenManager from '@gold/utils/token-manager'
|
||||
|
||||
// 状态管理
|
||||
const loading = ref(false)
|
||||
@@ -357,11 +356,6 @@ const handleChat = (agent) => {
|
||||
}
|
||||
|
||||
const handleHistory = (agent) => {
|
||||
// 检查登录状态
|
||||
if (!tokenManager.isLoggedIn()) {
|
||||
message.warning('请先登录')
|
||||
return
|
||||
}
|
||||
historyAgentId.value = agent.id
|
||||
historyPanelVisible.value = true
|
||||
}
|
||||
@@ -374,27 +368,22 @@ const handleSendMessage = (data) => {
|
||||
console.log('发送消息:', data)
|
||||
}
|
||||
|
||||
// 收藏切换
|
||||
// 收藏切换(乐观更新)
|
||||
const handleFavorite = async (agent) => {
|
||||
// 检查登录状态
|
||||
if (!tokenManager.isLoggedIn()) {
|
||||
message.warning('请先登录')
|
||||
return
|
||||
}
|
||||
const newStatus = !agent.isFavorite
|
||||
agent.isFavorite = newStatus // 立即更新 UI
|
||||
|
||||
try {
|
||||
if (agent.isFavorite) {
|
||||
await removeFavorite(agent.id)
|
||||
agent.isFavorite = false
|
||||
message.success('已取消收藏')
|
||||
} else {
|
||||
if (newStatus) {
|
||||
await addFavorite(agent.id)
|
||||
agent.isFavorite = true
|
||||
message.success('收藏成功')
|
||||
} else {
|
||||
await removeFavorite(agent.id)
|
||||
message.success('已取消收藏')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('收藏操作失败:', error)
|
||||
message.error('操作失败,请重试')
|
||||
} catch {
|
||||
agent.isFavorite = !newStatus // 失败时回滚
|
||||
message.error('操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user