Commit e28c4017 by Liu

fix:提质增效新建会话时逻辑

parent 18a982a3
...@@ -449,8 +449,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -449,8 +449,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
qaRecords: qaRes?.data || [], qaRecords: qaRes?.data || [],
}, },
})) }))
// 提质增效模式下,获取会话ID后立即调用提问接口 // 提质增效模式下,延迟触发自动提问接口
// 使用双重 requestAnimationFrame 确保 Chat 组件的 currentIdRef 已经更新
if (tool.toolId === '6712395743241') { if (tool.toolId === '6712395743241') {
console.log('[ChatEditor] 提质增效模式 - 准备延迟触发 autoSubmitQuestion', { conversationId, toolId: tool.toolId })
requestAnimationFrame(() => {
requestAnimationFrame(() => {
console.log('[ChatEditor] 提质增效模式 - 触发 autoSubmitQuestion 事件', { conversationId, toolId: tool.toolId })
window.dispatchEvent(new CustomEvent('autoSubmitQuestion', { window.dispatchEvent(new CustomEvent('autoSubmitQuestion', {
detail: { detail: {
conversationId, conversationId,
...@@ -460,6 +465,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -460,6 +465,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
busiType: '01', busiType: '01',
}, },
})) }))
})
})
} }
// 清除标记,避免影响后续路由切换 // 清除标记,避免影响后续路由切换
sessionStorage.removeItem('toolHistoryLoading') sessionStorage.removeItem('toolHistoryLoading')
......
...@@ -262,6 +262,15 @@ export const Chat: React.FC = () => { ...@@ -262,6 +262,15 @@ export const Chat: React.FC = () => {
const isEmptyQuestion = !question.trim() const isEmptyQuestion = !question.trim()
const isQualityImprovement = resolvedToolId === '6712395743241' const isQualityImprovement = resolvedToolId === '6712395743241'
isAutoSubmitQualityImprovementRef.current = isEmptyQuestion && isQualityImprovement isAutoSubmitQualityImprovementRef.current = isEmptyQuestion && isQualityImprovement
if (isAutoSubmitQualityImprovementRef.current) {
console.log('[Chat] 提质增效自动调用 - handleSubmitQuestion 被调用', {
question,
resolvedToolId,
conversationId: currentIdRef.current,
isEmptyQuestion,
isQualityImprovement,
})
}
// 停止之前的请求 // 停止之前的请求
if (abortControllerRef.current) { if (abortControllerRef.current) {
abortControllerRef.current.abort() abortControllerRef.current.abort()
...@@ -750,6 +759,8 @@ export const Chat: React.FC = () => { ...@@ -750,6 +759,8 @@ export const Chat: React.FC = () => {
const skipHistoryLoad = Boolean((location.state as { skipHistoryLoad?: boolean } | null)?.skipHistoryLoad) const skipHistoryLoad = Boolean((location.state as { skipHistoryLoad?: boolean } | null)?.skipHistoryLoad)
if (skipHistoryLoad) { if (skipHistoryLoad) {
console.log('[Chat] 检测到 skipHistoryLoad 标记,跳过历史记录加载,直接发送问题') console.log('[Chat] 检测到 skipHistoryLoad 标记,跳过历史记录加载,直接发送问题')
// 清空历史记录,只保留 system 记录(欢迎语)
setAllItems([{ role: 'system' } as ChatRecord])
currentIdRef.current = id currentIdRef.current = id
// 更新 toolId 相关状态(如果有) // 更新 toolId 相关状态(如果有)
if (initialToolId !== undefined) { if (initialToolId !== undefined) {
...@@ -990,10 +1001,25 @@ export const Chat: React.FC = () => { ...@@ -990,10 +1001,25 @@ export const Chat: React.FC = () => {
useEffect(() => { useEffect(() => {
const handleAutoSubmitQuestion = (event: CustomEvent) => { const handleAutoSubmitQuestion = (event: CustomEvent) => {
const { conversationId, question, toolId, recordType, busiType } = event.detail const { conversationId, question, toolId, recordType, busiType } = event.detail
console.log('[Chat] 收到 autoSubmitQuestion 事件', {
eventConversationId: conversationId,
currentIdRef: currentIdRef.current,
match: conversationId === currentIdRef.current,
toolId,
recordType,
busiType,
})
// 确保当前会话ID匹配 // 确保当前会话ID匹配
if (conversationId === currentIdRef.current) { if (conversationId === currentIdRef.current) {
console.log('[Chat] conversationId 匹配,调用 handleSubmitQuestion')
handleSubmitQuestion(question, undefined, toolId, { recordType, busiType }) handleSubmitQuestion(question, undefined, toolId, { recordType, busiType })
} }
else {
console.warn('[Chat] conversationId 不匹配,跳过自动提交', {
eventConversationId: conversationId,
currentIdRef: currentIdRef.current,
})
}
} }
window.addEventListener('autoSubmitQuestion', handleAutoSubmitQuestion as EventListener) window.addEventListener('autoSubmitQuestion', handleAutoSubmitQuestion as EventListener)
return () => { return () => {
......
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