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
b23d7f44
Commit
b23d7f44
authored
Jan 23, 2026
by
weiyudumei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复 workflow 卡片自动提交重复触发的问题,使用 useRef 和 useCallback 稳定函数引用
parent
6ae9376c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
src/pages/Chat/Chat.tsx
+2
-2
src/pages/Chat/components/ChatItem/CardWorkflowForm.tsx
+10
-3
src/pages/ChatTactics/TacticsChat.tsx
+2
-2
No files found.
src/pages/Chat/Chat.tsx
View file @
b23d7f44
...
...
@@ -409,7 +409,7 @@ export const Chat: React.FC = () => {
}
/** 处理 workflow 表单提交 */
const
handleWorkflowSubmit
=
async
(
paramMap
:
Record
<
string
,
string
>
,
recordId
?:
string
,
workFlowSessionId
?:
string
)
=>
{
const
handleWorkflowSubmit
=
useCallback
(
async
(
paramMap
:
Record
<
string
,
string
>
,
recordId
?:
string
,
workFlowSessionId
?:
string
)
=>
{
// workflow 提交时,question 可以为空字符串,但需要传递 paramMap、recordId 和 workFlowSessionId
await
handleSubmitQuestion
(
''
,
undefined
,
undefined
,
{
paramMap
,
...
...
@@ -417,7 +417,7 @@ export const Chat: React.FC = () => {
workFlowSessionId
,
recordType
:
'A01'
,
})
}
}
,
[])
/** 获取qa记录 */
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
,
toolId
?:
string
)
=>
{
...
...
src/pages/Chat/components/ChatItem/CardWorkflowForm.tsx
View file @
b23d7f44
...
...
@@ -22,6 +22,12 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
const
[
searchParams
]
=
useSearchParams
()
const
hasAutoSubmittedRef
=
useRef
(
false
)
// 防止重复自动提交
const
lastFirstQaFlagRef
=
useRef
<
boolean
|
undefined
>
(
undefined
)
// 记录上次的 firstQaFlag 值
const
onSubmitWorkflowRef
=
useRef
(
onSubmitWorkflow
)
// 保存 onSubmitWorkflow 的引用,避免依赖项变化导致重复执行
// 更新 onSubmitWorkflowRef 的引用
useEffect
(()
=>
{
onSubmitWorkflowRef
.
current
=
onSubmitWorkflow
},
[
onSubmitWorkflow
])
// 获取 text 类型的字段,使用 useMemo 稳定引用
const
textFields
=
useMemo
(()
=>
{
...
...
@@ -85,12 +91,13 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
// 延迟一下再提交,确保表单值已经设置完成
setTimeout
(()
=>
{
onSubmitWorkflow
(
paramMap
,
recordId
,
workFlowSessionId
)
onSubmitWorkflow
Ref
.
current
(
paramMap
,
recordId
,
workFlowSessionId
)
},
100
)
}
}
// 移除 answer.recordId 和 answer.workFlowSessionId 作为依赖项,避免流式更新时重复触发
},
[
answer
.
firstQaFlag
,
isSubmitting
,
isCompleted
,
searchParams
,
textFields
,
onSubmitWorkflow
])
// 移除 onSubmitWorkflow 作为依赖项,使用 useRef 保存引用,避免函数引用变化导致重复触发
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
answer
.
firstQaFlag
,
isSubmitting
,
isCompleted
,
searchParams
,
textFields
])
const
handleInputChange
=
(
key
:
string
,
value
:
string
)
=>
{
setFormValues
(
prev
=>
({
...
...
src/pages/ChatTactics/TacticsChat.tsx
View file @
b23d7f44
...
...
@@ -625,7 +625,7 @@ export const TacticsChat: React.FC = () => {
}
/** 处理 workflow 表单提交 */
const
handleWorkflowSubmit
=
async
(
paramMap
:
Record
<
string
,
string
>
,
recordId
?:
string
,
workFlowSessionId
?:
string
)
=>
{
const
handleWorkflowSubmit
=
useCallback
(
async
(
paramMap
:
Record
<
string
,
string
>
,
recordId
?:
string
,
workFlowSessionId
?:
string
)
=>
{
// workflow 提交时,question 可以为空字符串,但需要传递 paramMap、recordId 和 workFlowSessionId
await
handleSubmitQuestion
(
undefined
,
undefined
,
undefined
,
{
includeQuestion
:
false
,
...
...
@@ -634,7 +634,7 @@ export const TacticsChat: React.FC = () => {
workFlowSessionId
,
recordType
:
'A01'
,
})
}
}
,
[])
/** 获取qa记录 */
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
)
=>
{
...
...
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