Commit 6bf7f2b8 by Liu

fix:换一换后呢toolId处理

parent 749ccdec
......@@ -8,6 +8,7 @@ import Refresh from '@/assets/svg/refresh.svg?react'
import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { createConversation, setCurrentConversation, setShouldSendQuestion } from '@/store/conversationSlice'
import { safeSessionStorageGetItem } from '@/lib/utils'
import emptyIcon from '@/assets/empty-icon.png'
interface QuestionListProps {
......@@ -74,7 +75,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
const [isClicking, setIsClicking] = useState(false)
const dispatch = useAppDispatch()
const navigate = useNavigate()
const { currentConversationId, conversations } = useAppSelector(state => state.conversation)
const { currentConversationId, conversations, currentToolId } = useAppSelector(state => state.conversation)
// 根据 isToolBtn 动态设置 displayCount
const actualDisplayCount = isToolBtn ? 6 : 4
......@@ -92,13 +93,20 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
const handleClick = (item: string) => {
if (checkAuth() && !isClicking) {
setIsClicking(true)
// 获取当前的 toolId,优先从 Redux 获取,其次从 sessionStorage 获取
const toolId = currentToolId || safeSessionStorageGetItem('currentToolId') || null
// 优先使用当前会话,如果没有则使用第一个会话,如果都没有则创建新会话
const targetConversationId = currentConversationId || conversations[0]?.conversationId
if (targetConversationId) {
// 使用现有会话
dispatch(setCurrentConversation(targetConversationId))
dispatch(setShouldSendQuestion(item))
navigate(`/chat/${targetConversationId}`)
// 通过 location.state 传递 toolId,避免 Chat 页面清空 toolId
navigate(`/chat/${targetConversationId}`, {
state: {
toolId,
},
})
}
else {
// 如果没有现有会话,仍然创建新会话(向后兼容)
......
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