Commit f30979f3 by Liu

fix:切换工具按钮时调用常见问题时机&&切换工具时增加loading

parent 172d8756
......@@ -18,7 +18,7 @@ interface ChatEditorProps {
onChange?: (value: string) => void
onFocus?: () => 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[]
showContentTips?: boolean
initialValue?: string
......@@ -321,6 +321,9 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const handleGeneralClick = async () => {
if (!checkAuth())
return
// 通知上层开始 loading
onToolClick?.(true, undefined, '制度活化', false, undefined, true)
try {
// 重置提交按钮状态
dispatch(setIsAsking(false))
// 先更新 Redux,确保状态同步
......@@ -342,7 +345,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}
// 先调用 fetchSessionConversationId 获取会话ID
try {
// 等待 token 就绪后再调用接口
await waitForToken()
const requestData = {
......@@ -383,10 +385,17 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 出错时也要清除标记
sessionStorage.removeItem('toolHistoryLoading')
}
finally {
// 通知上层结束 loading
onToolClick?.(true, undefined, '制度活化', false, undefined, false)
}
}
// 处理工具按钮点击:先创建新会话,再切换工具
const handleToolClick = async (tool: any) => {
// 通知上层开始 loading
onToolClick?.(false, tool.toolId, tool.toolName, true, undefined, true)
try {
// 重置提交按钮状态
dispatch(setIsAsking(false))
if (tool.toolName === '数据助手') {
......@@ -404,7 +413,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setSessionToolId(tool.toolId)
// 先调用 fetchSessionConversationId 获取会话ID
try {
// 等待 token 就绪后再调用接口
await waitForToken()
const requestData = {
......@@ -450,6 +458,10 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 出错时也要清除标记
sessionStorage.removeItem('toolHistoryLoading')
}
finally {
// 通知上层结束 loading
onToolClick?.(false, tool.toolId, tool.toolName, true, undefined, false)
}
}
useEffect(() => {
......
......@@ -859,7 +859,11 @@ export const Chat: React.FC = () => {
</div>
<ChatEditor
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', {
detail: { isToolBtn, toolId, toolName, shouldChangeStyle, conversationId },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment