Commit 351d1015 by Liu

fix:会话id存入localStorage

parent 584fe21f
...@@ -12,6 +12,7 @@ import { withAuth } from '@/auth/withAuth' ...@@ -12,6 +12,7 @@ import { withAuth } from '@/auth/withAuth'
import { NAV_BAR_ITEMS } from '@/config/nav' import { NAV_BAR_ITEMS } from '@/config/nav'
import { useAppDispatch, useAppSelector } from '@/store/hook' import { useAppDispatch, useAppSelector } from '@/store/hook'
import { isMobile } from '@/utils' import { isMobile } from '@/utils'
import { safeLocalStorageSetItem } from '@/lib/utils'
// import { User } from './components/User' // import { User } from './components/User'
interface NavbarProps { interface NavbarProps {
...@@ -135,9 +136,12 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c ...@@ -135,9 +136,12 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
} }
}, [shouldNavigateToNewConversation, currentConversationId, currentToolId, navigate, dispatch]) }, [shouldNavigateToNewConversation, currentConversationId, currentToolId, navigate, dispatch])
// keep latest conversation id in sessionStorage for cross-page returns (e.g., from collect) // keep latest conversation id in localStorage (persists across page closes) and sessionStorage (for cross-page returns)
useEffect(() => { useEffect(() => {
if (currentConversationId) { if (currentConversationId) {
// 保存到 localStorage,关闭页面后仍能恢复
safeLocalStorageSetItem('currentConversationId', currentConversationId)
// 同时保存到 sessionStorage,用于跨页面返回(如从收藏页返回)
sessionStorage.setItem('currentConversationId', currentConversationId) sessionStorage.setItem('currentConversationId', currentConversationId)
} }
}, [currentConversationId]) }, [currentConversationId])
......
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