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
186aef40
Commit
186aef40
authored
Jan 09, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:常见问题调用时机
parent
dede7a75
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
7 deletions
+10
-7
src/components/ChatEditor/index.tsx
+5
-3
src/pages/Chat/Chat.tsx
+2
-2
src/pages/Home/HomeNew.tsx
+3
-2
No files found.
src/components/ChatEditor/index.tsx
View file @
186aef40
...
@@ -18,7 +18,7 @@ interface ChatEditorProps {
...
@@ -18,7 +18,7 @@ interface ChatEditorProps {
onChange
?:
(
value
:
string
)
=>
void
onChange
?:
(
value
:
string
)
=>
void
onFocus
?:
()
=>
void
onFocus
?:
()
=>
void
onSubmit
?:
(
value
:
string
,
toolId
?:
string
)
=>
void
onSubmit
?:
(
value
:
string
,
toolId
?:
string
)
=>
void
onToolClick
?:
(
isToolBtn
:
boolean
,
toolId
?:
string
,
toolName
?:
string
,
shouldChangeStyle
?:
boolean
)
=>
void
onToolClick
?:
(
isToolBtn
:
boolean
,
toolId
?:
string
,
toolName
?:
string
,
shouldChangeStyle
?:
boolean
,
conversationId
?:
string
)
=>
void
placeholders
:
string
[]
placeholders
:
string
[]
showContentTips
?:
boolean
showContentTips
?:
boolean
initialValue
?:
string
initialValue
?:
string
...
@@ -402,8 +402,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -402,8 +402,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setIsToolBtnActive
(
false
)
setIsToolBtnActive
(
false
)
safeSessionStorageSetItem
(
'currentToolId'
,
tool
.
toolId
)
safeSessionStorageSetItem
(
'currentToolId'
,
tool
.
toolId
)
setSessionToolId
(
tool
.
toolId
)
setSessionToolId
(
tool
.
toolId
)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick
?.(
false
,
tool
.
toolId
,
tool
.
toolName
,
true
)
// 先调用 fetchSessionConversationId 获取会话ID
// 先调用 fetchSessionConversationId 获取会话ID
try
{
try
{
...
@@ -415,6 +413,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -415,6 +413,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const
res
=
await
fetchSessionConversationId
(
requestData
)
const
res
=
await
fetchSessionConversationId
(
requestData
)
if
(
res
?.
data
?.
conversationId
)
{
if
(
res
?.
data
?.
conversationId
)
{
const
conversationId
=
res
.
data
.
conversationId
const
conversationId
=
res
.
data
.
conversationId
// 获取到会话ID后,通知上层更新欢迎语并传递 conversationId
onToolClick
?.(
false
,
tool
.
toolId
,
tool
.
toolName
,
true
,
conversationId
)
// 在 navigate 之前设置标记,避免 Chat 组件的 useEffect 重复调用接口
// 在 navigate 之前设置标记,避免 Chat 组件的 useEffect 重复调用接口
// 使用 sessionStorage 作为标记,因为 location.state 可能有时序问题
// 使用 sessionStorage 作为标记,因为 location.state 可能有时序问题
sessionStorage
.
setItem
(
'toolHistoryLoading'
,
conversationId
)
sessionStorage
.
setItem
(
'toolHistoryLoading'
,
conversationId
)
...
@@ -445,6 +445,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -445,6 +445,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}
}
catch
(
error
)
{
catch
(
error
)
{
console
.
error
(
'获取会话ID或历史记录失败:'
,
error
)
console
.
error
(
'获取会话ID或历史记录失败:'
,
error
)
// 出错时也要通知上层更新欢迎语(不传递 conversationId)
onToolClick
?.(
false
,
tool
.
toolId
,
tool
.
toolName
,
true
)
// 出错时也要清除标记
// 出错时也要清除标记
sessionStorage
.
removeItem
(
'toolHistoryLoading'
)
sessionStorage
.
removeItem
(
'toolHistoryLoading'
)
}
}
...
...
src/pages/Chat/Chat.tsx
View file @
186aef40
...
@@ -859,10 +859,10 @@ export const Chat: React.FC = () => {
...
@@ -859,10 +859,10 @@ export const Chat: React.FC = () => {
</
div
>
</
div
>
<
ChatEditor
<
ChatEditor
onSubmit=
{
(
question
,
toolId
)
=>
handleSubmitQuestion
(
question
,
undefined
,
toolId
)
}
onSubmit=
{
(
question
,
toolId
)
=>
handleSubmitQuestion
(
question
,
undefined
,
toolId
)
}
onToolClick=
{
(
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
)
=>
{
onToolClick=
{
(
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
,
conversationId
)
=>
{
// 发送自定义事件到父组件
// 发送自定义事件到父组件
window
.
dispatchEvent
(
new
CustomEvent
(
'toolButtonClick'
,
{
window
.
dispatchEvent
(
new
CustomEvent
(
'toolButtonClick'
,
{
detail
:
{
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
},
detail
:
{
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
,
conversationId
},
}))
}))
}
}
}
}
placeholders=
{
[]
}
placeholders=
{
[]
}
...
...
src/pages/Home/HomeNew.tsx
View file @
186aef40
...
@@ -241,7 +241,7 @@ export const Home: React.FC = () => {
...
@@ -241,7 +241,7 @@ export const Home: React.FC = () => {
// 监听工具按钮点击事件
// 监听工具按钮点击事件
useEffect
(()
=>
{
useEffect
(()
=>
{
const
handleToolClickEvent
=
(
event
:
CustomEvent
)
=>
{
const
handleToolClickEvent
=
(
event
:
CustomEvent
)
=>
{
const
{
isToolBtn
,
toolId
}
=
event
.
detail
const
{
isToolBtn
,
toolId
,
conversationId
}
=
event
.
detail
setIsToolBtnActive
(
isToolBtn
)
setIsToolBtnActive
(
isToolBtn
)
// 更新样式控制状态
// 更新样式控制状态
setShouldChangeStyle
(
true
)
setShouldChangeStyle
(
true
)
...
@@ -256,7 +256,8 @@ export const Home: React.FC = () => {
...
@@ -256,7 +256,8 @@ export const Home: React.FC = () => {
dispatch
(
clearCurrentToolId
())
dispatch
(
clearCurrentToolId
())
}
}
_handleToolClick
(
isToolBtn
,
toolId
)
// 传递 conversationId 给 _handleToolClick
_handleToolClick
(
isToolBtn
,
toolId
,
false
,
conversationId
)
}
}
window
.
addEventListener
(
'toolButtonClick'
,
handleToolClickEvent
as
EventListener
)
window
.
addEventListener
(
'toolButtonClick'
,
handleToolClickEvent
as
EventListener
)
return
()
=>
{
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