Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
2549858d
Commit
2549858d
authored
Feb 03, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:提质增效自动调用提问接口不传workFlowSessionId
parent
15ee66aa
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
92 deletions
+7
-92
src/pages/Chat/Chat.tsx
+7
-92
No files found.
src/pages/Chat/Chat.tsx
View file @
2549858d
...
@@ -121,7 +121,6 @@ export const Chat: React.FC = () => {
...
@@ -121,7 +121,6 @@ export const Chat: React.FC = () => {
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
debugInfo
.
href
&&
!
debugInfo
.
sessionToolId
)
if
(
!
debugInfo
.
href
&&
!
debugInfo
.
sessionToolId
)
return
return
console
.
debug
(
'[Chat] 当前链接 / 缓存 toolId:'
,
debugInfo
)
console
.
debug
(
'[Chat] 当前链接 / 缓存 toolId:'
,
debugInfo
)
},
[
debugInfo
])
},
[
debugInfo
])
...
@@ -284,13 +283,6 @@ export const Chat: React.FC = () => {
...
@@ -284,13 +283,6 @@ export const Chat: React.FC = () => {
// 重置欢迎语候选
// 重置欢迎语候选
autoWelcomeCandidateRef
.
current
=
''
autoWelcomeCandidateRef
.
current
=
''
hasAutoWelcomeCandidateRef
.
current
=
false
hasAutoWelcomeCandidateRef
.
current
=
false
console
.
log
(
'[Chat] 提质增效自动调用 - handleSubmitQuestion 被调用'
,
{
question
,
resolvedToolId
,
conversationId
:
currentIdRef
.
current
,
isEmptyQuestion
,
isQualityImprovement
,
})
}
}
// 停止之前的请求
// 停止之前的请求
if
(
abortControllerRef
.
current
)
{
if
(
abortControllerRef
.
current
)
{
...
@@ -358,11 +350,14 @@ export const Chat: React.FC = () => {
...
@@ -358,11 +350,14 @@ export const Chat: React.FC = () => {
// workFlowSessionId 的传递逻辑:
// workFlowSessionId 的传递逻辑:
// 1. 如果是重新问答(isReask === true),不传递 workFlowSessionId
// 1. 如果是重新问答(isReask === true),不传递 workFlowSessionId
// 2. 优先使用 extraParams 中的值
// 2. 如果是提质增效模式的自动调用(空问题),不传递 workFlowSessionId
// 3. 其次使用直接传递的参数
// 3. 优先使用 extraParams 中的值
// 4. 如果都没有,从会话历史中找到最后一个有 workFlowSessionId 的答案
// 4. 其次使用直接传递的参数
// 5. 如果都没有,从会话历史中找到最后一个有 workFlowSessionId 的答案
const
isReask
=
extraParams
?.
isReask
===
true
const
isReask
=
extraParams
?.
isReask
===
true
if
(
!
isReask
)
{
// 判断是否为提质增效自动调用:空问题且 toolId 为提质增效
const
isAutoQualityImprovement
=
isAutoSubmitQualityImprovementRef
.
current
if
(
!
isReask
&&
!
isAutoQualityImprovement
)
{
if
(
extraParams
?.
workFlowSessionId
)
{
if
(
extraParams
?.
workFlowSessionId
)
{
requestBody
.
workFlowSessionId
=
extraParams
.
workFlowSessionId
requestBody
.
workFlowSessionId
=
extraParams
.
workFlowSessionId
}
}
...
@@ -456,7 +451,6 @@ export const Chat: React.FC = () => {
...
@@ -456,7 +451,6 @@ export const Chat: React.FC = () => {
// 正常的stream数据
// 正常的stream数据
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'00000000'
)
{
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'00000000'
)
{
console
.
log
(
'========================流式输出===================='
,
msg
)
console
.
log
(
'========================流式输出===================='
,
msg
)
console
.
log
(
'========================流式输出字符串===================='
,
msg
.
content
?.
data
)
console
.
log
(
'========================流式输出字符串===================='
,
msg
.
content
?.
data
)
handleStreamMesageData
(
msg
,
question
)
handleStreamMesageData
(
msg
,
question
)
}
}
...
@@ -553,10 +547,8 @@ export const Chat: React.FC = () => {
...
@@ -553,10 +547,8 @@ export const Chat: React.FC = () => {
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
,
toolId
?:
string
)
=>
{
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
,
toolId
?:
string
)
=>
{
// 检查是否正在处理相同的 conversationId,避免重复调用
// 检查是否正在处理相同的 conversationId,避免重复调用
if
(
processingConversationIdRef
.
current
===
conversationId
)
{
if
(
processingConversationIdRef
.
current
===
conversationId
)
{
console
.
log
(
'[Chat] 正在处理相同的 conversationId,跳过重复调用:'
,
conversationId
)
return
return
}
}
setIsLoading
(
true
)
setIsLoading
(
true
)
// 标记正在处理
// 标记正在处理
processingConversationIdRef
.
current
=
conversationId
processingConversationIdRef
.
current
=
conversationId
...
@@ -566,7 +558,6 @@ export const Chat: React.FC = () => {
...
@@ -566,7 +558,6 @@ export const Chat: React.FC = () => {
// 检测是否从收藏页返回(优先使用 ref 中保存的值,避免 location.state 被清除后丢失)
// 检测是否从收藏页返回(优先使用 ref 中保存的值,避免 location.state 被清除后丢失)
// 增加 sessionStorage 检查,用于 navigate(-1) 的情况
// 增加 sessionStorage 检查,用于 navigate(-1) 的情况
const
fromCollect
=
fromCollectRef
.
current
||
Boolean
(
location
.
state
?.
fromCollect
)
||
Boolean
(
sessionStorage
.
getItem
(
'fromCollect'
))
const
fromCollect
=
fromCollectRef
.
current
||
Boolean
(
location
.
state
?.
fromCollect
)
||
Boolean
(
sessionStorage
.
getItem
(
'fromCollect'
))
// 如果从收藏页返回,先调用 get_user_conversation_session 获取新的会话ID
// 如果从收藏页返回,先调用 get_user_conversation_session 获取新的会话ID
if
(
fromCollect
&&
!
fromCollectProcessedRef
.
current
)
{
if
(
fromCollect
&&
!
fromCollectProcessedRef
.
current
)
{
fromCollectProcessedRef
.
current
=
true
fromCollectProcessedRef
.
current
=
true
...
@@ -576,7 +567,6 @@ export const Chat: React.FC = () => {
...
@@ -576,7 +567,6 @@ export const Chat: React.FC = () => {
const
sessionRes
=
await
fetchSessionConversationId
({
busiId
:
sessionToolId
})
const
sessionRes
=
await
fetchSessionConversationId
({
busiId
:
sessionToolId
})
if
(
sessionRes
?.
data
?.
conversationId
)
{
if
(
sessionRes
?.
data
?.
conversationId
)
{
finalConversationId
=
sessionRes
.
data
.
conversationId
finalConversationId
=
sessionRes
.
data
.
conversationId
console
.
log
(
'[Chat] 从收藏返回 - 获取到新会话ID:'
,
finalConversationId
)
// 如果获取到新会话ID,设置标记避免路由变化时重复调用
// 如果获取到新会话ID,设置标记避免路由变化时重复调用
toolHistoryLoadedRef
.
current
.
conversationId
=
finalConversationId
toolHistoryLoadedRef
.
current
.
conversationId
=
finalConversationId
// 更新 processingConversationIdRef 为新会话ID,避免使用旧ID重复调用
// 更新 processingConversationIdRef 为新会话ID,避免使用旧ID重复调用
...
@@ -592,8 +582,6 @@ export const Chat: React.FC = () => {
...
@@ -592,8 +582,6 @@ export const Chat: React.FC = () => {
// 如果从收藏页返回,触发事件通知 HomeNew 刷新问题列表
// 如果从收藏页返回,触发事件通知 HomeNew 刷新问题列表
if
(
fromCollect
)
{
if
(
fromCollect
)
{
const
eventToolId
=
toolId
||
currentToolId
||
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
const
eventToolId
=
toolId
||
currentToolId
||
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
console
.
log
(
'[Chat] 检测到从收藏页返回 (fromCollect=true) - 准备触发 refreshQuestionsFromCollect 事件'
)
console
.
log
(
'[Chat] refreshQuestionsFromCollect - 传递的 toolId:'
,
eventToolId
)
// 清除 sessionStorage 中的标记,避免影响后续路由
// 清除 sessionStorage 中的标记,避免影响后续路由
sessionStorage
.
removeItem
(
'fromCollect'
)
sessionStorage
.
removeItem
(
'fromCollect'
)
// 延迟触发事件,确保 Home 组件的监听器已注册
// 延迟触发事件,确保 Home 组件的监听器已注册
...
@@ -603,12 +591,10 @@ export const Chat: React.FC = () => {
...
@@ -603,12 +591,10 @@ export const Chat: React.FC = () => {
toolId
:
eventToolId
,
toolId
:
eventToolId
,
},
},
}))
}))
console
.
log
(
'[Chat] refreshQuestionsFromCollect 事件已触发'
)
},
100
)
},
100
)
}
}
await
waitForToken
()
await
waitForToken
()
const
res
=
await
fetchUserQaRecordPage
(
finalConversationId
,
toolId
||
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
)
const
res
=
await
fetchUserQaRecordPage
(
finalConversationId
,
toolId
||
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
)
console
.
log
(
'qaRes chatEditor2222222'
,
res
)
const
qaRecords
=
res
.
data
||
[]
const
qaRecords
=
res
.
data
||
[]
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
qaRecords
)]
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
qaRecords
)]
// 处理历史记录中的参考文档标记
// 处理历史记录中的参考文档标记
...
@@ -631,10 +617,8 @@ export const Chat: React.FC = () => {
...
@@ -631,10 +617,8 @@ export const Chat: React.FC = () => {
// 优先从 qaRecords 中查找 toolId(这是实际使用的)
// 优先从 qaRecords 中查找 toolId(这是实际使用的)
const
latestToolId
=
[...
qaRecords
].
reverse
().
find
(
item
=>
Boolean
(
item
.
toolId
))?.
toolId
?.
trim
?.()
const
latestToolId
=
[...
qaRecords
].
reverse
().
find
(
item
=>
Boolean
(
item
.
toolId
))?.
toolId
?.
trim
?.()
const
hasQaRecords
=
qaRecords
.
length
>
0
const
hasQaRecords
=
qaRecords
.
length
>
0
// 如果 qaRecords 中没有 toolId,尝试从 conversations 中查找当前会话的 toolId(会话级别)
// 如果 qaRecords 中没有 toolId,尝试从 conversations 中查找当前会话的 toolId(会话级别)
const
conversationToolId
=
latestToolId
||
(
conversations
.
find
(
conv
=>
conv
.
conversationId
===
finalConversationId
)?.
toolId
?.
trim
?.())
const
conversationToolId
=
latestToolId
||
(
conversations
.
find
(
conv
=>
conv
.
conversationId
===
finalConversationId
)?.
toolId
?.
trim
?.())
// 优先使用从 location.state 传递的 toolId(如果存在),这是从历史记录点击传递过来的
// 优先使用从 location.state 传递的 toolId(如果存在),这是从历史记录点击传递过来的
const
toolIdFromState
=
toolIdFromStateRef
.
current
!==
undefined
const
toolIdFromState
=
toolIdFromStateRef
.
current
!==
undefined
?
(
toolIdFromStateRef
.
current
?
String
(
toolIdFromStateRef
.
current
)
:
null
)
?
(
toolIdFromStateRef
.
current
?
String
(
toolIdFromStateRef
.
current
)
:
null
)
...
@@ -706,13 +690,6 @@ export const Chat: React.FC = () => {
...
@@ -706,13 +690,6 @@ export const Chat: React.FC = () => {
setIsLoading
(
false
)
setIsLoading
(
false
)
// 标记该会话的历史记录已加载完成
// 标记该会话的历史记录已加载完成
historyLoadedRef
.
current
.
conversationId
=
finalConversationId
historyLoadedRef
.
current
.
conversationId
=
finalConversationId
console
.
log
(
'[Chat] 历史记录加载完成:'
,
{
finalConversationId
,
currentIdRef
:
currentIdRef
.
current
,
pendingQuestion
:
pendingQuestionRef
.
current
,
lastSentQuestion
:
lastSentQuestionRef
.
current
,
})
// 清除处理标记(支持新会话ID的情况)
// finalConversationId 可能是新会话ID(从收藏返回时)或原来的 conversationId
// finalConversationId 可能是新会话ID(从收藏返回时)或原来的 conversationId
if
(
processingConversationIdRef
.
current
===
finalConversationId
)
{
if
(
processingConversationIdRef
.
current
===
finalConversationId
)
{
processingConversationIdRef
.
current
=
null
processingConversationIdRef
.
current
=
null
...
@@ -720,33 +697,17 @@ export const Chat: React.FC = () => {
...
@@ -720,33 +697,17 @@ export const Chat: React.FC = () => {
// 如果历史记录加载完成且有待发送的问题,触发自动发送
// 如果历史记录加载完成且有待发送的问题,触发自动发送
if
(
pendingQuestionRef
.
current
&&
finalConversationId
===
currentIdRef
.
current
)
{
if
(
pendingQuestionRef
.
current
&&
finalConversationId
===
currentIdRef
.
current
)
{
const
questionToSend
=
pendingQuestionRef
.
current
const
questionToSend
=
pendingQuestionRef
.
current
console
.
log
(
'[Chat] 历史记录加载完成,检查待发送问题:'
,
{
questionToSend
,
lastSentQuestion
:
lastSentQuestionRef
.
current
,
})
// 检查是否已经发送过相同的问题
// 检查是否已经发送过相同的问题
if
(
questionToSend
!==
lastSentQuestionRef
.
current
)
{
if
(
questionToSend
!==
lastSentQuestionRef
.
current
)
{
console
.
log
(
'[Chat] 触发待发送问题的自动发送:'
,
questionToSend
)
lastSentQuestionRef
.
current
=
questionToSend
lastSentQuestionRef
.
current
=
questionToSend
pendingQuestionRef
.
current
=
null
pendingQuestionRef
.
current
=
null
// 清除 shouldSendQuestion(如果还存在)
// 清除 shouldSendQuestion(如果还存在)
dispatch
(
clearShouldSendQuestion
())
dispatch
(
clearShouldSendQuestion
())
// 延迟发送,确保状态已更新
// 延迟发送,确保状态已更新
setTimeout
(()
=>
{
setTimeout
(()
=>
{
console
.
log
(
'[Chat] 执行待发送问题的提交:'
,
questionToSend
)
handleSubmitQuestion
(
questionToSend
,
undefined
,
currentToolId
)
handleSubmitQuestion
(
questionToSend
,
undefined
,
currentToolId
)
},
100
)
},
100
)
}
}
else
{
console
.
log
(
'[Chat] 待发送问题与已发送问题相同,跳过发送'
)
}
}
else
if
(
pendingQuestionRef
.
current
)
{
console
.
log
(
'[Chat] 有待发送问题但 conversationId 不匹配,等待:'
,
{
pendingQuestion
:
pendingQuestionRef
.
current
,
finalConversationId
,
currentIdRef
:
currentIdRef
.
current
,
})
}
}
}
}
},
[
dispatch
,
currentToolId
,
conversations
,
location
.
state
])
},
[
dispatch
,
currentToolId
,
conversations
,
location
.
state
])
...
@@ -767,7 +728,6 @@ export const Chat: React.FC = () => {
...
@@ -767,7 +728,6 @@ export const Chat: React.FC = () => {
// 检查是否已通过 toolHistoryLoaded 事件加载过相同会话的数据
// 检查是否已通过 toolHistoryLoaded 事件加载过相同会话的数据
// 如果已加载,跳过接口调用,避免重复请求
// 如果已加载,跳过接口调用,避免重复请求
if
(
toolHistoryLoadedRef
.
current
.
conversationId
===
id
)
{
if
(
toolHistoryLoadedRef
.
current
.
conversationId
===
id
)
{
console
.
log
(
'[Chat] 已通过 toolHistoryLoaded 加载,跳过历史记录接口调用'
)
// 已加载,清除标记,避免影响后续正常的路由切换
// 已加载,清除标记,避免影响后续正常的路由切换
toolHistoryLoadedRef
.
current
.
conversationId
=
null
toolHistoryLoadedRef
.
current
.
conversationId
=
null
// 更新 currentIdRef,确保状态一致
// 更新 currentIdRef,确保状态一致
...
@@ -779,7 +739,6 @@ export const Chat: React.FC = () => {
...
@@ -779,7 +739,6 @@ export const Chat: React.FC = () => {
// 通过 sessionStorage 标记判断,避免时序问题导致的重复调用
// 通过 sessionStorage 标记判断,避免时序问题导致的重复调用
const
toolHistoryLoadingId
=
sessionStorage
.
getItem
(
'toolHistoryLoading'
)
const
toolHistoryLoadingId
=
sessionStorage
.
getItem
(
'toolHistoryLoading'
)
if
(
toolHistoryLoadingId
===
id
)
{
if
(
toolHistoryLoadingId
===
id
)
{
console
.
log
(
'[Chat] 检测到 toolHistoryLoading 标记,ChatEditor 正在加载历史记录,跳过重复调用'
)
currentIdRef
.
current
=
id
currentIdRef
.
current
=
id
// 更新 toolId 相关状态(如果有)
// 更新 toolId 相关状态(如果有)
if
(
initialToolId
!==
undefined
)
{
if
(
initialToolId
!==
undefined
)
{
...
@@ -791,9 +750,6 @@ export const Chat: React.FC = () => {
...
@@ -791,9 +750,6 @@ 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 标记,跳过历史记录加载,直接发送问题'
)
// 不清空已有对话:常见问题点击应在当前对话基础上继续追加
// 仅当当前为空时,确保存在 system 记录(欢迎语占位)
setAllItems
(
prev
=>
(
prev
.
length
>
0
?
prev
:
([{
role
:
'system'
}
as
ChatRecord
])))
setAllItems
(
prev
=>
(
prev
.
length
>
0
?
prev
:
([{
role
:
'system'
}
as
ChatRecord
])))
currentIdRef
.
current
=
id
currentIdRef
.
current
=
id
// 更新 toolId 相关状态(如果有)
// 更新 toolId 相关状态(如果有)
...
@@ -807,23 +763,10 @@ export const Chat: React.FC = () => {
...
@@ -807,23 +763,10 @@ export const Chat: React.FC = () => {
if
(
currentIdRef
.
current
===
id
)
{
if
(
currentIdRef
.
current
===
id
)
{
// 检查是否从收藏页返回(需要重新加载历史记录)
// 检查是否从收藏页返回(需要重新加载历史记录)
const
fromCollect
=
Boolean
(
location
.
state
?.
fromCollect
)
||
Boolean
(
sessionStorage
.
getItem
(
'fromCollect'
))
const
fromCollect
=
Boolean
(
location
.
state
?.
fromCollect
)
||
Boolean
(
sessionStorage
.
getItem
(
'fromCollect'
))
console
.
log
(
'[Chat] conversationId 相同,检查是否需要重新加载:'
,
{
fromCollect
,
locationStateFromCollect
:
location
.
state
?.
fromCollect
,
sessionStorageFromCollect
:
sessionStorage
.
getItem
(
'fromCollect'
),
allItemsLength
:
allItems
.
length
,
})
// 如果 allItems 为空,说明是首次加载,需要加载历史记录
// 如果 allItems 为空,说明是首次加载,需要加载历史记录
if
(
!
fromCollect
&&
allItems
.
length
>
0
)
{
if
(
!
fromCollect
&&
allItems
.
length
>
0
)
{
console
.
log
(
'[Chat] 路由不变且非收藏页返回,跳过历史记录加载,只更新 toolId'
)
// 不是从收藏页返回,只是 location.state 变化(比如点击常见问题但路由不变),
// 不应该重新加载历史记录,只需要更新 toolId 相关状态
// toolId 的更新逻辑在 useEffect 中处理(120-134行)
return
return
}
}
console
.
log
(
'[Chat] 从收藏页返回,即使 conversationId 相同也重新加载历史记录'
)
// 如果是从收藏页返回,即使 conversationId 相同,也需要重新加载历史记录
// 因为收藏页返回时可能会获取新的会话ID(在 getUserQaRecordPage 中处理)
}
}
// 停止之前的请求
// 停止之前的请求
...
@@ -831,8 +774,6 @@ export const Chat: React.FC = () => {
...
@@ -831,8 +774,6 @@ export const Chat: React.FC = () => {
abortControllerRef
.
current
.
abort
()
abortControllerRef
.
current
.
abort
()
dispatch
(
setIsAsking
(
false
))
dispatch
(
setIsAsking
(
false
))
}
}
console
.
log
(
'[Chat] 开始加载历史记录,重置相关状态'
)
currentIdRef
.
current
=
id
currentIdRef
.
current
=
id
lastSentQuestionRef
.
current
=
''
// 重置标记
lastSentQuestionRef
.
current
=
''
// 重置标记
pendingQuestionRef
.
current
=
null
// 清除待发送的问题
pendingQuestionRef
.
current
=
null
// 清除待发送的问题
...
@@ -848,7 +789,6 @@ export const Chat: React.FC = () => {
...
@@ -848,7 +789,6 @@ export const Chat: React.FC = () => {
// 等待 token 就绪后再调用接口
// 等待 token 就绪后再调用接口
waitForToken
().
then
(()
=>
{
waitForToken
().
then
(()
=>
{
console
.
log
(
'[Chat] Token 就绪,调用 getUserQaRecordPage:'
,
id
)
getUserQaRecordPage
(
id
)
getUserQaRecordPage
(
id
)
})
})
}
}
...
@@ -856,15 +796,6 @@ export const Chat: React.FC = () => {
...
@@ -856,15 +796,6 @@ export const Chat: React.FC = () => {
// 处理shouldSendQuestion的变化 - 自动发送问题
// 处理shouldSendQuestion的变化 - 自动发送问题
useEffect
(()
=>
{
useEffect
(()
=>
{
console
.
log
(
'[Chat] shouldSendQuestion 变化检查:'
,
{
shouldSendQuestion
,
currentIdRef
:
currentIdRef
.
current
,
isLoading
,
lastSentQuestion
:
lastSentQuestionRef
.
current
,
historyLoadedId
:
historyLoadedRef
.
current
.
conversationId
,
allItemsLength
:
allItems
.
length
,
pendingQuestion
:
pendingQuestionRef
.
current
,
})
if
(
if
(
shouldSendQuestion
shouldSendQuestion
&&
currentIdRef
.
current
&&
currentIdRef
.
current
...
@@ -875,14 +806,8 @@ export const Chat: React.FC = () => {
...
@@ -875,14 +806,8 @@ export const Chat: React.FC = () => {
// 如果历史记录已加载完成(historyLoadedRef.current.conversationId === currentIdRef.current),可以立即发送
// 如果历史记录已加载完成(historyLoadedRef.current.conversationId === currentIdRef.current),可以立即发送
// 如果是新会话(allItems.length <= 1),可以立即发送
// 如果是新会话(allItems.length <= 1),可以立即发送
const
canSend
=
historyLoadedRef
.
current
.
conversationId
===
currentIdRef
.
current
||
allItems
.
length
<=
1
const
canSend
=
historyLoadedRef
.
current
.
conversationId
===
currentIdRef
.
current
||
allItems
.
length
<=
1
console
.
log
(
'[Chat] 自动发送问题判断:'
,
{
canSend
,
historyLoaded
:
historyLoadedRef
.
current
.
conversationId
===
currentIdRef
.
current
,
isNewSession
:
allItems
.
length
<=
1
,
})
if
(
canSend
)
{
if
(
canSend
)
{
const
questionToSend
=
shouldSendQuestion
const
questionToSend
=
shouldSendQuestion
console
.
log
(
'[Chat] 可以立即发送,准备发送问题:'
,
questionToSend
)
lastSentQuestionRef
.
current
=
questionToSend
lastSentQuestionRef
.
current
=
questionToSend
pendingQuestionRef
.
current
=
null
pendingQuestionRef
.
current
=
null
// 立即清除shouldSendQuestion,防止重复发送
// 立即清除shouldSendQuestion,防止重复发送
...
@@ -894,7 +819,6 @@ export const Chat: React.FC = () => {
...
@@ -894,7 +819,6 @@ export const Chat: React.FC = () => {
},
100
)
},
100
)
}
}
else
{
else
{
console
.
log
(
'[Chat] 历史记录还在加载中,保存待发送问题到 pendingQuestionRef:'
,
shouldSendQuestion
)
// 如果历史记录还在加载中,保存待发送的问题,等待历史记录加载完成后再发送
// 如果历史记录还在加载中,保存待发送的问题,等待历史记录加载完成后再发送
pendingQuestionRef
.
current
=
shouldSendQuestion
pendingQuestionRef
.
current
=
shouldSendQuestion
}
}
...
@@ -1035,17 +959,8 @@ export const Chat: React.FC = () => {
...
@@ -1035,17 +959,8 @@ 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
{
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment