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
be60ab98
Commit
be60ab98
authored
Dec 18, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:清空记录时不展示分割线
parent
80e91beb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
9 deletions
+23
-9
src/pages/ChatTactics/TacticsChat.tsx
+23
-9
No files found.
src/pages/ChatTactics/TacticsChat.tsx
View file @
be60ab98
...
@@ -392,8 +392,23 @@ export const TacticsChat: React.FC = () => {
...
@@ -392,8 +392,23 @@ export const TacticsChat: React.FC = () => {
// 一次性添加用户问题和空的AI回答;如果不需要问题(自动触发场景),只添加 AI 占位
// 一次性添加用户问题和空的AI回答;如果不需要问题(自动触发场景),只添加 AI 占位
const
shouldIncludeQuestion
=
extra
?.
includeQuestion
!==
false
&&
!!
question
const
shouldIncludeQuestion
=
extra
?.
includeQuestion
!==
false
&&
!!
question
const
isReanalyze
=
extra
?.
isReanalyze
===
true
const
isReanalyze
=
extra
?.
isReanalyze
===
true
// 同步计算分割线位置(基于当前 allItems 长度)
// 重新分析时,在添加新记录之前计算分割线位置
const
nextDividerIndex
=
isReanalyze
?
allItems
.
length
+
(
shouldIncludeQuestion
?
2
:
1
)
:
null
// 分割线应该显示在历史记录之后、新记录之前
// 渲染时使用 divider.index === index + 1 来匹配,所以分割线的 index 应该是新记录的位置
// 只有当存在历史记录时,才显示分割线
if
(
isReanalyze
&&
hasHistory
===
true
)
{
// 基于当前 allItems 长度计算分割线位置
// 分割线会在新添加的第一个记录之前显示(即 prevItems.length + 1)
const
nextDividerIndex
=
allItems
.
length
+
1
const
currentTime
=
formatCurrentTime
()
setHistoryDividers
((
prev
)
=>
{
// 避免重复添加相同位置的分割线
if
(
prev
.
some
(
divider
=>
divider
.
index
===
nextDividerIndex
))
{
return
prev
}
return
[...
prev
,
{
index
:
nextDividerIndex
,
time
:
currentTime
}]
})
}
setAllItems
(
prevItems
=>
[
setAllItems
(
prevItems
=>
[
...
prevItems
,
...
prevItems
,
...(
shouldIncludeQuestion
...(
shouldIncludeQuestion
...
@@ -409,10 +424,6 @@ export const TacticsChat: React.FC = () => {
...
@@ -409,10 +424,6 @@ export const TacticsChat: React.FC = () => {
answerList
:
[{
answer
:
''
}],
answerList
:
[{
answer
:
''
}],
}
as
ChatRecord
,
}
as
ChatRecord
,
])
])
if
(
isReanalyze
&&
nextDividerIndex
!==
null
)
{
const
currentTime
=
formatCurrentTime
()
setHistoryDividers
(
prev
=>
[...
prev
,
{
index
:
nextDividerIndex
,
time
:
currentTime
}])
}
// 创建新的 AbortController
// 创建新的 AbortController
abortControllerRef
.
current
=
new
AbortController
()
abortControllerRef
.
current
=
new
AbortController
()
...
@@ -560,7 +571,9 @@ export const TacticsChat: React.FC = () => {
...
@@ -560,7 +571,9 @@ export const TacticsChat: React.FC = () => {
}
}
return
processedMessages
return
processedMessages
})
})
setHasCleared
(
false
)
// 如果是清除记录创建的新会话且没有历史记录,保持 hasCleared 为 true
setHasCleared
(
createdFromClearRef
.
current
&&
!
hasHistoryFlag
)
setHistoryDividers
([])
setHasHistory
(
hasHistoryFlag
)
setHasHistory
(
hasHistoryFlag
)
}
}
catch
{
catch
{
...
@@ -576,7 +589,8 @@ export const TacticsChat: React.FC = () => {
...
@@ -576,7 +589,8 @@ export const TacticsChat: React.FC = () => {
}
}
return
[{
role
:
'system'
}
as
ChatRecord
]
return
[{
role
:
'system'
}
as
ChatRecord
]
})
})
setHasCleared
(
false
)
// 如果是清除记录创建的新会话,保持 hasCleared 为 true
setHasCleared
(
createdFromClearRef
.
current
)
setHistoryDividers
([])
setHistoryDividers
([])
// 拉取失败时视为无历史记录,后续可按需触发自动提问
// 拉取失败时视为无历史记录,后续可按需触发自动提问
setHasHistory
(
false
)
setHasHistory
(
false
)
...
@@ -605,7 +619,7 @@ export const TacticsChat: React.FC = () => {
...
@@ -605,7 +619,7 @@ export const TacticsChat: React.FC = () => {
// 清空对话列表,只保留欢迎语
// 清空对话列表,只保留欢迎语
setAllItems
([{
role
:
'system'
}
as
ChatRecord
])
setAllItems
([{
role
:
'system'
}
as
ChatRecord
])
setHasCleared
(
true
)
setHasCleared
(
true
)
setHistoryDividers
([])
setHistoryDividers
(
()
=>
[])
// 标记接下来创建的新会话来源于「清空记录」,用于阻止自动触发一次提问
// 标记接下来创建的新会话来源于「清空记录」,用于阻止自动触发一次提问
createdFromClearRef
.
current
=
true
createdFromClearRef
.
current
=
true
dispatch
(
dispatch
(
...
...
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