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
aa90f3a8
Commit
aa90f3a8
authored
Dec 16, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:存在历史记录时则不自动调用提问接口
parent
7bc5496b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
src/pages/ChatTactics/TacticsChat.tsx
+14
-5
No files found.
src/pages/ChatTactics/TacticsChat.tsx
View file @
aa90f3a8
...
...
@@ -34,6 +34,8 @@ export const TacticsChat: React.FC = () => {
const
[
historyDividerTime
,
setHistoryDividerTime
]
=
useState
<
string
|
null
>
(
null
)
const
[
hasCleared
,
setHasCleared
]
=
useState
(
false
)
const
[
showClearConfirm
,
setShowClearConfirm
]
=
useState
(
false
)
// 标记当前会话是否已有历史记录;null 表示尚未完成查询
const
[
hasHistory
,
setHasHistory
]
=
useState
<
boolean
|
null
>
(
null
)
const
dispatch
=
useAppDispatch
()
const
{
shouldSendQuestion
:
shouldSendQuestionFromState
,
...
...
@@ -484,11 +486,11 @@ export const TacticsChat: React.FC = () => {
try
{
const
res
=
await
fetchTacticsQaRecordPage
(
conversationId
)
const
qaRecords
=
res
.
data
||
[]
const
hasHistoryFlag
=
qaRecords
.
length
>
0
// 始终添加 system 角色作为欢迎语
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
qaRecords
)]
const
hasHistory
=
qaRecords
.
length
>
0
setHistoryDividerIndex
(
hasHistory
?
messages
.
length
:
null
)
setHistoryDividerTime
(
hasHistory
?
formatCurrentTime
()
:
null
)
setHistoryDividerIndex
(
hasHistoryFlag
?
messages
.
length
:
null
)
setHistoryDividerTime
(
hasHistoryFlag
?
formatCurrentTime
()
:
null
)
// 处理历史记录中的参考文档标记
const
processedMessages
=
messages
.
map
((
item
)
=>
{
if
(
item
.
role
===
'ai'
&&
item
.
answerList
?.[
0
]?.
answer
)
{
...
...
@@ -520,6 +522,7 @@ export const TacticsChat: React.FC = () => {
return
processedMessages
})
setHasCleared
(
false
)
setHasHistory
(
hasHistoryFlag
)
}
catch
{
// 如果获取失败,至少显示欢迎语
...
...
@@ -537,6 +540,8 @@ export const TacticsChat: React.FC = () => {
setHasCleared
(
false
)
setHistoryDividerIndex
(
null
)
setHistoryDividerTime
(
null
)
// 拉取失败时视为无历史记录,后续可按需触发自动提问
setHasHistory
(
false
)
}
finally
{
setIsLoading
(
false
)
...
...
@@ -625,6 +630,8 @@ export const TacticsChat: React.FC = () => {
currentIdRef
.
current
=
id
lastSentQuestionRef
.
current
=
''
// 每次切换会话时重置历史标记,等待新会话的历史查询结果
setHasHistory
(
null
)
getUserQaRecordPage
(
id
)
}
else
{
...
...
@@ -633,6 +640,7 @@ export const TacticsChat: React.FC = () => {
setHistoryDividerIndex
(
null
)
setHistoryDividerTime
(
null
)
setIsLoading
(
false
)
setHasHistory
(
false
)
}
},
[
id
,
getUserQaRecordPage
,
dispatch
])
...
...
@@ -650,7 +658,8 @@ export const TacticsChat: React.FC = () => {
}
},
[
id
])
useEffect
(()
=>
{
if
(
currentIdRef
.
current
&&
!
isLoading
&&
!
hasAutoSubmittedRef
.
current
)
{
// 仅在历史记录查询完成且为空时,才自动触发一次提交
if
(
currentIdRef
.
current
&&
!
isLoading
&&
hasHistory
===
false
&&
!
hasAutoSubmittedRef
.
current
)
{
hasAutoSubmittedRef
.
current
=
true
// 进入会话后自动触发一次提交:
// - 无 userMeta:沿用原逻辑,recordType=A02,携带 tacticsMeta
...
...
@@ -685,7 +694,7 @@ export const TacticsChat: React.FC = () => {
)
}
}
},
[
isLoading
,
handleSubmitQuestion
,
id
,
userMeta
,
getNumberTypeWithUserMeta
])
},
[
isLoading
,
handleSubmitQuestion
,
id
,
userMeta
,
getNumberTypeWithUserMeta
,
hasHistory
])
// 创建新会话成功后跳转到新会话页面
useEffect
(()
=>
{
...
...
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