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
b8758181
Commit
b8758181
authored
Nov 25, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 选中工具时刷新逻辑
parent
c398ed18
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
63 additions
and
15 deletions
+63
-15
src/components/ChatEditor/index.tsx
+10
-4
src/layouts/HistoryBar/components/HistoryBarList/index.tsx
+4
-2
src/layouts/Navbar/Navbar.tsx
+11
-3
src/pages/Collect/Collect.tsx
+13
-3
src/pages/Home/HomeNew.tsx
+15
-0
src/pages/Home/components/QuestionList/QuestionList.tsx
+5
-1
src/store/conversationSlice.ts
+4
-2
src/types/conversation.ts
+1
-0
No files found.
src/components/ChatEditor/index.tsx
View file @
b8758181
...
...
@@ -8,7 +8,7 @@ import SendIcon from '@/assets/svg/send.svg?react'
import
{
type
WithAuthProps
,
withAuth
}
from
'@/auth/withAuth'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
{
fetchToolList
}
from
'@/api/home'
import
{
c
reateConversation
}
from
'@/store/conversationSlice'
import
{
c
learCurrentToolId
,
createConversation
,
setCurrentToolId
}
from
'@/store/conversationSlice'
interface
ChatEditorProps
{
onChange
?:
(
value
:
string
)
=>
void
...
...
@@ -138,6 +138,10 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
if
(
!
checkAuth
())
return
try
{
// 先清除 toolId,确保创建会话时能获取到正确的状态
dispatch
(
clearCurrentToolId
())
// 清除 sessionStorage 中的 toolId
sessionStorage
.
removeItem
(
'currentToolId'
)
await
dispatch
(
createConversation
({
conversationData
:
{},
shouldNavigate
:
true
,
...
...
@@ -157,6 +161,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
if
(
!
checkAuth
())
return
try
{
// 先设置 toolId,确保创建会话时能获取到正确的状态
dispatch
(
setCurrentToolId
(
tool
.
toolId
))
await
dispatch
(
createConversation
({
conversationData
:
{},
shouldNavigate
:
true
,
...
...
@@ -276,13 +282,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
{
toolList
&&
toolList
.
length
>
0
&&
(
<
div
className=
"absolute left-4 bottom-2 flex items-center gap-3 pointer-events-auto pl-[16px]"
>
{
toolList
.
map
((
tool
:
any
,
index
:
number
)
=>
{
//
index === 1 的按钮(通用模式)
在默认状态下高亮
const
isSelected
=
(
selectedToolId
===
tool
.
toolId
&&
!
isToolBtnActive
)
||
(
index
===
1
&&
isToolBtnActive
)
//
(index === 1 || tool.toolName === '通用模式')
在默认状态下高亮
const
isSelected
=
(
selectedToolId
===
tool
.
toolId
&&
!
isToolBtnActive
)
||
(
(
index
===
1
||
tool
.
toolName
===
'通用模式'
)
&&
isToolBtnActive
)
const
handleButtonPress
=
async
()
=>
{
// 高亮状态直接返回,避免重复触发
if
(
isSelected
)
return
if
(
index
===
1
)
if
(
(
index
===
1
||
tool
.
toolName
===
'通用模式'
)
)
await
handleGeneralClick
()
else
await
handleToolClick
(
tool
)
...
...
src/layouts/HistoryBar/components/HistoryBarList/index.tsx
View file @
b8758181
...
...
@@ -24,9 +24,11 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS
if
(
isMobile
())
{
onSetHistoryVisible
(
false
)
}
// 直接导航到历史记录,不设置shouldSendQuestion
navigate
(
`/chat/
${
conversation
.
conversationId
}
`
)
// 将 toolId 拼接到路由上,默认为空字符串
const
toolId
=
conversation
.
toolId
||
''
const
toolIdParam
=
`?toolId=
${
toolId
}
`
navigate
(
`/chat/
${
conversation
.
conversationId
}${
toolIdParam
}
`
)
}
const
handleFilter
=
useDebounceFn
(()
=>
{
...
...
src/layouts/Navbar/Navbar.tsx
View file @
b8758181
...
...
@@ -22,7 +22,7 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
const
dispatch
=
useAppDispatch
()
const
navigate
=
useNavigate
()
const
{
currentConversationId
,
shouldNavigateToNewConversation
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
{
currentConversationId
,
shouldNavigateToNewConversation
,
currentToolId
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
handleCreateConversation
=
()
=>
{
dispatch
(
createConversation
({
...
...
@@ -77,6 +77,12 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
if
(
conversationId
)
{
sessionStorage
.
setItem
(
'currentConversationId'
,
conversationId
)
}
// 从URL参数中提取toolId并保存到sessionStorage
const
urlParams
=
new
URLSearchParams
(
location
.
search
)
const
toolId
=
urlParams
.
get
(
'toolId'
)
if
(
toolId
&&
toolId
!==
''
)
{
sessionStorage
.
setItem
(
'currentToolId'
,
toolId
)
}
navigate
(
'/collect'
)
}
...
...
@@ -103,10 +109,12 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
useEffect
(()
=>
{
if
(
shouldNavigateToNewConversation
&&
currentConversationId
)
{
navigate
(
`/chat/
${
currentConversationId
}
`
)
// 将 toolId 拼接到路由上,默认为空字符串
const
toolIdParam
=
currentToolId
?
`?toolId=
${
currentToolId
}
`
:
'?toolId='
navigate
(
`/chat/
${
currentConversationId
}${
toolIdParam
}
`
)
dispatch
(
clearNavigationFlag
())
}
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
navigate
,
dispatch
])
},
[
shouldNavigateToNewConversation
,
currentConversationId
,
currentToolId
,
navigate
,
dispatch
])
// keep latest conversation id in sessionStorage for cross-page returns (e.g., from collect)
useEffect
(()
=>
{
...
...
src/pages/Collect/Collect.tsx
View file @
b8758181
...
...
@@ -14,10 +14,12 @@ import QIcon from '@/assets/svg/qicon.svg?react'
import
EmptyIcon
from
'@/assets/svg/empty.svg?react'
import
ShineBorder
from
'@/components/ShineBorder'
import
SdreamLoading
from
'@/components/SdreamLoading'
import
{
useAppSelector
}
from
'@/store/hook'
export
const
Collect
:
React
.
FC
=
()
=>
{
const
navigate
=
useNavigate
()
const
hasLoaded
=
useRef
(
false
)
const
{
conversations
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
isOpen
,
setIsOpen
]
=
useState
(
false
)
...
...
@@ -86,7 +88,15 @@ export const Collect: React.FC = () => {
// 添加返回上一页的函数
const
handleGoBack
=
()
=>
{
const
conversationId
=
sessionStorage
.
getItem
(
'currentConversationId'
)
||
''
navigate
(
`/chat/
${
conversationId
}
`
,
{
state
:
{
fromCollect
:
true
}
})
// 优先从 sessionStorage 中获取 toolId
let
toolId
=
sessionStorage
.
getItem
(
'currentToolId'
)
||
''
// 如果 sessionStorage 中没有,则从会话列表中查找
if
(
!
toolId
)
{
const
targetConversation
=
conversations
.
find
(
conv
=>
conv
.
conversationId
===
conversationId
)
toolId
=
targetConversation
?.
toolId
||
''
}
const
toolIdParam
=
`?toolId=
${
toolId
}
`
navigate
(
`/chat/
${
conversationId
}${
toolIdParam
}
`
,
{
state
:
{
fromCollect
:
true
}
})
}
useEffect
(()
=>
{
...
...
@@ -131,11 +141,11 @@ export const Collect: React.FC = () => {
}
}
className=
"flex flex-col gap-[24px]"
>
{
collectList
.
map
((
item
:
any
,
index
:
number
)
=>
(
{
collectList
.
map
((
item
:
any
)
=>
(
<
ShineBorder
borderRadius=
{
20
}
className=
"text-[#27353C] w-full mx-auto bg-white rounded-[20px] box-border px-[24px] py-[20px]"
key=
{
`${item.collectionId}_${index
}`
}
key=
{
item
.
collectionId
??
`${item.question}-${item.collectionTime
}`
}
>
<
div
className=
"flex mb-[20px]"
>
<
div
className=
"mr-[20px]"
>
...
...
src/pages/Home/HomeNew.tsx
View file @
b8758181
...
...
@@ -144,6 +144,21 @@ finally {
}
},
[
originalOtherQuestions
])
// 进入页面时,如果路由中有 toolId 且不为空,执行工具点击逻辑
useEffect
(()
=>
{
if
(
location
.
pathname
.
startsWith
(
'/chat/'
))
{
const
urlParams
=
new
URLSearchParams
(
window
.
location
.
search
)
const
toolIdFromUrl
=
urlParams
.
get
(
'toolId'
)
if
(
toolIdFromUrl
&&
toolIdFromUrl
!==
''
)
{
// 有 toolId,执行工具点击逻辑
dispatch
(
setCurrentToolId
(
toolIdFromUrl
))
setShouldChangeStyle
(
true
)
setIsToolBtnActive
(
false
)
_handleToolClick
(
false
,
toolIdFromUrl
)
}
}
},
[
location
.
pathname
,
location
.
search
,
dispatch
,
_handleToolClick
])
// 监听工具按钮点击事件
useEffect
(()
=>
{
const
handleToolClickEvent
=
(
event
:
CustomEvent
)
=>
{
...
...
src/pages/Home/components/QuestionList/QuestionList.tsx
View file @
b8758181
...
...
@@ -98,7 +98,11 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
// 使用现有会话
dispatch
(
setCurrentConversation
(
targetConversationId
))
dispatch
(
setShouldSendQuestion
(
item
))
navigate
(
`/chat/
${
targetConversationId
}
`
)
// 从会话列表中查找对应的 toolId,默认为空字符串
const
targetConversation
=
conversations
.
find
(
conv
=>
conv
.
conversationId
===
targetConversationId
)
const
toolId
=
targetConversation
?.
toolId
||
''
const
toolIdParam
=
`?toolId=
${
toolId
}
`
navigate
(
`/chat/
${
targetConversationId
}${
toolIdParam
}
`
)
}
else
{
// 如果没有现有会话,仍然创建新会话(向后兼容)
...
...
src/store/conversationSlice.ts
View file @
b8758181
...
...
@@ -62,8 +62,10 @@ export const createConversation = createAsyncThunk<
{
state
:
{
conversation
:
ConversationState
}
}
>
(
'conversation/createConversation'
,
async
({
conversationData
,
shouldNavigate
,
shouldSendQuestion
},
{
dispatch
})
=>
{
const
response
=
await
fetchCreateConversation
(
conversationData
)
async
({
conversationData
,
shouldNavigate
,
shouldSendQuestion
},
{
dispatch
,
getState
})
=>
{
const
state
=
getState
()
const
toolId
=
state
.
conversation
.
currentToolId
||
''
const
response
=
await
fetchCreateConversation
({
...
conversationData
,
toolId
})
const
newConversation
=
response
.
data
dispatch
(
fetchConversations
())
...
...
src/types/conversation.ts
View file @
b8758181
...
...
@@ -5,6 +5,7 @@ export interface Conversation {
endTime
:
string
startTime
:
string
qaNum
:
number
toolId
?:
string
}
export
interface
ConversationState
{
...
...
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