Commit 94e0db57 by Liu

fix: 切换工具时重置按钮

parent a058d446
......@@ -9,6 +9,7 @@ import SendIcon from '@/assets/svg/send.svg?react'
import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { clearCurrentToolId, setCurrentToolId } from '@/store/conversationSlice'
import { setIsAsking } from '@/store/chatSlice'
import { fetchToolList } from '@/api/home'
import { getUserRolesForApi, safeSessionStorageGetItem, safeSessionStorageRemoveItem, safeSessionStorageSetItem } from '@/lib/utils'
import { fetchSessionConversationId, fetchUserQaRecordPage } from '@/api/conversation'
......@@ -299,6 +300,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const handleGeneralClick = async () => {
if (!checkAuth())
return
// 重置提交按钮状态
dispatch(setIsAsking(false))
// 先更新 Redux,确保状态同步
dispatch(clearCurrentToolId())
// 立即更新本地状态,让 UI 立即响应
......@@ -349,6 +352,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 处理工具按钮点击:先创建新会话,再切换工具
const handleToolClick = async (tool: any) => {
// 重置提交按钮状态
dispatch(setIsAsking(false))
if (tool.toolName === '数据助手') {
safeSessionStorageSetItem('showToolQuestion', 'true')
setShowToolQuestion(true)
......
......@@ -274,6 +274,8 @@ export const Chat: React.FC = () => {
// 处理错误
if (msg?.type === 'ERROR') {
// 出错时需要重置 isAsking 状态
dispatch(setIsAsking(false))
// 如果是 AbortError,不显示错误
if (msg.content?.name === 'AbortError') {
return
......@@ -293,6 +295,8 @@ export const Chat: React.FC = () => {
return
}
if (msg.type === 'END') {
// 流式请求正常结束时重置 isAsking 状态
dispatch(setIsAsking(false))
if (isNew) {
setTimeout(() => {
dispatch(fetchConversations())
......
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