Commit f0801acf by Liu

fix:提质增效增加toolId参数

parent 883b6d47
......@@ -74,16 +74,20 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
return
if (checkAuth()) {
if (content.trim()) {
// 根据选择的工具或默认工具获取toolId
// 只在提质增效模式下传递 toolId,通用模式不传
let toolId: string | undefined
if (selectedToolId) {
// 如果选择了"提质增效"工具,使用对应的toolId
if (!isToolBtnActive && selectedToolId) {
// 提质增效模式:使用选中的 toolId
toolId = selectedToolId
// eslint-disable-next-line no-console
console.log('📤 [ChatEditor] 提质增效模式提交,toolId:', toolId)
}
else if (toolList.length > 0) {
// 如果没有选择工具,使用第一个工具的toolId
toolId = toolList[0].toolId
else {
// 通用模式:不传递 toolId
toolId = undefined
// eslint-disable-next-line no-console
console.log('📤 [ChatEditor] 通用模式提交,不传递 toolId')
}
onSubmit?.(content.trim(), toolId)
setContent('')
......@@ -138,6 +142,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const handleGeneralClick = () => {
// 切换到通用模式(true 表示通用模式,恢复默认不切换左侧)
setIsToolBtnActive(true)
// 清除选中的工具ID
setSelectedToolId(null)
// 调用父组件的回调函数,传递通用模式状态和工具ID,以及是否需要改变样式
onToolClick?.(true, undefined, false)
}
......
......@@ -12,7 +12,7 @@ import { ChatEditor } from '@/components/ChatEditor'
import type { ChatRecord } from '@/types/chat'
import { fetchUserQaRecordPage } from '@/api/conversation'
import { fetchCheckTokenApi, fetchStreamResponse } from '@/api/chat'
import { clearShouldSendQuestion, fetchConversations } from '@/store/conversationSlice'
import { clearCurrentToolId, clearShouldSendQuestion, fetchConversations, setCurrentToolId } from '@/store/conversationSlice'
import type { RootState } from '@/store'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import ScrollBtoIcon from '@/assets/svg/scrollBto.svg?react'
......@@ -24,7 +24,7 @@ export const Chat: React.FC = () => {
const [isLoading, setIsLoading] = useState(false)
const [allItems, setAllItems] = useState<ChatRecord[]>([])
const dispatch = useAppDispatch()
const { shouldSendQuestion } = useAppSelector((state: RootState) => state.conversation)
const { shouldSendQuestion, currentToolId } = useAppSelector((state: RootState) => state.conversation)
const scrollableRef = useRef<HTMLDivElement | any>(null)
const position = useScroll(scrollableRef)
const currentIdRef = useRef<string | undefined>(id)
......@@ -115,6 +115,16 @@ export const Chat: React.FC = () => {
/** 提交问题 */
const handleSubmitQuestion = async (question: string, productCode?: string, toolId?: string) => {
// 打印提交的参数
// eslint-disable-next-line no-console
console.log('📤 [Chat] 提交问题:', {
question,
productCode,
toolId,
conversationId: currentIdRef.current,
模式: toolId ? '提质增效模式' : '通用模式',
})
// 停止之前的请求
if (abortControllerRef.current) {
abortControllerRef.current.abort()
......@@ -264,23 +274,36 @@ export const Chat: React.FC = () => {
dispatch(clearShouldSendQuestion())
// 确保历史记录加载完成后再发送问题
setTimeout(() => {
handleSubmitQuestion(shouldSendQuestion)
handleSubmitQuestion(shouldSendQuestion, undefined, currentToolId)
}, 100)
}
}, [shouldSendQuestion, isLoading])
}, [shouldSendQuestion, isLoading, currentToolId])
// 监听工具按钮点击事件,更新 ChatWelcome 提示语
// 监听工具按钮点击事件,更新 ChatWelcome 提示语和 toolId
useEffect(() => {
const handleToolClickEvent = (event: CustomEvent) => {
const { isToolBtn } = event.detail
const { isToolBtn, toolId } = event.detail
// isToolBtn = true 表示通用模式,false 表示提质增效模式
setIsEfficiencyMode(!isToolBtn)
// 保存当前选择的 toolId 到 Redux
if (!isToolBtn && toolId) {
// 提质增效模式,保存 toolId
dispatch(setCurrentToolId(toolId))
// eslint-disable-next-line no-console
console.log('🔧 [Chat] 切换到提质增效模式,toolId:', toolId)
}
else {
// 通用模式,清除 toolId
dispatch(clearCurrentToolId())
// eslint-disable-next-line no-console
console.log('🔄 [Chat] 切换到通用模式,清除 toolId')
}
}
window.addEventListener('toolButtonClick', handleToolClickEvent as EventListener)
return () => {
window.removeEventListener('toolButtonClick', handleToolClickEvent as EventListener)
}
}, [])
}, [dispatch])
return (
<div className={styles.scrollView}>
......
......@@ -8,7 +8,7 @@ import { QuestionList } from './components/QuestionList'
import HomeIcon1 from '@/assets/homeIcon1.png'
import HomeIcon2 from '@/assets/homeIcon2.png'
import SmartIce from '@/assets/smart-ice.png'
import { createConversation, fetchConversations } from '@/store/conversationSlice'
import { clearCurrentToolId, createConversation, fetchConversations, setCurrentToolId } from '@/store/conversationSlice'
import { useAppDispatch } from '@/store/hook'
import { fetchEfficiencyQuestionList, fetchQuestionList } from '@/api/home'
import SdreamLoading from '@/components/SdreamLoading'
......@@ -149,7 +149,7 @@ finally {
const handleToolClickEvent = (event: CustomEvent) => {
const { isToolBtn, toolId, shouldChangeStyle: shouldChangeStyleParam } = event.detail
// eslint-disable-next-line no-console
console.log('🔧 工具按钮点击事件触发:', {
console.log('🔧 [Home] 工具按钮点击事件触发:', {
isToolBtn,
toolId,
shouldChangeStyle: shouldChangeStyleParam,
......@@ -161,17 +161,28 @@ finally {
if (shouldChangeStyleParam !== undefined) {
setShouldChangeStyle(shouldChangeStyleParam)
}
// eslint-disable-next-line no-console
console.log('✅ isToolBtnActive 已更新为:', isToolBtn)
// eslint-disable-next-line no-console
console.log('🎨 shouldChangeStyle 已更新为:', shouldChangeStyleParam)
// 保存当前选择的 toolId 到 Redux
if (!isToolBtn && toolId) {
// 提质增效模式,保存 toolId
dispatch(setCurrentToolId(toolId))
// eslint-disable-next-line no-console
console.log('✅ [Home] 已保存 toolId 到 Redux:', toolId)
}
else {
// 通用模式,清除 toolId
dispatch(clearCurrentToolId())
// eslint-disable-next-line no-console
console.log('🔄 [Home] 已清除 Redux 中的 toolId')
}
_handleToolClick(isToolBtn, toolId)
}
window.addEventListener('toolButtonClick', handleToolClickEvent as EventListener)
return () => {
window.removeEventListener('toolButtonClick', handleToolClickEvent as EventListener)
}
}, [_handleToolClick, isToolBtnActive, shouldChangeStyle])
}, [_handleToolClick, isToolBtnActive, shouldChangeStyle, dispatch])
const login = useCallback(async () => {
// 防止重复调用
......
......@@ -11,6 +11,7 @@ const initialState: ConversationState = {
error: null,
shouldNavigateToNewConversation: false,
shouldSendQuestion: '',
currentToolId: undefined,
}
export const fetchConversations = createAsyncThunk(
......@@ -93,6 +94,12 @@ const conversationSlice = createSlice({
clearNavigationFlag: (state) => {
state.shouldNavigateToNewConversation = false
},
setCurrentToolId: (state, action: PayloadAction<string | undefined>) => {
state.currentToolId = action.payload
},
clearCurrentToolId: (state) => {
state.currentToolId = undefined
},
removeConversation: (state, action: PayloadAction<string>) => {
state.conversations = state.conversations.filter(conv => conv.conversationId !== action.payload)
if (state.currentConversationId === action.payload) {
......@@ -138,6 +145,6 @@ const conversationSlice = createSlice({
},
})
export const { setCurrentConversation, clearCurrentConversation, clearNavigationFlag, clearShouldSendQuestion, setShouldSendQuestion } = conversationSlice.actions
export const { setCurrentConversation, clearCurrentConversation, clearNavigationFlag, clearShouldSendQuestion, setShouldSendQuestion, setCurrentToolId, clearCurrentToolId } = conversationSlice.actions
export default conversationSlice.reducer
......@@ -14,4 +14,5 @@ export interface ConversationState {
shouldNavigateToNewConversation: boolean
error: string | null
shouldSendQuestion: string
currentToolId: string | undefined
}
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