Commit 88c37852 by HoMeTown

fix: 修复bug

parent 7c315e1e
...@@ -34,43 +34,8 @@ export const Chat: React.FC = () => { ...@@ -34,43 +34,8 @@ 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)
const handleSubmitQuestion = async (question: string, productCode?: string) => { /** 处理正常stream的数据 */
const isNew = allItems.length <= 1 const handleStreamMesageData = (msg: any, question: string) => {
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') {
setAllItems((prevItems) => { setAllItems((prevItems) => {
const newItems = [...prevItems] // 创建数组的浅拷贝 const newItems = [...prevItems] // 创建数组的浅拷贝
const lastIndex = newItems.length - 1 const lastIndex = newItems.length - 1
...@@ -91,11 +56,12 @@ export const Chat: React.FC = () => { ...@@ -91,11 +56,12 @@ export const Chat: React.FC = () => {
return newItems return newItems
}) })
} }
if (msg?.type === 'DATA' && msg?.content?.code === '01010005') {
// showToast('已超过会话支持的轮数上线!', 'error') /** 处理超过最大条数的数据 */
const handleChatMaxCount = (msg: any, question: string) => {
toast(t => ( toast(t => (
<div className="flex items-center"> <div className="flex items-center">
<p className="text-[14px]">⚠️ 超过最大轮数上线!请新建对话 👉🏻</p> <p className="text-[14px]">⚠️ 超过最大轮数上限!请新建对话 👉🏻</p>
<Button <Button
color="primary" color="primary"
size="sm" size="sm"
...@@ -117,10 +83,75 @@ export const Chat: React.FC = () => { ...@@ -117,10 +83,75 @@ export const Chat: React.FC = () => {
position: 'bottom-center', position: 'bottom-center',
duration: 0, duration: 0,
style: { style: {
// transform: 'translateY(-400px)',
marginBottom: '120px', 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 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' })
} }
......
...@@ -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} />}
......
...@@ -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()
......
...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment