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
4a6d1a42
Commit
4a6d1a42
authored
Dec 17, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:重新分析分割线
parent
ef640258
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
17 deletions
+24
-17
src/pages/ChatTactics/TacticsChat.tsx
+24
-17
No files found.
src/pages/ChatTactics/TacticsChat.tsx
View file @
4a6d1a42
...
...
@@ -43,8 +43,7 @@ export const TacticsChat: React.FC = () => {
const
viteOutputObj
=
import
.
meta
.
env
.
VITE_OUTPUT_OBJ
||
'open'
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
[
historyDividerIndex
,
setHistoryDividerIndex
]
=
useState
<
number
|
null
>
(
null
)
const
[
historyDividerTime
,
setHistoryDividerTime
]
=
useState
<
string
|
null
>
(
null
)
const
[
historyDividers
,
setHistoryDividers
]
=
useState
<
{
index
:
number
,
time
:
string
}[]
>
([])
const
[
hasCleared
,
setHasCleared
]
=
useState
(
false
)
const
[
showClearConfirm
,
setShowClearConfirm
]
=
useState
(
false
)
// 标记当前会话是否已有历史记录;null 表示尚未完成查询
...
...
@@ -370,7 +369,7 @@ export const TacticsChat: React.FC = () => {
question
:
string
|
undefined
,
productCode
?:
string
,
toolId
?:
string
,
extra
?:
{
busiType
?:
string
,
recordType
?:
string
,
numberType
?:
string
,
includeQuestion
?:
boolean
,
includeTacticsMeta
?:
boolean
,
includeUserMeta
?:
boolean
},
extra
?:
{
busiType
?:
string
,
recordType
?:
string
,
numberType
?:
string
,
includeQuestion
?:
boolean
,
includeTacticsMeta
?:
boolean
,
includeUserMeta
?:
boolean
,
isReanalyze
?:
boolean
},
)
=>
{
// 优先读取缓存中的 toolId,再回退到传参
const
sessionToolId
=
sessionStorage
.
getItem
(
'currentToolId'
)
??
undefined
...
...
@@ -387,6 +386,9 @@ export const TacticsChat: React.FC = () => {
await
fetchCheckTokenApi
()
// 一次性添加用户问题和空的AI回答;如果不需要问题(自动触发场景),只添加 AI 占位
const
shouldIncludeQuestion
=
extra
?.
includeQuestion
!==
false
&&
!!
question
const
isReanalyze
=
extra
?.
isReanalyze
===
true
// 同步计算分割线位置(基于当前 allItems 长度)
const
nextDividerIndex
=
isReanalyze
?
allItems
.
length
+
(
shouldIncludeQuestion
?
2
:
1
)
:
null
setAllItems
(
prevItems
=>
[
...
prevItems
,
...(
shouldIncludeQuestion
...
...
@@ -402,6 +404,10 @@ export const TacticsChat: React.FC = () => {
answerList
:
[{
answer
:
''
}],
}
as
ChatRecord
,
])
if
(
isReanalyze
&&
nextDividerIndex
!==
null
)
{
const
currentTime
=
formatCurrentTime
()
setHistoryDividers
(
prev
=>
[...
prev
,
{
index
:
nextDividerIndex
,
time
:
currentTime
}])
}
// 创建新的 AbortController
abortControllerRef
.
current
=
new
AbortController
()
...
...
@@ -489,9 +495,9 @@ export const TacticsChat: React.FC = () => {
// 正常的stream数据
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'00000000'
)
{
// eslint-disable-next-line no-console
console
.
log
(
'
流式[TacticsChat] handleSubmitQuestion:success
'
,
msg
)
console
.
log
(
'
========================流式输出====================
'
,
msg
)
// eslint-disable-next-line no-console
console
.
log
(
'
[TacticsChat] handleSubmitQuestion:data
'
,
msg
.
content
?.
data
)
console
.
log
(
'
========================流式输出字符串====================
'
,
msg
.
content
?.
data
)
handleStreamMesageData
(
msg
,
question
||
''
)
}
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'01010005'
)
{
...
...
@@ -517,12 +523,8 @@ export const TacticsChat: React.FC = () => {
const
res
=
await
fetchTacticsQaRecordPage
(
conversationId
)
const
qaRecords
=
res
.
data
||
[]
const
hasHistoryFlag
=
qaRecords
.
length
>
0
const
historyCount
=
qaRecords
.
length
// 始终添加 system 角色作为欢迎语
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
qaRecords
)]
// 分割线按“历史记录条数 + 欢迎语”计算,避免缺失 question 的记录被漏算
setHistoryDividerIndex
(
hasHistoryFlag
?
historyCount
+
1
:
null
)
setHistoryDividerTime
(
hasHistoryFlag
?
formatCurrentTime
()
:
null
)
// 处理历史记录中的参考文档标记
const
processedMessages
=
messages
.
map
((
item
)
=>
{
if
(
item
.
role
===
'ai'
&&
item
.
answerList
?.[
0
]?.
answer
)
{
...
...
@@ -570,8 +572,7 @@ export const TacticsChat: React.FC = () => {
return
[{
role
:
'system'
}
as
ChatRecord
]
})
setHasCleared
(
false
)
setHistoryDividerIndex
(
null
)
setHistoryDividerTime
(
null
)
setHistoryDividers
([])
// 拉取失败时视为无历史记录,后续可按需触发自动提问
setHasHistory
(
false
)
}
...
...
@@ -599,8 +600,7 @@ export const TacticsChat: React.FC = () => {
// 清空对话列表,只保留欢迎语
setAllItems
([{
role
:
'system'
}
as
ChatRecord
])
setHasCleared
(
true
)
setHistoryDividerIndex
(
null
)
setHistoryDividerTime
(
null
)
setHistoryDividers
([])
// 标记接下来创建的新会话来源于「清空记录」,用于阻止自动触发一次提问
createdFromClearRef
.
current
=
true
dispatch
(
...
...
@@ -644,6 +644,7 @@ export const TacticsChat: React.FC = () => {
includeQuestion
:
false
,
includeTacticsMeta
:
false
,
includeUserMeta
:
true
,
isReanalyze
:
true
,
})
}
else
{
...
...
@@ -652,6 +653,7 @@ export const TacticsChat: React.FC = () => {
recordType
:
'A01'
,
includeQuestion
:
false
,
includeTacticsMeta
:
true
,
isReanalyze
:
true
,
})
}
// 重新拉取会话列表,保持原有行为
...
...
@@ -682,13 +684,13 @@ export const TacticsChat: React.FC = () => {
lastSentQuestionRef
.
current
=
''
// 每次切换会话时重置历史标记,等待新会话的历史查询结果
setHasHistory
(
null
)
setHistoryDividers
([])
getUserQaRecordPage
(
id
)
}
else
{
// 如果没有 id,显示欢迎语,等待登录成功后创建新会话
setAllItems
([{
role
:
'system'
}
as
ChatRecord
])
setHistoryDividerIndex
(
null
)
setHistoryDividerTime
(
null
)
setHistoryDividers
([])
setIsLoading
(
false
)
setHasHistory
(
false
)
}
...
...
@@ -927,17 +929,22 @@ export const TacticsChat: React.FC = () => {
>
<
div
className=
{
`${styles.inter} pt-[8px] pb-[24px] min-h-full`
}
>
{
allItems
.
map
((
record
,
index
)
=>
{
// 如果 question 为空字符串、null 或不存在则不展示该条记录
if
(
record
.
role
===
'user'
&&
!
record
.
question
)
{
return
null
}
const
matchedDivider
=
historyDividers
.
find
(
divider
=>
divider
.
index
===
index
+
1
)
const
recordId
=
record
.
answerList
?.[
0
]?.
recordId
||
record
.
groupId
const
uniqueKey
=
recordId
?
`${record.role}-${recordId}`
:
`${record.role}-${record.question || record.answerList?.[0]?.answer || ''}-${index}`
return
(
<
React
.
Fragment
key=
{
uniqueKey
}
>
{
historyDividerIndex
!==
null
&&
index
+
1
===
historyDividerIndex
&&
(
{
matchedDivider
&&
(
<
div
className=
"flex items-center gap-[12px] my-[16px] text-[#B2B8C1] text-[12px]"
>
<
div
className=
"flex-1 h-px bg-[#E4E7EC]"
/>
<
span
>
以上为历史分析数据
</
span
>
<
span
>
{
historyDividerTime
||
formatCurrentTime
()
}
</
span
>
<
span
>
{
matchedDivider
.
time
}
</
span
>
<
div
className=
"flex-1 h-px bg-[#E4E7EC]"
/>
</
div
>
)
}
...
...
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