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
37d31ea8
Commit
37d31ea8
authored
Jan 26, 2026
by
weiyudumei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复自动提交触发2次的问题,只在firstQaFlag首次变为true时触发一次
parent
b14e994b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
src/pages/Chat/components/ChatItem/CardWorkflowForm.tsx
+14
-6
No files found.
src/pages/Chat/components/ChatItem/CardWorkflowForm.tsx
View file @
37d31ea8
...
@@ -68,8 +68,15 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
...
@@ -68,8 +68,15 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
// 如果 firstQaFlag 为 true,自动提交(仅对流式返回的新记录,历史记录不会渲染此组件)
// 如果 firstQaFlag 为 true,自动提交(仅对流式返回的新记录,历史记录不会渲染此组件)
useEffect
(()
=>
{
useEffect
(()
=>
{
// 如果 firstQaFlag 为 true,尝试自动提交(不检查是否从 false 变为 true,因为组件可能是在 firstQaFlag 已经是 true 时才渲染的)
// 如果 firstQaFlag 为 true,尝试自动提交
if
(
answer
.
firstQaFlag
===
true
&&
!
hasAutoSubmittedRef
.
current
&&
!
isSubmitting
&&
!
isCompleted
)
{
// 检查 firstQaFlag 是否从 false/undefined 变为 true(首次变为 true)
const
isFirstQaFlagChangedToTrue
=
answer
.
firstQaFlag
===
true
&&
lastFirstQaFlagRef
.
current
!==
true
// 更新记录的值
lastFirstQaFlagRef
.
current
=
answer
.
firstQaFlag
// 只在 firstQaFlag 首次变为 true 且尚未自动提交时执行
if
(
isFirstQaFlagChangedToTrue
&&
!
hasAutoSubmittedRef
.
current
&&
!
isSubmitting
&&
!
isCompleted
)
{
// 检查是否有字段(textFields 不为空)
// 检查是否有字段(textFields 不为空)
if
(
textFields
.
length
===
0
)
{
if
(
textFields
.
length
===
0
)
{
console
.
log
(
'[CardWorkflowForm] 自动提交:textFields 为空,跳过'
)
console
.
log
(
'[CardWorkflowForm] 自动提交:textFields 为空,跳过'
)
...
@@ -93,7 +100,9 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
...
@@ -93,7 +100,9 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
})
})
if
(
allFieldsHaveValues
)
{
if
(
allFieldsHaveValues
)
{
// 立即设置 hasAutoSubmittedRef,防止重复提交
hasAutoSubmittedRef
.
current
=
true
hasAutoSubmittedRef
.
current
=
true
// 构建 paramMap
// 构建 paramMap
const
paramMap
:
Record
<
string
,
string
>
=
{}
const
paramMap
:
Record
<
string
,
string
>
=
{}
textFields
.
forEach
((
field
)
=>
{
textFields
.
forEach
((
field
)
=>
{
...
@@ -119,11 +128,10 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
...
@@ -119,11 +128,10 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
})
})
}
}
}
}
// 更新记录的值
// 移除 onSubmitWorkflow 和 textFields 作为依赖项,使用 useRef 保存引用,避免函数引用变化或 textFields 更新导致重复触发
lastFirstQaFlagRef
.
current
=
answer
.
firstQaFlag
// textFields 更新不应该触发重新提交,因为我们已经检查了 firstQaFlag 的变化
// 移除 onSubmitWorkflow 作为依赖项,使用 useRef 保存引用,避免函数引用变化导致重复触发
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
answer
.
firstQaFlag
,
isSubmitting
,
isCompleted
,
searchParams
,
textFields
])
},
[
answer
.
firstQaFlag
,
isSubmitting
,
isCompleted
,
searchParams
])
const
handleInputChange
=
(
key
:
string
,
value
:
string
)
=>
{
const
handleInputChange
=
(
key
:
string
,
value
:
string
)
=>
{
setFormValues
(
prev
=>
({
setFormValues
(
prev
=>
({
...
...
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