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
548b62d4
Commit
548b62d4
authored
Feb 03, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:历史记录正常展示
parent
306d592c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
src/pages/Chat/Chat.tsx
+15
-4
No files found.
src/pages/Chat/Chat.tsx
View file @
548b62d4
...
@@ -146,6 +146,8 @@ export const Chat: React.FC = () => {
...
@@ -146,6 +146,8 @@ export const Chat: React.FC = () => {
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
lastIndex
=
newItems
.
length
-
1
const
lastIndex
=
newItems
.
length
-
1
const
isEmptyQuestion
=
!
question
.
trim
()
const
isEmptyQuestion
=
!
question
.
trim
()
// 提质增效自动欢迎语场景:空问题的流式回答应追加在历史记录之后,避免复用最后一条历史 AI 记录
const
shouldAlwaysAppendAi
=
isAutoSubmitQualityImprovementRef
.
current
&&
isEmptyQuestion
// 提质增效模式下,自动调用时收集首个有效 answer 作为欢迎语候选(按流式增量累积)
// 提质增效模式下,自动调用时收集首个有效 answer 作为欢迎语候选(按流式增量累积)
if
(
isAutoSubmitQualityImprovementRef
.
current
&&
isEmptyQuestion
)
{
if
(
isAutoSubmitQualityImprovementRef
.
current
&&
isEmptyQuestion
)
{
...
@@ -183,8 +185,8 @@ export const Chat: React.FC = () => {
...
@@ -183,8 +185,8 @@ export const Chat: React.FC = () => {
}
}
}
}
// 如果是空问题且
最后一项不是AI回答,需要添加AI回答
// 如果是空问题且
需要追加新的 AI 记录(历史末尾没有 AI,或提质增效自动欢迎语场景),则添加 AI 回答占位
if
(
isEmptyQuestion
&&
(
lastIndex
<
0
||
newItems
[
lastIndex
].
role
!==
'ai'
))
{
if
(
isEmptyQuestion
&&
(
lastIndex
<
0
||
newItems
[
lastIndex
].
role
!==
'ai'
||
shouldAlwaysAppendAi
))
{
newItems
.
push
({
newItems
.
push
({
role
:
'ai'
,
role
:
'ai'
,
answerList
:
[{
answer
:
''
}],
answerList
:
[{
answer
:
''
}],
...
@@ -1008,12 +1010,21 @@ export const Chat: React.FC = () => {
...
@@ -1008,12 +1010,21 @@ export const Chat: React.FC = () => {
// 如果是自动调用提问接口(空问题且是流式返回的新记录),不显示问题和回答
// 如果是自动调用提问接口(空问题且是流式返回的新记录),不显示问题和回答
// 判断条件:question === undefined(空问题)且 isShow === false(流式返回的新记录,不是历史记录)
// 判断条件:question === undefined(空问题)且 isShow === false(流式返回的新记录,不是历史记录)
const
shouldHideEmptyQuestionAnswer
=
record
.
role
===
'ai'
&&
record
.
question
===
undefined
&&
record
.
answerList
?.[
0
]?.
isShow
===
false
const
shouldHideEmptyQuestionAnswer
=
record
.
role
===
'ai'
&&
record
.
question
===
undefined
&&
record
.
answerList
?.[
0
]?.
isShow
===
false
// 白名单:当同一条 AI 记录里同时有 question + answer(且 firstQaFlag 不为 true)时,强制展示,避免误隐藏
const
hasQuestion
=
typeof
record
.
question
===
'string'
&&
record
.
question
.
trim
().
length
>
0
const
firstAnswer
=
record
.
answerList
?.[
0
]
const
hasAnswer
=
typeof
firstAnswer
?.
answer
===
'string'
&&
firstAnswer
.
answer
.
trim
().
length
>
0
const
hasCardList
=
Array
.
isArray
(
firstAnswer
?.
cardList
)
&&
firstAnswer
!
.
cardList
.
length
>
0
const
shouldForceShow
=
record
.
role
===
'ai'
&&
hasQuestion
&&
(
hasAnswer
||
hasCardList
)
&&
firstAnswer
?.
firstQaFlag
!==
true
console
.
log
(
'9yyyyyyyyyy'
,
record
.
answerList
?.[
0
]?.
answer
,
uniqueKey
)
return
(
return
(
<
div
<
div
className=
"w-full chatItem mx-auto"
className=
"w-full chatItem mx-auto"
key=
{
uniqueKey
}
key=
{
uniqueKey
}
style=
{
(
shouldHideHistoryItem
||
shouldHideEmptyQuestionAnswer
)
?
{
visibility
:
'hidden'
,
height
:
0
,
overflow
:
'hidden'
,
margin
:
0
,
padding
:
0
}
:
undefined
}
style=
{
(
!
shouldForceShow
&&
(
shouldHideHistoryItem
||
shouldHideEmptyQuestionAnswer
)
)
?
{
visibility
:
'hidden'
,
height
:
0
,
overflow
:
'hidden'
,
margin
:
0
,
padding
:
0
}
:
undefined
}
>
>
{
record
.
role
===
'system'
&&
<
ChatWelcome
toolName=
{
currentToolName
}
welcomeText=
{
(
record
as
any
).
welcomeText
}
/>
}
{
record
.
role
===
'system'
&&
<
ChatWelcome
toolName=
{
currentToolName
}
welcomeText=
{
(
record
as
any
).
welcomeText
}
/>
}
{
record
.
role
===
'user'
&&
<
ChatItemUser
record=
{
record
}
/>
}
{
record
.
role
===
'user'
&&
<
ChatItemUser
record=
{
record
}
/>
}
...
...
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