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
ec975429
Commit
ec975429
authored
Dec 03, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:关闭后管标签时清空toolId
parent
e015bccc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
18 deletions
+55
-18
src/components/ChatEditor/index.tsx
+17
-1
src/pages/Home/HomeNew.tsx
+38
-17
No files found.
src/components/ChatEditor/index.tsx
View file @
ec975429
...
...
@@ -155,10 +155,26 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}
syncSessionToolId
()
window
.
addEventListener
(
'storage'
,
syncSessionToolId
)
// 监听强制重置为通用模式的事件(登录成功后触发)
const
handleForceReset
=
()
=>
{
// 强制同步 sessionStorage(此时应该已经被清除了)
syncSessionToolId
()
// 确保 Redux 也被清除(如果还没有)
if
(
currentToolId
)
{
dispatch
(
clearCurrentToolId
())
}
// 强制设置为通用模式
setSelectedToolId
(
null
)
setIsToolBtnActive
(
true
)
}
window
.
addEventListener
(
'forceResetToGeneralMode'
,
handleForceReset
)
return
()
=>
{
window
.
removeEventListener
(
'storage'
,
syncSessionToolId
)
window
.
removeEventListener
(
'forceResetToGeneralMode'
,
handleForceReset
)
}
},
[])
},
[
currentToolId
,
dispatch
])
// 当路由变化时,同步更新 sessionToolId(因为 storage 事件不会在同标签页触发)
useEffect
(()
=>
{
...
...
src/pages/Home/HomeNew.tsx
View file @
ec975429
...
...
@@ -85,24 +85,19 @@ export const Home: React.FC = () => {
}))
setIsDataLoaded
(
false
)
// 重置加载状态
try
{
/**
* 获取最终用于请求的 toolId:
* - 如果传入了 toolId:
* - 通用模式(isToolBtn === true):保持传入值(可能是空字符串),不再从 sessionStorage / URL 回退
* - 工具模式(isToolBtn === false):如果传入为空,再从 sessionStorage / URL 回退
* - 如果没有传入 toolId:保留原有回退逻辑
*/
let
finalToolId
=
toolId
||
''
const
storedToolId
=
sessionStorage
.
getItem
(
'currentToolId'
)
||
''
const
searchParams
=
new
URLSearchParams
(
location
.
search
)
const
urlToolId
=
searchParams
.
get
(
'toolId'
)
||
''
const
shouldForceClearToolId
=
!
storedToolId
&&
!
urlToolId
if
(
!
finalToolId
&&
!
isToolBtn
)
{
let
finalToolId
=
toolId
||
''
if
(
shouldForceClearToolId
&&
!
isToolBtn
)
{
finalToolId
=
''
}
else
if
(
!
finalToolId
&&
!
isToolBtn
)
{
// 仅在工具模式下才使用回退逻辑,避免通用模式误用上一次的 toolId
finalToolId
=
sessionStorage
.
getItem
(
'currentToolId'
)
||
''
if
(
!
finalToolId
)
{
const
searchParams
=
new
URLSearchParams
(
location
.
search
)
finalToolId
=
searchParams
.
get
(
'toolId'
)
||
''
}
finalToolId
=
storedToolId
||
urlToolId
}
const
res
=
await
fetchEfficiencyQuestionList
({
toolId
:
finalToolId
})
if
(
res
&&
res
.
data
&&
res
.
data
.
questions
)
{
setOtherQuestions
((
prev
:
any
)
=>
({
...
...
@@ -171,7 +166,20 @@ export const Home: React.FC = () => {
storageArea
:
localStorage
,
}),
)
sessionStorage
.
setItem
(
'currentToolId'
,
''
)
// 登录成功后强制重置为通用模式:清除所有 toolId 相关状态
// 1. 清除 Redux 中的 currentToolId
dispatch
(
clearCurrentToolId
())
// 2. 清除 sessionStorage 中的 currentToolId
sessionStorage
.
removeItem
(
'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 强制重置为通用模式
window
.
dispatchEvent
(
new
CustomEvent
(
'forceResetToGeneralMode'
))
initConversation
()
dispatch
(
fetchConversations
())
}
...
...
@@ -196,11 +204,24 @@ export const Home: React.FC = () => {
storageArea
:
localStorage
,
}),
)
// 登录成功后强制重置为通用模式:清除所有 toolId 相关状态
// 1. 清除 Redux 中的 currentToolId
dispatch
(
clearCurrentToolId
())
// 2. 清除 sessionStorage 中的 currentToolId
sessionStorage
.
removeItem
(
'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 强制重置为通用模式
window
.
dispatchEvent
(
new
CustomEvent
(
'forceResetToGeneralMode'
))
initConversation
()
dispatch
(
fetchConversations
())
}
}
},
[
setToken
])
},
[
setToken
,
dispatch
])
// 修改 useEffect
useEffect
(()
=>
{
...
...
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