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
cb8cbb71
Commit
cb8cbb71
authored
Sep 01, 2025
by
weiw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:去除 [参考文档《任意内容》 《任意内容》...]
parent
7632c25c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
10 deletions
+48
-10
src/pages/Chat/Chat.tsx
+48
-10
No files found.
src/pages/Chat/Chat.tsx
View file @
cb8cbb71
...
@@ -38,6 +38,10 @@ export const Chat: React.FC = () => {
...
@@ -38,6 +38,10 @@ export const Chat: React.FC = () => {
const
lastIndex
=
newItems
.
length
-
1
const
lastIndex
=
newItems
.
length
-
1
if
(
lastIndex
>=
0
)
{
if
(
lastIndex
>=
0
)
{
// 创建最后一项的新对象,合并现有数据和新的 answer
// 创建最后一项的新对象,合并现有数据和新的 answer
const
originalAnswer
=
(
newItems
[
lastIndex
].
answerList
?.[
0
]?.
answer
||
''
)
+
msg
.
content
.
data
.
answer
// 去除 [参考文档《任意内容》 《任意内容》...] 格式的内容
const
filteredAnswer
=
originalAnswer
.
replace
(
/
\[
参考文档
(?:
《
[^
》
]
*》
\s
*
)
+
\]
/g
,
''
).
trim
()
newItems
[
lastIndex
]
=
{
newItems
[
lastIndex
]
=
{
...
newItems
[
lastIndex
],
...
newItems
[
lastIndex
],
question
,
question
,
...
@@ -45,7 +49,7 @@ export const Chat: React.FC = () => {
...
@@ -45,7 +49,7 @@ export const Chat: React.FC = () => {
{
{
...
msg
.
content
.
data
,
...
msg
.
content
.
data
,
isShow
:
false
,
isShow
:
false
,
answer
:
(
newItems
[
lastIndex
].
answerList
?.[
0
]?.
answer
||
''
)
+
msg
.
content
.
data
.
a
nswer
,
answer
:
filteredA
nswer
,
},
},
],
],
}
}
...
@@ -188,13 +192,25 @@ export const Chat: React.FC = () => {
...
@@ -188,13 +192,25 @@ export const Chat: React.FC = () => {
try
{
try
{
const
res
=
await
fetchUserQaRecordPage
(
conversationId
)
const
res
=
await
fetchUserQaRecordPage
(
conversationId
)
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
res
.
data
)]
const
messages
=
[{
role
:
'system'
}
as
ChatRecord
,
...
processApiResponse
(
res
.
data
)]
setAllItems
(
messages
)
// 假设 API 返回的数据结构符合 ChatRecord[]
// 处理历史记录中的参考文档标记
const
processedMessages
=
messages
.
map
((
item
)
=>
{
if
(
item
.
role
===
'ai'
&&
item
.
answerList
?.[
0
]?.
answer
)
{
return
{
...
item
,
answerList
:
item
.
answerList
.
map
(
answerItem
=>
({
...
answerItem
,
answer
:
answerItem
.
answer
?.
replace
(
/
\[
参考文档
(?:
《
[^
》
]
*》
\s
*
)
+
\]
/g
,
''
).
trim
(),
})),
}
}
return
item
})
setAllItems
(
processedMessages
)
}
}
catch
{
catch
{
// console.error('Failed to fetch chat records:', error)
// 错误处理
// 可以在这里添加错误处理逻辑
}
}
finally
{
finally
{
setIsLoading
(
false
)
setIsLoading
(
false
)
}
}
},
[])
},
[])
...
@@ -220,7 +236,12 @@ export const Chat: React.FC = () => {
...
@@ -220,7 +236,12 @@ export const Chat: React.FC = () => {
// 处理shouldSendQuestion的变化 - 自动发送问题
// 处理shouldSendQuestion的变化 - 自动发送问题
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
shouldSendQuestion
&&
currentIdRef
.
current
&&
!
isLoading
&&
shouldSendQuestion
!==
lastSentQuestionRef
.
current
)
{
if
(
shouldSendQuestion
&&
currentIdRef
.
current
&&
!
isLoading
&&
shouldSendQuestion
!==
lastSentQuestionRef
.
current
)
{
lastSentQuestionRef
.
current
=
shouldSendQuestion
lastSentQuestionRef
.
current
=
shouldSendQuestion
// 立即清除shouldSendQuestion,防止重复发送
// 立即清除shouldSendQuestion,防止重复发送
dispatch
(
clearShouldSendQuestion
())
dispatch
(
clearShouldSendQuestion
())
...
@@ -237,7 +258,11 @@ export const Chat: React.FC = () => {
...
@@ -237,7 +258,11 @@ export const Chat: React.FC = () => {
{
/* <ChatSlogan />
{
/* <ChatSlogan />
<ChatMaskBar /> */
}
<ChatMaskBar /> */
}
<
div
className=
{
`${styles.content}`
}
>
<
div
className=
{
`${styles.content}`
}
>
{
isLoading
&&
<
div
className=
"w-full h-full flex justify-center items-center"
><
SdreamLoading
/></
div
>
}
{
isLoading
&&
(
<
div
className=
"w-full h-full flex justify-center items-center"
>
<
SdreamLoading
/>
</
div
>
)
}
{
!
isLoading
&&
(
{
!
isLoading
&&
(
<
motion
.
div
<
motion
.
div
ref=
{
scrollableRef
}
ref=
{
scrollableRef
}
...
@@ -251,10 +276,23 @@ export const Chat: React.FC = () => {
...
@@ -251,10 +276,23 @@ export const Chat: React.FC = () => {
>
>
<
div
className=
{
styles
.
inter
}
>
<
div
className=
{
styles
.
inter
}
>
{
allItems
.
map
((
record
,
index
)
=>
(
{
allItems
.
map
((
record
,
index
)
=>
(
<
div
className=
"w-full chatItem mx-auto"
key=
{
`${record.role}-${record.id || index}-${record.question || record.answerList?.[0]?.answer || ''}`
}
>
<
div
className=
"w-full chatItem mx-auto"
key=
{
`${record.role}-${record.id || index}-${
record.question || record.answerList?.[0]?.answer || ''
}`
}
>
{
record
.
role
===
'system'
&&
<
ChatWelcome
/>
}
{
record
.
role
===
'system'
&&
<
ChatWelcome
/>
}
{
record
.
role
===
'user'
&&
<
ChatItemUser
record=
{
record
}
/>
}
{
record
.
role
===
'user'
&&
<
ChatItemUser
record=
{
record
}
/>
}
{
record
.
role
===
'ai'
&&
<
ChatAnswerBox
onSubmitQuestion=
{
handleSubmitQuestion
}
isLastAnswer=
{
index
===
allItems
.
length
-
1
}
showIndex=
{
0
}
record=
{
record
}
index=
{
index
}
/>
}
{
record
.
role
===
'ai'
&&
(
<
ChatAnswerBox
onSubmitQuestion=
{
handleSubmitQuestion
}
isLastAnswer=
{
index
===
allItems
.
length
-
1
}
showIndex=
{
0
}
record=
{
record
}
index=
{
index
}
/>
)
}
</
div
>
</
div
>
))
}
))
}
</
div
>
</
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