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
552559f6
Commit
552559f6
authored
Dec 01, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:历史纪录到会话逻辑
parent
0bdbb145
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
16 deletions
+37
-16
src/layouts/HistoryBar/components/HistoryBarList/index.tsx
+5
-1
src/pages/Chat/Chat.tsx
+32
-15
No files found.
src/layouts/HistoryBar/components/HistoryBarList/index.tsx
View file @
552559f6
...
...
@@ -46,7 +46,11 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS
dispatch
(
clearCurrentToolId
())
}
// 直接导航到历史记录,不设置shouldSendQuestion
navigate
(
`/chat/
${
conversation
.
conversationId
}
`
)
navigate
(
`/chat/
${
conversation
.
conversationId
}
`
,
{
state
:
{
toolId
:
conversation
.
toolId
||
null
,
},
})
}
const
handleFilter
=
useDebounceFn
(()
=>
{
...
...
src/pages/Chat/Chat.tsx
View file @
552559f6
import
React
,
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
useParams
}
from
'react-router-dom'
import
{
use
Location
,
use
Params
}
from
'react-router-dom'
import
{
Button
}
from
'@heroui/react'
import
{
motion
}
from
'framer-motion'
import
{
useScroll
}
from
'ahooks'
...
...
@@ -23,6 +23,8 @@ import SdreamLoading from '@/components/SdreamLoading'
export
const
Chat
:
React
.
FC
=
()
=>
{
const
{
id
}
=
useParams
<
{
id
:
string
}
>
()
const
location
=
useLocation
()
const
initialToolId
=
(
location
.
state
as
{
toolId
?:
string
|
null
}
|
null
)?.
toolId
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
dispatch
=
useAppDispatch
()
...
...
@@ -32,7 +34,19 @@ export const Chat: React.FC = () => {
const
currentIdRef
=
useRef
<
string
|
undefined
>
(
id
)
const
lastSentQuestionRef
=
useRef
<
string
>
(
''
)
const
abortControllerRef
=
useRef
<
AbortController
|
null
>
(
null
)
const
[
currentToolName
,
setCurrentToolName
]
=
useState
<
string
>
(
'通用模式'
)
const
[
currentToolName
,
setCurrentToolName
]
=
useState
<
string
|
undefined
>
(
undefined
)
// 历史记录点击时将 toolId 通过路由 state 传入,优先使用该值快速同步高亮
useEffect
(()
=>
{
if
(
typeof
initialToolId
===
'undefined'
)
return
if
(
initialToolId
)
{
dispatch
(
setCurrentToolId
(
initialToolId
))
}
else
{
dispatch
(
clearCurrentToolId
())
}
},
[
dispatch
,
initialToolId
])
/** 处理正常stream的数据 */
const
handleStreamMesageData
=
(
msg
:
any
,
question
:
string
)
=>
{
...
...
@@ -330,23 +344,26 @@ export const Chat: React.FC = () => {
// 根据 currentToolId 获取对应的 toolName
useEffect
(()
=>
{
if
(
!
currentToolId
)
return
const
getToolNameFromToolId
=
async
()
=>
{
try
{
// 使用统一的方法获取 userRoles(先同步路由到 localStorage,然后读取)
const
userRoles
=
getUserRolesForApi
()
const
res
=
await
fetchToolList
({
userRoles
})
if
(
res
?.
data
)
{
const
tool
=
res
.
data
.
find
((
t
:
any
)
=>
t
.
toolId
===
currentToolId
)
if
(
tool
?.
toolName
)
{
setCurrentToolName
(
tool
.
toolName
)
if
(
currentToolId
)
{
try
{
// 使用统一的方法获取 userRoles(先同步路由到 localStorage,然后读取)
const
userRoles
=
getUserRolesForApi
()
const
res
=
await
fetchToolList
({
userRoles
})
if
(
res
?.
data
)
{
const
tool
=
res
.
data
.
find
((
t
:
any
)
=>
t
.
toolId
===
currentToolId
)
if
(
tool
?.
toolName
)
{
setCurrentToolName
(
tool
.
toolName
)
}
}
}
catch
(
error
)
{
console
.
error
(
'获取工具列表失败:'
,
error
)
}
}
catch
(
error
)
{
console
.
error
(
'获取工具列表失败:'
,
error
)
else
{
// 通用模式
setCurrentToolName
(
'通用模式'
)
}
}
getToolNameFromToolId
()
...
...
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