Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
35fc01e1
Commit
35fc01e1
authored
Dec 08, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:清空缓存逻辑
parent
9fa0ba6e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
27 deletions
+22
-27
src/components/ChatEditor/index.tsx
+2
-1
src/pages/Home/HomeNew.tsx
+20
-26
No files found.
src/components/ChatEditor/index.tsx
View file @
35fc01e1
...
...
@@ -144,7 +144,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const
storedToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
// 如果 currentToolId 是空字符串,视为 null,确保通用模式能正确高亮
setSessionToolId
(
storedToolId
&&
storedToolId
.
trim
()
?
storedToolId
:
null
)
},
[
toolIdFromUrl
])
// 当路由切换(如点击历史记录)时,同步最新的 sessionStorage,避免同标签页删除后状态不同步
},
[
toolIdFromUrl
,
location
.
pathname
])
const
startAnimation
=
()
=>
{
intervalRef
.
current
=
setInterval
(()
=>
{
...
...
src/pages/Home/HomeNew.tsx
View file @
35fc01e1
...
...
@@ -168,6 +168,15 @@ export const Home: React.FC = () => {
if
(
_loginCode
)
{
res
=
await
fetchLoginByToken
(
_loginCode
)
if
(
res
.
data
)
{
// 登录成功后先清理旧状态,避免沿用上一次的工具模式
dispatch
(
clearCurrentToolId
())
safeSessionStorageRemoveItem
(
'currentToolId'
)
const
currentUrl
=
new
URL
(
window
.
location
.
href
)
if
(
currentUrl
.
searchParams
.
has
(
'toolId'
))
{
currentUrl
.
searchParams
.
delete
(
'toolId'
)
// 使用 replace 避免产生新的历史记录
window
.
history
.
replaceState
({},
''
,
currentUrl
.
toString
())
}
setToken
(
res
.
data
.
token
)
// 主动触发 storage 事件,确保其他组件能监听到变化
window
.
dispatchEvent
(
...
...
@@ -179,25 +188,13 @@ export const Home: React.FC = () => {
storageArea
:
localStorage
,
}),
)
// 登录成功后强制重置为通用模式:清除所有 toolId 相关状态
// 1. 清除 Redux 中的 currentToolId
dispatch
(
clearCurrentToolId
())
// 2. 清除 sessionStorage 中的 currentToolId
safeSessionStorageRemoveItem
(
'currentToolId'
)
// 3. 清除 URL 中的 toolId 参数(如果存在)
const
currentUrl
=
new
URL
(
window
.
location
.
href
)
if
(
currentUrl
.
searchParams
.
has
(
'toolId'
))
{
currentUrl
.
searchParams
.
delete
(
'toolId'
)
// 使用 replace 避免产生新的历史记录
window
.
history
.
replaceState
({},
''
,
currentUrl
.
toString
())
}
// 4. 触发自定义事件,通知 ChatEditor 强制重置为通用模式
// 触发自定义事件,通知 ChatEditor 强制重置为通用模式
window
.
dispatchEvent
(
new
CustomEvent
(
'forceResetToGeneralMode'
))
initConversation
()
dispatch
(
fetchConversations
())
}
}
else
{
else
{
initConversation
()
dispatch
(
fetchConversations
())
}
...
...
@@ -206,6 +203,14 @@ export const Home: React.FC = () => {
// 模拟登录 可以用来测试
res
=
await
fetchLoginByUid
(
'123123'
)
if
(
res
.
data
)
{
// 登录成功后先清理旧状态,避免沿用上一次的工具模式
dispatch
(
clearCurrentToolId
())
safeSessionStorageRemoveItem
(
'currentToolId'
)
const
currentUrl
=
new
URL
(
window
.
location
.
href
)
if
(
currentUrl
.
searchParams
.
has
(
'toolId'
))
{
currentUrl
.
searchParams
.
delete
(
'toolId'
)
window
.
history
.
replaceState
({},
''
,
currentUrl
.
toString
())
}
setToken
(
res
.
data
.
token
)
// 主动触发 storage 事件,确保其他组件能监听到变化
window
.
dispatchEvent
(
...
...
@@ -217,18 +222,7 @@ export const Home: React.FC = () => {
storageArea
:
localStorage
,
}),
)
// 登录成功后强制重置为通用模式:清除所有 toolId 相关状态
// 1. 清除 Redux 中的 currentToolId
dispatch
(
clearCurrentToolId
())
// 2. 清除 sessionStorage 中的 currentToolId
safeSessionStorageRemoveItem
(
'currentToolId'
)
// 3. 清除 URL 中的 toolId 参数(如果存在)
const
currentUrl
=
new
URL
(
window
.
location
.
href
)
if
(
currentUrl
.
searchParams
.
has
(
'toolId'
))
{
currentUrl
.
searchParams
.
delete
(
'toolId'
)
window
.
history
.
replaceState
({},
''
,
currentUrl
.
toString
())
}
// 4. 触发自定义事件,通知 ChatEditor 强制重置为通用模式
// 触发自定义事件,通知 ChatEditor 强制重置为通用模式
window
.
dispatchEvent
(
new
CustomEvent
(
'forceResetToGeneralMode'
))
initConversation
()
dispatch
(
fetchConversations
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment