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
aefb636d
Commit
aefb636d
authored
Jan 06, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:收藏返回时逻辑
parent
1fbf75db
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
src/pages/Chat/Chat.tsx
+13
-5
src/pages/Collect/Collect.tsx
+2
-0
No files found.
src/pages/Chat/Chat.tsx
View file @
aefb636d
...
...
@@ -309,10 +309,12 @@ export const Chat: React.FC = () => {
setIsLoading
(
true
)
// 标记正在处理
processingConversationIdRef
.
current
=
conversationId
// 定义 finalConversationId 在 try 块外,以便 finally 块可以访问
let
finalConversationId
=
conversationId
try
{
// 检测是否从收藏页返回(优先使用 ref 中保存的值,避免 location.state 被清除后丢失)
const
fromCollect
=
fromCollectRef
.
current
||
Boolean
(
location
.
state
?.
fromCollect
)
let
finalConversationId
=
conversationId
// 增加 sessionStorage 检查,用于 navigate(-1) 的情况
const
fromCollect
=
fromCollectRef
.
current
||
Boolean
(
location
.
state
?.
fromCollect
)
||
Boolean
(
sessionStorage
.
getItem
(
'fromCollect'
))
// 如果从收藏页返回,先调用 get_user_conversation_session 获取新的会话ID
if
(
fromCollect
&&
!
fromCollectProcessedRef
.
current
)
{
...
...
@@ -326,6 +328,8 @@ export const Chat: React.FC = () => {
console
.
log
(
'[Chat] 从收藏返回 - 获取到新会话ID:'
,
finalConversationId
)
// 如果获取到新会话ID,设置标记避免路由变化时重复调用
toolHistoryLoadedRef
.
current
.
conversationId
=
finalConversationId
// 更新 processingConversationIdRef 为新会话ID,避免使用旧ID重复调用
processingConversationIdRef
.
current
=
finalConversationId
}
}
catch
(
error
)
{
...
...
@@ -339,6 +343,8 @@ export const Chat: React.FC = () => {
const
eventToolId
=
toolId
||
currentToolId
||
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
console
.
log
(
'[Chat] 检测到从收藏页返回 (fromCollect=true) - 准备触发 refreshQuestionsFromCollect 事件'
)
console
.
log
(
'[Chat] refreshQuestionsFromCollect - 传递的 toolId:'
,
eventToolId
)
// 清除 sessionStorage 中的标记,避免影响后续路由
sessionStorage
.
removeItem
(
'fromCollect'
)
// 延迟触发事件,确保 Home 组件的监听器已注册
setTimeout
(()
=>
{
window
.
dispatchEvent
(
new
CustomEvent
(
'refreshQuestionsFromCollect'
,
{
...
...
@@ -452,8 +458,9 @@ export const Chat: React.FC = () => {
}
finally
{
setIsLoading
(
false
)
// 清除处理标记
if
(
processingConversationIdRef
.
current
===
conversationId
)
{
// 清除处理标记(支持新会话ID的情况)
// finalConversationId 可能是新会话ID(从收藏返回时)或原来的 conversationId
if
(
processingConversationIdRef
.
current
===
finalConversationId
)
{
processingConversationIdRef
.
current
=
null
}
}
...
...
@@ -485,7 +492,8 @@ export const Chat: React.FC = () => {
currentIdRef
.
current
=
id
lastSentQuestionRef
.
current
=
''
// 重置标记
// 保存 fromCollect 标记到 ref,避免 location.state 被清除后丢失
fromCollectRef
.
current
=
Boolean
(
location
.
state
?.
fromCollect
)
// 优先使用 location.state,其次使用 sessionStorage(用于 navigate(-1) 的情况)
fromCollectRef
.
current
=
Boolean
(
location
.
state
?.
fromCollect
)
||
Boolean
(
sessionStorage
.
getItem
(
'fromCollect'
))
// 重置 fromCollect 处理标记,确保每次路由变化时都能正确处理
fromCollectProcessedRef
.
current
=
false
// 清除处理标记,允许新的 conversationId 处理
...
...
src/pages/Collect/Collect.tsx
View file @
aefb636d
...
...
@@ -85,6 +85,8 @@ export const Collect: React.FC = () => {
// 添加返回上一页的函数
const
handleGoBack
=
()
=>
{
// 设置标记,用于 Chat 组件检测从收藏页返回
sessionStorage
.
setItem
(
'fromCollect'
,
'true'
)
if
(
window
.
history
.
length
>
1
)
{
navigate
(
-
1
)
return
...
...
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