Commit f1e37696 by Liu

fix:当前会话及时更新

parent 396afeb0
......@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react'
import { AnimatePresence, motion } from 'framer-motion'
import { Button, Tooltip } from '@heroui/react'
import { useLocalStorageState, useToggle } from 'ahooks'
import { useLocation, useParams, useSearchParams } from 'react-router-dom'
import { useLocation, useSearchParams } from 'react-router-dom'
import { LoginModal } from '../LoginModal'
import type { RootState } from '@/store'
import SendIcon from '@/assets/svg/send.svg?react'
......@@ -10,7 +10,6 @@ import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { clearCurrentToolId, setCurrentToolId } from '@/store/conversationSlice'
import { fetchToolList } from '@/api/home'
import { fetchUserQaRecordPage } from '@/api/conversation'
import { getUserRolesForApi, safeSessionStorageGetItem, safeSessionStorageRemoveItem, safeSessionStorageSetItem } from '@/lib/utils'
interface ChatEditorProps {
......@@ -41,7 +40,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const [sessionToolId, setSessionToolId] = useState<string | null>(null)
const [searchParams, setSearchParams] = useSearchParams()
const location = useLocation()
const { id: conversationId } = useParams<{ id: string }>()
const toolIdFromUrl = searchParams.get('toolId')
const fromCollect = location.state?.fromCollect
......@@ -237,15 +235,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
newSearchParams.delete('toolId')
setSearchParams(newSearchParams, { replace: true })
}
// 调用接口
if (conversationId) {
try {
await fetchUserQaRecordPage(conversationId, '')
}
catch (error) {
console.error('获取问答记录失败:', error)
}
}
// try {
// await dispatch(createConversation({
// conversationData: {},
......@@ -275,16 +264,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setSessionToolId(tool.toolId)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick?.(false, tool.toolId, tool.toolName, true)
// 调用接口
if (conversationId) {
const toolId = safeSessionStorageGetItem('currentToolId') || ''
try {
await fetchUserQaRecordPage(conversationId, toolId)
}
catch (error) {
console.error('获取问答记录失败:', error)
}
}
// try {
// await dispatch(createConversation({
// conversationData: { toolId: tool.toolId },
......
......@@ -15,7 +15,7 @@ import { fetchUserQaRecordPage } from '@/api/conversation'
import { fetchCheckTokenApi, fetchStreamResponse } from '@/api/chat'
import { fetchToolList } from '@/api/home'
import { clearCurrentToolId, clearShouldSendQuestion, fetchConversations, setCurrentToolId } from '@/store/conversationSlice'
import { getUserRolesForApi } from '@/lib/utils'
import { getUserRolesForApi, safeSessionStorageGetItem } from '@/lib/utils'
import type { RootState } from '@/store'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import ScrollBtoIcon from '@/assets/svg/scrollBto.svg?react'
......@@ -332,14 +332,14 @@ export const Chat: React.FC = () => {
}
/** 获取qa记录 */
const getUserQaRecordPage = useCallback(async (conversationId: string) => {
const getUserQaRecordPage = useCallback(async (conversationId: string, toolId?: string) => {
setIsLoading(true)
try {
// 检测是否从收藏页返回
const fromCollect = location.state?.fromCollect
// eslint-disable-next-line no-console
console.log('[Chat] 开始获取历史记录:', conversationId)
const res = await fetchUserQaRecordPage(conversationId)
const res = await fetchUserQaRecordPage(conversationId, toolId || '')
const qaRecords = res.data || []
const messages = [{ role: 'system' } as ChatRecord, ...processApiResponse(qaRecords)]
// 处理历史记录中的参考文档标记
......@@ -558,12 +558,17 @@ export const Chat: React.FC = () => {
// 制度活化,清除 toolId
dispatch(clearCurrentToolId())
}
// 刷新对话内容
if (currentIdRef.current) {
const toolIdForApi = toolId || safeSessionStorageGetItem('currentToolId') || ''
getUserQaRecordPage(currentIdRef.current, toolIdForApi)
}
}
window.addEventListener('toolButtonClick', handleToolClickEvent as EventListener)
return () => {
window.removeEventListener('toolButtonClick', handleToolClickEvent as EventListener)
}
}, [dispatch])
}, [dispatch, getUserQaRecordPage])
return (
<div className={styles.scrollView}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment