Commit f0801acf by Liu

fix:提质增效增加toolId参数

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