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
88c37852
Commit
88c37852
authored
Jan 23, 2025
by
HoMeTown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复bug
parent
7c315e1e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
51 deletions
+86
-51
src/pages/Chat/Chat.tsx
+81
-49
src/pages/Chat/components/ChatItem/ChatAnswerBox.tsx
+3
-1
src/pages/Tools/Tools.tsx
+1
-1
src/types/chat.ts
+1
-0
No files found.
src/pages/Chat/Chat.tsx
View file @
88c37852
...
@@ -34,6 +34,82 @@ export const Chat: React.FC = () => {
...
@@ -34,6 +34,82 @@ export const Chat: React.FC = () => {
const
scrollableRef
=
useRef
<
HTMLDivElement
|
any
>
(
null
)
const
scrollableRef
=
useRef
<
HTMLDivElement
|
any
>
(
null
)
const
position
=
useScroll
(
scrollableRef
)
const
position
=
useScroll
(
scrollableRef
)
/** 处理正常stream的数据 */
const
handleStreamMesageData
=
(
msg
:
any
,
question
:
string
)
=>
{
setAllItems
((
prevItems
)
=>
{
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
lastIndex
=
newItems
.
length
-
1
if
(
lastIndex
>=
0
)
{
// 创建最后一项的新对象,合并现有数据和新的 answer
newItems
[
lastIndex
]
=
{
...
newItems
[
lastIndex
],
question
,
answerList
:
[
{
...
msg
.
content
.
data
,
isShow
:
false
,
answer
:
(
newItems
[
lastIndex
].
answerList
[
0
].
answer
||
''
)
+
msg
.
content
.
data
.
answer
,
},
],
}
}
return
newItems
})
}
/** 处理超过最大条数的数据 */
const
handleChatMaxCount
=
(
msg
:
any
,
question
:
string
)
=>
{
toast
(
t
=>
(
<
div
className=
"flex items-center"
>
<
p
className=
"text-[14px]"
>
⚠️ 超过最大轮数上限!请新建对话 👉🏻
</
p
>
<
Button
color=
"primary"
size=
"sm"
variant=
"light"
isIconOnly
onClick=
{
()
=>
{
dispatch
(
createConversation
({
conversationData
:
{},
shouldNavigate
:
true
,
shouldSendQuestion
:
''
,
}))
toast
.
dismiss
(
t
.
id
)
}
}
>
<
AddNewChat
/>
</
Button
>
</
div
>
),
{
position
:
'bottom-center'
,
duration
:
0
,
style
:
{
marginBottom
:
'120px'
,
},
})
setAllItems
((
prevItems
)
=>
{
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
lastIndex
=
newItems
.
length
-
1
if
(
lastIndex
>=
0
)
{
// 创建最后一项的新对象,合并现有数据和新的 answer
newItems
[
lastIndex
]
=
{
...
newItems
[
lastIndex
],
question
,
answerList
:
[
{
...
msg
.
content
.
data
,
isShow
:
false
,
isChatMaxCount
:
true
,
endAnswerFlag
:
true
,
answer
:
'已达上限'
,
},
],
}
}
return
newItems
})
}
/** 提交问题 */
const
handleSubmitQuestion
=
async
(
question
:
string
,
productCode
?:
string
)
=>
{
const
handleSubmitQuestion
=
async
(
question
:
string
,
productCode
?:
string
)
=>
{
const
isNew
=
allItems
.
length
<=
1
const
isNew
=
allItems
.
length
<=
1
dispatch
(
setIsAsking
(
true
))
dispatch
(
setIsAsking
(
true
))
...
@@ -70,57 +146,12 @@ export const Chat: React.FC = () => {
...
@@ -70,57 +146,12 @@ export const Chat: React.FC = () => {
productCode
,
productCode
,
},
},
(
msg
)
=>
{
(
msg
)
=>
{
// 正常的stream数据
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'00000000'
)
{
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'00000000'
)
{
setAllItems
((
prevItems
)
=>
{
handleStreamMesageData
(
msg
,
question
)
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
lastIndex
=
newItems
.
length
-
1
if
(
lastIndex
>=
0
)
{
// 创建最后一项的新对象,合并现有数据和新的 answer
newItems
[
lastIndex
]
=
{
...
newItems
[
lastIndex
],
question
,
answerList
:
[
{
...
msg
.
content
.
data
,
isShow
:
false
,
answer
:
(
newItems
[
lastIndex
].
answerList
[
0
].
answer
||
''
)
+
msg
.
content
.
data
.
answer
,
},
],
}
}
return
newItems
})
}
}
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'01010005'
)
{
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'01010005'
)
{
// showToast('已超过会话支持的轮数上线!', 'error')
handleChatMaxCount
(
msg
,
question
)
toast
(
t
=>
(
<
div
className=
"flex items-center"
>
<
p
className=
"text-[14px]"
>
⚠️ 超过最大轮数上线!请新建对话 👉🏻
</
p
>
<
Button
color=
"primary"
size=
"sm"
variant=
"light"
isIconOnly
onClick=
{
()
=>
{
dispatch
(
createConversation
({
conversationData
:
{},
shouldNavigate
:
true
,
shouldSendQuestion
:
''
,
}))
toast
.
dismiss
(
t
.
id
)
}
}
>
<
AddNewChat
/>
</
Button
>
</
div
>
),
{
position
:
'bottom-center'
,
duration
:
0
,
style
:
{
// transform: 'translateY(-400px)',
marginBottom
:
'120px'
,
},
})
return
return
}
}
if
(
msg
.
type
===
'END'
)
{
if
(
msg
.
type
===
'END'
)
{
...
@@ -134,6 +165,7 @@ export const Chat: React.FC = () => {
...
@@ -134,6 +165,7 @@ export const Chat: React.FC = () => {
)
)
}
}
/** 获取qa记录 */
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
)
=>
{
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
)
=>
{
setIsLoading
(
true
)
setIsLoading
(
true
)
try
{
try
{
...
@@ -154,8 +186,8 @@ export const Chat: React.FC = () => {
...
@@ -154,8 +186,8 @@ export const Chat: React.FC = () => {
}
}
},
[
shouldSendQuestion
])
},
[
shouldSendQuestion
])
/** 点击滚动到底部 */
const
scrollToBottom
=
()
=>
{
const
scrollToBottom
=
()
=>
{
// scrollableRef.current.scrollTop = scrollableRef.current.scrollHeight
scrollableRef
.
current
.
scrollTo
(
scrollableRef
.
current
.
scrollHeight
,
{
behavior
:
'smooth'
})
scrollableRef
.
current
.
scrollTo
(
scrollableRef
.
current
.
scrollHeight
,
{
behavior
:
'smooth'
})
}
}
...
...
src/pages/Chat/components/ChatItem/ChatAnswerBox.tsx
View file @
88c37852
...
@@ -60,7 +60,8 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
...
@@ -60,7 +60,8 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
?
(
?
(
<
div
className=
"content"
>
<
div
className=
"content"
>
{
item
.
isShow
&&
<
ChatAnswerShower
onSubmitQuestion=
{
onSubmitQuestion
}
isLastAnswer=
{
isLastAnswer
}
answer=
{
item
}
/>
}
{
item
.
isShow
&&
<
ChatAnswerShower
onSubmitQuestion=
{
onSubmitQuestion
}
isLastAnswer=
{
isLastAnswer
}
answer=
{
item
}
/>
}
{
!
item
.
isShow
&&
<
ChatAnswerParser
onSubmitQuestion=
{
onSubmitQuestion
}
isLastAnswer=
{
isLastAnswer
}
isStopTyping=
{
item
.
isStopTyping
}
onTyping=
{
handleTyping
}
onComplate=
{
()
=>
handleComplate
(
item
)
}
answer=
{
item
}
/>
}
{
!
item
.
isShow
&&
!
item
.
isChatMaxCount
&&
<
ChatAnswerParser
onSubmitQuestion=
{
onSubmitQuestion
}
isLastAnswer=
{
isLastAnswer
}
isStopTyping=
{
item
.
isStopTyping
}
onTyping=
{
handleTyping
}
onComplate=
{
()
=>
handleComplate
(
item
)
}
answer=
{
item
}
/>
}
{
!
item
.
isShow
&&
item
.
isChatMaxCount
&&
<
div
>
{
item
.
answer
}
</
div
>
}
</
div
>
</
div
>
)
)
:
<
SdreamLoading
/>
}
:
<
SdreamLoading
/>
}
...
@@ -77,6 +78,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
...
@@ -77,6 +78,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
)
}
)
}
{
isLastAnswer
{
isLastAnswer
&&
!
item
.
isChatMaxCount
&&
isShowRecommend
&&
isShowRecommend
&&
recommendUseAnswer
&&
recommendUseAnswer
&&
<
ChatAnswerRecommend
onSubmitQuestion=
{
onSubmitQuestion
}
answer=
{
recommendUseAnswer
}
/>
}
&&
<
ChatAnswerRecommend
onSubmitQuestion=
{
onSubmitQuestion
}
answer=
{
recommendUseAnswer
}
/>
}
...
...
src/pages/Tools/Tools.tsx
View file @
88c37852
...
@@ -36,7 +36,7 @@ function getAnimationProps(delay: number) {
...
@@ -36,7 +36,7 @@ function getAnimationProps(delay: number) {
export
const
Tools
:
React
.
FC
=
()
=>
{
export
const
Tools
:
React
.
FC
=
()
=>
{
const
tools
=
[
const
tools
=
[
{
name
:
'定制计划书'
,
desc
:
'预估保费,辅助决策'
,
icon
:
ToolsCalculation
,
linkUrl
:
'http://82.157.184.197:8118/dist/#/BusinessPlan?name=%E5%AE%9A%E5%88%B6%E8%AE%A1%E5%88%92%E4%B9%A6&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwaG9uZSI6IjJYbFhId1RTRkZYMm1NTGd2OSsrZkE9PSIsInVzZXJJZCI6Im9RZ2Y0U0dpY2FBaTFoU1M3Nm80Wmc9PSIsInRpbWVzdGFtcCI6ImdhaU15S2VaaEZpODRVeWVRSk8wWEE9PSJ9.lLkD0q7teg4DzqQVNiMc7L4jGOIqxxFimC7JgSE3ci4'
},
{
name
:
'定制计划书'
,
desc
:
'预估保费,辅助决策'
,
icon
:
ToolsCalculation
,
linkUrl
:
'http://82.157.184.197:8118/dist/#/BusinessPlan?name=%E5%AE%9A%E5%88%B6%E8%AE%A1%E5%88%92%E4%B9%A6&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwaG9uZSI6IjJYbFhId1RTRkZYMm1NTGd2OSsrZkE9PSIsInVzZXJJZCI6Im9RZ2Y0U0dpY2FBaTFoU1M3Nm80Wmc9PSIsInRpbWVzdGFtcCI6ImdhaU15S2VaaEZpODRVeWVRSk8wWEE9PSJ9.lLkD0q7teg4DzqQVNiMc7L4jGOIqxxFimC7JgSE3ci4'
},
{
name
:
'产品比对'
,
desc
:
'客观中立全维度比对'
,
icon
:
ToolsNav
,
linkUrl
:
'
http://82.157.184.197:8118/dist/#/CompareListAI?type=L&id=ff80808191f018b60191ff37216b000b&age=30&productIdList=102001011,102001008&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwaG9uZSI6IjJYbFhId1RTRkZYMm1NTGd2OSsrZkE9PSIsInVzZXJJZCI6Im9RZ2Y0U0dpY2FBaTFoU1M3Nm80Wmc9PSIsInRpbWVzdGFtcCI6ImdhaU15S2VaaEZpODRVeWVRSk8wWEE9PSJ9.lLkD0q7teg4DzqQVNiMc7L4jGOIqxxFimC7JgSE3ci4
'
},
{
name
:
'产品比对'
,
desc
:
'客观中立全维度比对'
,
icon
:
ToolsNav
,
linkUrl
:
''
},
// { name: '净值查询', desc: '支持商养产品净值查询', icon: ToolsDetail, linkUrl: '' },
// { name: '净值查询', desc: '支持商养产品净值查询', icon: ToolsDetail, linkUrl: '' },
]
]
const
showToast
=
useToast
()
const
showToast
=
useToast
()
...
...
src/types/chat.ts
View file @
88c37852
...
@@ -34,6 +34,7 @@ interface AnswerStep {
...
@@ -34,6 +34,7 @@ interface AnswerStep {
export
interface
Answer
{
export
interface
Answer
{
endAnswerFlag
?:
boolean
endAnswerFlag
?:
boolean
isStopTyping
?:
boolean
isStopTyping
?:
boolean
isChatMaxCount
?:
boolean
isShow
:
boolean
isShow
:
boolean
answer
:
string
answer
:
string
collectionFlag
?:
boolean
collectionFlag
?:
boolean
...
...
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