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
f30979f3
Commit
f30979f3
authored
Jan 09, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:切换工具按钮时调用常见问题时机&&切换工具时增加loading
parent
172d8756
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
40 deletions
+56
-40
src/components/ChatEditor/index.tsx
+51
-39
src/pages/Chat/Chat.tsx
+5
-1
No files found.
src/components/ChatEditor/index.tsx
View file @
f30979f3
...
@@ -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
,
conversationId
?:
string
)
=>
void
onToolClick
?:
(
isToolBtn
:
boolean
,
toolId
?:
string
,
toolName
?:
string
,
shouldChangeStyle
?:
boolean
,
conversationId
?:
string
,
isLoading
?:
boolean
)
=>
void
placeholders
:
string
[]
placeholders
:
string
[]
showContentTips
?:
boolean
showContentTips
?:
boolean
initialValue
?:
string
initialValue
?:
string
...
@@ -321,28 +321,30 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -321,28 +321,30 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const
handleGeneralClick
=
async
()
=>
{
const
handleGeneralClick
=
async
()
=>
{
if
(
!
checkAuth
())
if
(
!
checkAuth
())
return
return
// 重置提交按钮状态
// 通知上层开始 loading
dispatch
(
setIsAsking
(
false
))
onToolClick
?.(
true
,
undefined
,
'制度活化'
,
false
,
undefined
,
true
)
// 先更新 Redux,确保状态同步
dispatch
(
clearCurrentToolId
())
// 立即更新本地状态,让 UI 立即响应
setIsToolBtnActive
(
true
)
setSelectedToolId
(
null
)
safeSessionStorageRemoveItem
(
'showToolQuestion'
)
safeSessionStorageRemoveItem
(
'currentToolId'
)
setSessionToolId
(
null
)
setShowToolQuestion
(
false
)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick
?.(
true
,
undefined
,
'制度活化'
,
false
)
// 清空路由中的 toolId 参数
if
(
toolIdFromUrl
)
{
const
newSearchParams
=
new
URLSearchParams
(
searchParams
)
newSearchParams
.
delete
(
'toolId'
)
setSearchParams
(
newSearchParams
,
{
replace
:
true
})
}
// 先调用 fetchSessionConversationId 获取会话ID
try
{
try
{
// 重置提交按钮状态
dispatch
(
setIsAsking
(
false
))
// 先更新 Redux,确保状态同步
dispatch
(
clearCurrentToolId
())
// 立即更新本地状态,让 UI 立即响应
setIsToolBtnActive
(
true
)
setSelectedToolId
(
null
)
safeSessionStorageRemoveItem
(
'showToolQuestion'
)
safeSessionStorageRemoveItem
(
'currentToolId'
)
setSessionToolId
(
null
)
setShowToolQuestion
(
false
)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick
?.(
true
,
undefined
,
'制度活化'
,
false
)
// 清空路由中的 toolId 参数
if
(
toolIdFromUrl
)
{
const
newSearchParams
=
new
URLSearchParams
(
searchParams
)
newSearchParams
.
delete
(
'toolId'
)
setSearchParams
(
newSearchParams
,
{
replace
:
true
})
}
// 先调用 fetchSessionConversationId 获取会话ID
// 等待 token 就绪后再调用接口
// 等待 token 就绪后再调用接口
await
waitForToken
()
await
waitForToken
()
const
requestData
=
{
const
requestData
=
{
...
@@ -383,28 +385,34 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -383,28 +385,34 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 出错时也要清除标记
// 出错时也要清除标记
sessionStorage
.
removeItem
(
'toolHistoryLoading'
)
sessionStorage
.
removeItem
(
'toolHistoryLoading'
)
}
}
finally
{
// 通知上层结束 loading
onToolClick
?.(
true
,
undefined
,
'制度活化'
,
false
,
undefined
,
false
)
}
}
}
// 处理工具按钮点击:先创建新会话,再切换工具
// 处理工具按钮点击:先创建新会话,再切换工具
const
handleToolClick
=
async
(
tool
:
any
)
=>
{
const
handleToolClick
=
async
(
tool
:
any
)
=>
{
// 重置提交按钮状态
// 通知上层开始 loading
dispatch
(
setIsAsking
(
false
))
onToolClick
?.(
false
,
tool
.
toolId
,
tool
.
toolName
,
true
,
undefined
,
true
)
if
(
tool
.
toolName
===
'数据助手'
)
{
safeSessionStorageSetItem
(
'showToolQuestion'
,
'true'
)
setShowToolQuestion
(
true
)
}
else
{
safeSessionStorageRemoveItem
(
'showToolQuestion'
)
setShowToolQuestion
(
false
)
}
dispatch
(
setCurrentToolId
(
tool
.
toolId
))
setSelectedToolId
(
tool
.
toolId
)
setIsToolBtnActive
(
false
)
safeSessionStorageSetItem
(
'currentToolId'
,
tool
.
toolId
)
setSessionToolId
(
tool
.
toolId
)
// 先调用 fetchSessionConversationId 获取会话ID
try
{
try
{
// 重置提交按钮状态
dispatch
(
setIsAsking
(
false
))
if
(
tool
.
toolName
===
'数据助手'
)
{
safeSessionStorageSetItem
(
'showToolQuestion'
,
'true'
)
setShowToolQuestion
(
true
)
}
else
{
safeSessionStorageRemoveItem
(
'showToolQuestion'
)
setShowToolQuestion
(
false
)
}
dispatch
(
setCurrentToolId
(
tool
.
toolId
))
setSelectedToolId
(
tool
.
toolId
)
setIsToolBtnActive
(
false
)
safeSessionStorageSetItem
(
'currentToolId'
,
tool
.
toolId
)
setSessionToolId
(
tool
.
toolId
)
// 先调用 fetchSessionConversationId 获取会话ID
// 等待 token 就绪后再调用接口
// 等待 token 就绪后再调用接口
await
waitForToken
()
await
waitForToken
()
const
requestData
=
{
const
requestData
=
{
...
@@ -450,6 +458,10 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -450,6 +458,10 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 出错时也要清除标记
// 出错时也要清除标记
sessionStorage
.
removeItem
(
'toolHistoryLoading'
)
sessionStorage
.
removeItem
(
'toolHistoryLoading'
)
}
}
finally
{
// 通知上层结束 loading
onToolClick
?.(
false
,
tool
.
toolId
,
tool
.
toolName
,
true
,
undefined
,
false
)
}
}
}
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
src/pages/Chat/Chat.tsx
View file @
f30979f3
...
@@ -859,7 +859,11 @@ export const Chat: React.FC = () => {
...
@@ -859,7 +859,11 @@ 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
,
conversationId
)
=>
{
onToolClick=
{
(
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
,
conversationId
,
isLoading
)
=>
{
// 如果传递了 loading 状态,更新 isLoading
if
(
isLoading
!==
undefined
)
{
setIsLoading
(
isLoading
)
}
// 发送自定义事件到父组件
// 发送自定义事件到父组件
window
.
dispatchEvent
(
new
CustomEvent
(
'toolButtonClick'
,
{
window
.
dispatchEvent
(
new
CustomEvent
(
'toolButtonClick'
,
{
detail
:
{
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
,
conversationId
},
detail
:
{
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
,
conversationId
},
...
...
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