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
100f5c87
Commit
100f5c87
authored
Dec 15, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:清除会话逻辑&&清空后欢迎语
parent
7a462a27
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
12 deletions
+53
-12
src/pages/ChatTactics/TacticsChat.tsx
+45
-10
src/pages/ChatTactics/components/TacticsWelcome/index.tsx
+8
-2
No files found.
src/pages/ChatTactics/TacticsChat.tsx
View file @
100f5c87
...
...
@@ -32,6 +32,8 @@ export const TacticsChat: React.FC = () => {
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
[
historyDividerIndex
,
setHistoryDividerIndex
]
=
useState
<
number
|
null
>
(
null
)
const
[
historyDividerTime
,
setHistoryDividerTime
]
=
useState
<
string
|
null
>
(
null
)
const
[
hasCleared
,
setHasCleared
]
=
useState
(
false
)
const
[
showClearConfirm
,
setShowClearConfirm
]
=
useState
(
false
)
const
dispatch
=
useAppDispatch
()
const
{
shouldSendQuestion
:
shouldSendQuestionFromState
,
...
...
@@ -291,25 +293,21 @@ export const TacticsChat: React.FC = () => {
const
shouldSendQuestion
=
extra
?.
includeQuestion
!==
false
// 去除缓存中可能存在的 from 字段,避免作为参数传递
const
{
from
:
_omitFrom
,
...
safeTacticsMeta
}
=
tacticsMeta
||
{}
const
requestBody
:
Record
<
string
,
any
>
=
{
conversationId
:
currentIdRef
.
current
,
stream
:
true
,
productCode
,
toolId
:
resolvedToolId
,
...
(
tacticsMeta
||
{})
,
...
safeTacticsMeta
,
...(
extra
?.
busiType
?
{
busiType
:
extra
.
busiType
}
:
{}),
...(
extra
?.
recordType
?
{
recordType
:
extra
.
recordType
}
:
{}),
}
if
(
shouldSendQuestion
)
{
requestBody
.
question
=
question
??
''
}
// eslint-disable-next-line no-console
console
.
log
(
'[TacticsChat] handleSubmitQuestion:requesting'
,
{
fetchUrl
,
body
:
requestBody
,
})
fetchStreamResponse
(
fetchUrl
,
requestBody
,
...
...
@@ -332,6 +330,8 @@ 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
)
handleStreamMesageData
(
msg
,
question
||
''
)
}
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'01010005'
)
{
...
...
@@ -379,10 +379,12 @@ export const TacticsChat: React.FC = () => {
return
item
})
setAllItems
(
processedMessages
)
setHasCleared
(
false
)
}
catch
{
// 如果获取失败,至少显示欢迎语
setAllItems
([{
role
:
'system'
}
as
ChatRecord
])
setHasCleared
(
false
)
setHistoryDividerIndex
(
null
)
setHistoryDividerTime
(
null
)
}
...
...
@@ -399,6 +401,7 @@ export const TacticsChat: React.FC = () => {
const
handleClearRecord
=
useCallback
(
async
()
=>
{
if
(
!
currentIdRef
.
current
)
return
setShowClearConfirm
(
false
)
try
{
await
dispatch
(
deleteTacticsConversations
([
currentIdRef
.
current
])).
unwrap
()
// 停止正在进行的请求
...
...
@@ -408,6 +411,7 @@ export const TacticsChat: React.FC = () => {
}
// 清空对话列表,只保留欢迎语
setAllItems
([{
role
:
'system'
}
as
ChatRecord
])
setHasCleared
(
true
)
setHistoryDividerIndex
(
null
)
setHistoryDividerTime
(
null
)
dispatch
(
...
...
@@ -433,6 +437,14 @@ export const TacticsChat: React.FC = () => {
}
},
[
dispatch
,
navigate
,
handleSubmitQuestion
])
const
handleCancelClear
=
useCallback
(()
=>
{
setShowClearConfirm
(
false
)
},
[])
const
handleOpenClearConfirm
=
useCallback
(()
=>
{
setShowClearConfirm
(
true
)
},
[])
useEffect
(()
=>
{
if
(
id
)
{
// 停止之前的请求
...
...
@@ -533,7 +545,7 @@ export const TacticsChat: React.FC = () => {
<
div
className=
"flex justify-end items-center gap-[16px] px-[16px] pt-[16px] pb-[8px]"
>
<
button
type=
"button"
onClick=
{
handle
ClearRecord
}
onClick=
{
handle
OpenClearConfirm
}
className=
"flex items-center gap-[4px] text-[#4A90E2] text-[14px] hover:opacity-80 transition-opacity cursor-pointer bg-transparent border-none outline-none"
>
<
DeleteIcon
className=
"w-[16px] h-[16px] text-[#B2B8C1]"
/>
...
...
@@ -549,6 +561,29 @@ export const TacticsChat: React.FC = () => {
</
button
>
</
div
>
<
div
className=
{
`${styles.chatPage} relative flex flex-col h-full`
}
>
{
showClearConfirm
&&
(
<
div
className=
"fixed inset-0 z-[2000] flex items-center justify-center bg-black/40 px-4"
>
<
div
className=
"bg-white rounded-[12px] p-6 w-full max-w-[360px] shadow-lg"
>
<
div
className=
"text-[16px] font-medium text-[#1F2937] mb-4"
>
是否确定清空历史记录?
</
div
>
<
div
className=
"flex justify-end gap-3"
>
<
button
type=
"button"
onClick=
{
handleCancelClear
}
className=
"px-4 py-2 rounded-[8px] border border-[#E5E7EB] text-[#4B5563] hover:bg-[#F9FAFB]"
>
取消
</
button
>
<
button
type=
"button"
onClick=
{
handleClearRecord
}
className=
"px-4 py-2 rounded-[8px] bg-[#2563EB] text-white hover:opacity-90"
>
确定
</
button
>
</
div
>
</
div
>
</
div
>
)
}
<
div
className=
{
`${styles.content} flex-1 overflow-hidden flex flex-col`
}
>
{
isLoading
&&
(
<
div
className=
"w-full h-full flex justify-center items-center"
>
...
...
@@ -584,7 +619,7 @@ export const TacticsChat: React.FC = () => {
<
div
className=
"w-full chatItem mx-auto"
>
{
record
.
role
===
'system'
&&
<
TacticsWelcome
/>
}
{
record
.
role
===
'system'
&&
<
TacticsWelcome
cleared=
{
hasCleared
}
/>
}
{
record
.
role
===
'user'
&&
<
ChatItemUser
record=
{
record
}
/>
}
{
record
.
role
===
'ai'
&&
(
<
ChatAnswerBox
...
...
src/pages/ChatTactics/components/TacticsWelcome/index.tsx
View file @
100f5c87
...
...
@@ -4,9 +4,15 @@ import { motion } from 'framer-motion'
import
AvatarBot
from
'@/assets/avatarBot.png'
import
AIIcon
from
'@/assets/ai-icon.png'
export
const
TacticsWelcome
:
React
.
FC
=
()
=>
{
interface
TacticsWelcomeProps
{
cleared
?:
boolean
}
export
const
TacticsWelcome
:
React
.
FC
<
TacticsWelcomeProps
>
=
({
cleared
})
=>
{
const
viteOutputObj
=
import
.
meta
.
env
.
VITE_OUTPUT_OBJ
||
'open'
const
welcomeText
=
'正在为您分析策略,请耐心等待一会儿哦~'
const
welcomeText
=
cleared
?
'暂无分析记录,点击右上方按钮开始新的分析吧!'
:
'正在为您分析策略,请耐心等待一会儿哦~'
return
(
<
div
className=
"chatWelcomeContainer w-full"
>
...
...
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