Commit aba0789f by Liu

fix:auto submit

parent 778f325d
...@@ -8,7 +8,7 @@ import EmptyIcon from '@/assets/svg/empty.svg?react' ...@@ -8,7 +8,7 @@ import EmptyIcon from '@/assets/svg/empty.svg?react'
import { useAppDispatch, useAppSelector } from '@/store/hook' import { useAppDispatch, useAppSelector } from '@/store/hook'
import type { Conversation } from '@/types/conversation' import type { Conversation } from '@/types/conversation'
import { processConversationData } from '@/store/conversationSlice.helper' import { processConversationData } from '@/store/conversationSlice.helper'
import { clearCurrentToolId, setCurrentToolId } from '@/store/conversationSlice' import { clearCurrentToolId, clearShouldSendQuestion, setCurrentToolId, setShouldSendQuestion } from '@/store/conversationSlice'
import { isMobile } from '@/utils' import { isMobile } from '@/utils'
interface HistoryBarListProps { interface HistoryBarListProps {
...@@ -39,6 +39,23 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS ...@@ -39,6 +39,23 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS
sessionStorage.removeItem('currentToolId') sessionStorage.removeItem('currentToolId')
dispatch(clearCurrentToolId()) dispatch(clearCurrentToolId())
} }
// 仅当历史记录为“提质增效”时,进入对话页后自动触发一次提问接口
// 用空格字符串触发 shouldSendQuestion 的监听,但不会在 UI 中新增用户问题气泡(question.trim() 为 false)。
const isQualityImprovement = conversation.toolId === '6712395743241'
if (isQualityImprovement) {
const autoShouldSendQuestion = ' '
dispatch(setShouldSendQuestion(autoShouldSendQuestion))
console.log('[HistoryBarList] shouldSendQuestion 000000:', {
conversationId: conversation.conversationId,
toolId: conversation.toolId,
shouldSendQuestion: autoShouldSendQuestion,
})
}
else {
// 避免上一次残留的 shouldSendQuestion 误触发自动提问
dispatch(clearShouldSendQuestion())
}
// 直接导航到历史记录,不设置shouldSendQuestion // 直接导航到历史记录,不设置shouldSendQuestion
// 在 URL 中拼接 toolId 作为查询参数,以便刷新页面后仍能保留 // 在 URL 中拼接 toolId 作为查询参数,以便刷新页面后仍能保留
const url = conversation.toolId const url = conversation.toolId
......
...@@ -124,6 +124,17 @@ export const Chat: React.FC = () => { ...@@ -124,6 +124,17 @@ export const Chat: React.FC = () => {
console.debug('[Chat] 当前链接 / 缓存 toolId:', debugInfo) console.debug('[Chat] 当前链接 / 缓存 toolId:', debugInfo)
}, [debugInfo]) }, [debugInfo])
// 调试:观察 shouldSendQuestion 在对话页的变化
useEffect(() => {
console.log('[Chat] shouldSendQuestion changed 111111:', {
conversationIdFromRoute: id,
shouldSendQuestion,
currentToolId,
isLoading,
allItemsLength: allItems.length,
})
}, [id, shouldSendQuestion, currentToolId, isLoading, allItems.length])
// 历史记录点击时将 toolId 通过路由 state 传入,优先使用该值快速同步高亮 // 历史记录点击时将 toolId 通过路由 state 传入,优先使用该值快速同步高亮
useEffect(() => { useEffect(() => {
// 保存从 location.state 传递的 toolId 到 ref // 保存从 location.state 传递的 toolId 到 ref
...@@ -717,7 +728,8 @@ export const Chat: React.FC = () => { ...@@ -717,7 +728,8 @@ export const Chat: React.FC = () => {
dispatch(clearShouldSendQuestion()) dispatch(clearShouldSendQuestion())
// 延迟发送,确保状态已更新 // 延迟发送,确保状态已更新
setTimeout(() => { setTimeout(() => {
handleSubmitQuestion(questionToSend, undefined, currentToolId) // 自动触发提问时,不传 workFlowSessionId(与提质增效按钮自动调用保持一致)
handleSubmitQuestion(questionToSend, undefined, currentToolId, { isReask: true })
}, 100) }, 100)
} }
} }
...@@ -820,6 +832,11 @@ export const Chat: React.FC = () => { ...@@ -820,6 +832,11 @@ export const Chat: React.FC = () => {
const canSend = historyLoadedRef.current.conversationId === currentIdRef.current || allItems.length <= 1 const canSend = historyLoadedRef.current.conversationId === currentIdRef.current || allItems.length <= 1
if (canSend) { if (canSend) {
const questionToSend = shouldSendQuestion const questionToSend = shouldSendQuestion
console.log('[Chat] auto send triggered (shouldSendQuestion):', {
conversationId: currentIdRef.current,
question: questionToSend,
currentToolId,
})
lastSentQuestionRef.current = questionToSend lastSentQuestionRef.current = questionToSend
pendingQuestionRef.current = null pendingQuestionRef.current = null
// 立即清除shouldSendQuestion,防止重复发送 // 立即清除shouldSendQuestion,防止重复发送
...@@ -827,7 +844,8 @@ export const Chat: React.FC = () => { ...@@ -827,7 +844,8 @@ export const Chat: React.FC = () => {
// 确保历史记录加载完成后再发送问题 // 确保历史记录加载完成后再发送问题
setTimeout(() => { setTimeout(() => {
console.log('[Chat] 执行自动发送问题:', questionToSend) console.log('[Chat] 执行自动发送问题:', questionToSend)
handleSubmitQuestion(questionToSend, undefined, currentToolId) // 自动触发提问时,不传 workFlowSessionId(与提质增效按钮自动调用保持一致)
handleSubmitQuestion(questionToSend, undefined, currentToolId, { isReask: true })
}, 100) }, 100)
} }
else { else {
......
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