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
7db07d6f
Commit
7db07d6f
authored
Jan 23, 2026
by
weiyudumei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复历史记录自动提交问题,历史记录只隐藏UI不执行自动提交,只有流式返回的新记录才执行自动提交
parent
5b082fd7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
10 deletions
+15
-10
src/api/chat.ts
+0
-0
src/pages/Chat/Chat.tsx
+5
-5
src/pages/Chat/components/ChatItem/CardWorkflowForm.tsx
+1
-1
src/pages/Chat/components/ChatItem/ChatAnswerBox.tsx
+3
-2
src/pages/Chat/components/ChatItem/ChatAnswerParser.tsx
+3
-1
src/pages/Chat/components/ChatItem/ChatAnswerShower.tsx
+3
-1
No files found.
src/api/chat.ts
View file @
7db07d6f
src/pages/Chat/Chat.tsx
View file @
7db07d6f
...
@@ -949,19 +949,19 @@ export const Chat: React.FC = () => {
...
@@ -949,19 +949,19 @@ export const Chat: React.FC = () => {
>
>
<
div
className=
{
styles
.
inter
}
>
<
div
className=
{
styles
.
inter
}
>
{
allItems
.
map
((
record
,
index
)
=>
{
{
allItems
.
map
((
record
,
index
)
=>
{
// 如果历史记录中 firstQaFlag 为 true,则不展示该条 chatItem
if
(
record
.
role
===
'ai'
&&
record
.
answerList
?.[
0
]?.
firstQaFlag
===
true
)
{
return
null
}
const
recordId
=
record
.
answerList
?.[
0
]?.
recordId
||
record
.
groupId
const
recordId
=
record
.
answerList
?.[
0
]?.
recordId
||
record
.
groupId
const
uniqueKey
=
recordId
const
uniqueKey
=
recordId
?
`${record.role}-${recordId}`
?
`${record.role}-${recordId}`
:
`${record.role}-${record.question || record.answerList?.[0]?.answer || ''}-${index}`
:
`${record.role}-${record.question || record.answerList?.[0]?.answer || ''}-${index}`
// 如果历史记录中 firstQaFlag 为 true,隐藏 UI 但保留组件渲染(确保自动提交逻辑能执行)
const
shouldHideHistoryItem
=
record
.
role
===
'ai'
&&
record
.
answerList
?.[
0
]?.
firstQaFlag
===
true
return
(
return
(
<
div
<
div
className=
"w-full chatItem mx-auto"
className=
"w-full chatItem mx-auto"
key=
{
uniqueKey
}
key=
{
uniqueKey
}
style=
{
shouldHideHistoryItem
?
{
visibility
:
'hidden'
,
height
:
0
,
overflow
:
'hidden'
,
margin
:
0
,
padding
:
0
}
:
undefined
}
>
>
{
record
.
role
===
'system'
&&
<
ChatWelcome
toolName=
{
currentToolName
}
/>
}
{
record
.
role
===
'system'
&&
<
ChatWelcome
toolName=
{
currentToolName
}
/>
}
{
record
.
role
===
'user'
&&
<
ChatItemUser
record=
{
record
}
/>
}
{
record
.
role
===
'user'
&&
<
ChatItemUser
record=
{
record
}
/>
}
...
...
src/pages/Chat/components/ChatItem/CardWorkflowForm.tsx
View file @
7db07d6f
...
@@ -60,7 +60,7 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
...
@@ -60,7 +60,7 @@ export const CardWorkflowForm: React.FC<CardWorkflowFormProps> = ({
}
}
},
[
attachment
,
answer
.
firstQaFlag
,
searchParams
,
textFields
])
},
[
attachment
,
answer
.
firstQaFlag
,
searchParams
,
textFields
])
// 如果 firstQaFlag 为 true,自动提交
// 如果 firstQaFlag 为 true,自动提交
(仅对流式返回的新记录,历史记录不会渲染此组件)
useEffect
(()
=>
{
useEffect
(()
=>
{
// 检查 firstQaFlag 是否从 false/undefined 变为 true(首次变为 true)
// 检查 firstQaFlag 是否从 false/undefined 变为 true(首次变为 true)
const
isFirstQaFlagChangedToTrue
=
answer
.
firstQaFlag
===
true
&&
lastFirstQaFlagRef
.
current
!==
true
const
isFirstQaFlagChangedToTrue
=
answer
.
firstQaFlag
===
true
&&
lastFirstQaFlagRef
.
current
!==
true
...
...
src/pages/Chat/components/ChatItem/ChatAnswerBox.tsx
View file @
7db07d6f
...
@@ -60,8 +60,9 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
...
@@ -60,8 +60,9 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
// 当前默认始终展示点赞 / 点踩 / 复制等操作区(是否展示由下层基于卡片类型自行决定)
// 当前默认始终展示点赞 / 点踩 / 复制等操作区(是否展示由下层基于卡片类型自行决定)
const
shouldHideOperate
=
false
const
shouldHideOperate
=
false
// 如果 firstQaFlag 为 true 且存在 workflow 卡片,隐藏整个 chatItem(表单会自动提交,用户不需要看到这次的结果)
// 如果 firstQaFlag 为 true 且存在 workflow 卡片,隐藏整个 chatItem(用户不需要看到这次的结果)
// 但保留组件的渲染,确保 CardWorkflowForm 的自动提交逻辑能够执行
// 注意:历史记录(isShow === true)不会渲染 CardWorkflowForm,不会自动提交
// 只有流式返回的新记录(isShow === false)才会渲染 CardWorkflowForm 并执行自动提交
const
hasWorkflowCard
=
(
item
.
cardList
||
[]).
some
(
attachment
=>
attachment
.
type
===
'card-workflow'
)
const
hasWorkflowCard
=
(
item
.
cardList
||
[]).
some
(
attachment
=>
attachment
.
type
===
'card-workflow'
)
const
shouldHideChatItem
=
item
.
firstQaFlag
===
true
&&
hasWorkflowCard
const
shouldHideChatItem
=
item
.
firstQaFlag
===
true
&&
hasWorkflowCard
...
...
src/pages/Chat/components/ChatItem/ChatAnswerParser.tsx
View file @
7db07d6f
...
@@ -202,7 +202,9 @@ export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer
...
@@ -202,7 +202,9 @@ export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer
</
MarkdownDetail
>
</
MarkdownDetail
>
</
div
>
</
div
>
)
}
)
}
{
!
isTyping
{
/* ChatAnswerParser 用于流式返回的新记录(isShow === false),即使 firstQaFlag === true 也要渲染 ChatAnswerAttachment,确保自动提交逻辑能执行
如果 firstQaFlag 为 true 且存在 workflow 卡片,即使 isTyping 为 true 也要渲染 ChatAnswerAttachment */
}
{
((
!
isTyping
)
||
(
answer
.
firstQaFlag
===
true
&&
(
answer
.
cardList
||
[]).
some
(
attachment
=>
attachment
.
type
===
'card-workflow'
)))
&&
answer
.
cardList
&&
answer
.
cardList
&&
answer
.
cardList
?.
length
!==
0
&&
answer
.
cardList
?.
length
!==
0
&&
(
&&
(
...
...
src/pages/Chat/components/ChatItem/ChatAnswerShower.tsx
View file @
7db07d6f
...
@@ -28,7 +28,9 @@ export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLa
...
@@ -28,7 +28,9 @@ export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLa
</
MarkdownDetail
>
</
MarkdownDetail
>
</
div
>
</
div
>
)
}
)
}
{
answer
.
cardList
&&
answer
.
cardList
?.
length
!==
0
&&
(
{
/* 历史记录(isShow === true)且 firstQaFlag === true 时,不渲染 ChatAnswerAttachment(不需要自动提交)
流式返回的新记录(isShow === false)即使 firstQaFlag === true 也要渲染,确保自动提交逻辑能执行 */
}
{
answer
.
cardList
&&
answer
.
cardList
?.
length
!==
0
&&
!
(
answer
.
isShow
===
true
&&
answer
.
firstQaFlag
===
true
)
&&
(
<
ChatAnswerAttachment
<
ChatAnswerAttachment
onSubmitQuestion=
{
onSubmitQuestion
}
onSubmitQuestion=
{
onSubmitQuestion
}
isLastAnswer=
{
isLastAnswer
}
isLastAnswer=
{
isLastAnswer
}
...
...
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