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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
44 deletions
+79
-44
src/pages/Chat/Chat.tsx
+74
-42
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,43 +34,8 @@ export const Chat: React.FC = () => {
const
scrollableRef
=
useRef
<
HTMLDivElement
|
any
>
(
null
)
const
position
=
useScroll
(
scrollableRef
)
const
handleSubmitQuestion
=
async
(
question
:
string
,
productCode
?:
string
)
=>
{
const
isNew
=
allItems
.
length
<=
1
dispatch
(
setIsAsking
(
true
))
// 添加用户提问的问题
setAllItems
(
prevItems
=>
[
...
prevItems
,
{
role
:
'user'
,
question
,
}
as
ChatRecord
,
])
// 检查token
await
fetchCheckTokenApi
()
// 添加一条空的ai问题
setAllItems
(
prevItems
=>
[
...
prevItems
,
{
role
:
'ai'
,
answerList
:
[{}],
}
as
ChatRecord
,
])
let
fetchUrl
=
`/conversation/api/conversation/mobile/v1/submit_question_stream`
const
proxy
=
import
.
meta
.
env
.
MODE
===
'dev'
?
'/api'
:
'/dev-sdream-api'
fetchUrl
=
proxy
+
fetchUrl
fetchStreamResponse
(
fetchUrl
,
{
question
,
conversationId
:
id
,
stream
:
true
,
productCode
,
},
(
msg
)
=>
{
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'00000000'
)
{
/** 处理正常stream的数据 */
const
handleStreamMesageData
=
(
msg
:
any
,
question
:
string
)
=>
{
setAllItems
((
prevItems
)
=>
{
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
lastIndex
=
newItems
.
length
-
1
...
...
@@ -91,11 +56,12 @@ export const Chat: React.FC = () => {
return
newItems
})
}
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'01010005'
)
{
// showToast('已超过会话支持的轮数上线!', 'error')
/** 处理超过最大条数的数据 */
const
handleChatMaxCount
=
(
msg
:
any
,
question
:
string
)
=>
{
toast
(
t
=>
(
<
div
className=
"flex items-center"
>
<
p
className=
"text-[14px]"
>
⚠️ 超过最大轮数上线
!请新建对话 👉🏻
</
p
>
<
p
className=
"text-[14px]"
>
⚠️ 超过最大轮数上限
!请新建对话 👉🏻
</
p
>
<
Button
color=
"primary"
size=
"sm"
...
...
@@ -117,10 +83,75 @@ export const Chat: React.FC = () => {
position
:
'bottom-center'
,
duration
:
0
,
style
:
{
// transform: 'translateY(-400px)',
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
isNew
=
allItems
.
length
<=
1
dispatch
(
setIsAsking
(
true
))
// 添加用户提问的问题
setAllItems
(
prevItems
=>
[
...
prevItems
,
{
role
:
'user'
,
question
,
}
as
ChatRecord
,
])
// 检查token
await
fetchCheckTokenApi
()
// 添加一条空的ai问题
setAllItems
(
prevItems
=>
[
...
prevItems
,
{
role
:
'ai'
,
answerList
:
[{}],
}
as
ChatRecord
,
])
let
fetchUrl
=
`/conversation/api/conversation/mobile/v1/submit_question_stream`
const
proxy
=
import
.
meta
.
env
.
MODE
===
'dev'
?
'/api'
:
'/dev-sdream-api'
fetchUrl
=
proxy
+
fetchUrl
fetchStreamResponse
(
fetchUrl
,
{
question
,
conversationId
:
id
,
stream
:
true
,
productCode
,
},
(
msg
)
=>
{
// 正常的stream数据
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'00000000'
)
{
handleStreamMesageData
(
msg
,
question
)
}
if
(
msg
?.
type
===
'DATA'
&&
msg
?.
content
?.
code
===
'01010005'
)
{
handleChatMaxCount
(
msg
,
question
)
return
}
if
(
msg
.
type
===
'END'
)
{
...
...
@@ -134,6 +165,7 @@ export const Chat: React.FC = () => {
)
}
/** 获取qa记录 */
const
getUserQaRecordPage
=
useCallback
(
async
(
conversationId
:
string
)
=>
{
setIsLoading
(
true
)
try
{
...
...
@@ -154,8 +186,8 @@ export const Chat: React.FC = () => {
}
},
[
shouldSendQuestion
])
/** 点击滚动到底部 */
const
scrollToBottom
=
()
=>
{
// scrollableRef.current.scrollTop = scrollableRef.current.scrollHeight
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,
?
(
<
div
className=
"content"
>
{
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
>
)
:
<
SdreamLoading
/>
}
...
...
@@ -77,6 +78,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
)
}
{
isLastAnswer
&&
!
item
.
isChatMaxCount
&&
isShowRecommend
&&
recommendUseAnswer
&&
<
ChatAnswerRecommend
onSubmitQuestion=
{
onSubmitQuestion
}
answer=
{
recommendUseAnswer
}
/>
}
...
...
src/pages/Tools/Tools.tsx
View file @
88c37852
...
...
@@ -36,7 +36,7 @@ function getAnimationProps(delay: number) {
export
const
Tools
:
React
.
FC
=
()
=>
{
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
:
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: '' },
]
const
showToast
=
useToast
()
...
...
src/types/chat.ts
View file @
88c37852
...
...
@@ -34,6 +34,7 @@ interface AnswerStep {
export
interface
Answer
{
endAnswerFlag
?:
boolean
isStopTyping
?:
boolean
isChatMaxCount
?:
boolean
isShow
:
boolean
answer
:
string
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