|
|
@@ -17,6 +17,8 @@ type TRobotMessageWithOptionalId = Omit<TRobotMessage, "msgUk"> & {
|
|
|
|
|
|
const INIT_CURRENT_ROBOT_MSG_UK = ''
|
|
|
|
|
|
+const SCROLL_STEP = 1
|
|
|
+
|
|
|
export interface TextChat {
|
|
|
currentRobotMsgUk: string; // 当前正在说话的 AI 机器人 id, 可用于控制是否继续输出文本至当前 message 框内
|
|
|
scrollTop: number; // 控制聊天内容变化后滚动至最底部
|
|
|
@@ -119,13 +121,12 @@ export const useTextChat = create<TextChat>((set, get) => ({
|
|
|
return {
|
|
|
list: [...state.list, newRobotMessage],
|
|
|
currentRobotMsgUk: msgUk,
|
|
|
- scrollTop: state.scrollTop + 1,
|
|
|
};
|
|
|
});
|
|
|
setTimeout(()=> {
|
|
|
set((state) => {
|
|
|
return {
|
|
|
- scrollTop: state.scrollTop + 1,
|
|
|
+ scrollTop: state.scrollTop + SCROLL_STEP,
|
|
|
};
|
|
|
});
|
|
|
}, 100)
|
|
|
@@ -144,7 +145,7 @@ export const useTextChat = create<TextChat>((set, get) => ({
|
|
|
setTimeout(()=> {
|
|
|
set((state) => {
|
|
|
return {
|
|
|
- scrollTop: state.scrollTop + 1,
|
|
|
+ scrollTop: state.scrollTop + SCROLL_STEP,
|
|
|
};
|
|
|
});
|
|
|
}, 100)
|
|
|
@@ -162,7 +163,7 @@ export const useTextChat = create<TextChat>((set, get) => ({
|
|
|
// console.log('autoScroll: ', state.autoScroll)
|
|
|
if(state.autoScroll){
|
|
|
return {
|
|
|
- scrollTop: state.scrollTop + 1,
|
|
|
+ scrollTop: state.scrollTop + SCROLL_STEP,
|
|
|
};
|
|
|
}
|
|
|
return {scrollTop: state.scrollTop};
|
|
|
@@ -176,7 +177,7 @@ export const useTextChat = create<TextChat>((set, get) => ({
|
|
|
}
|
|
|
return message; // 返回未修改的 message
|
|
|
});
|
|
|
- return { list: updatedList, scrollTop: state.scrollTop + 1 }; // 返回新的状态
|
|
|
+ return { list: updatedList, scrollTop: state.scrollTop + SCROLL_STEP }; // 返回新的状态
|
|
|
});
|
|
|
return msgUk
|
|
|
},
|
|
|
@@ -196,9 +197,18 @@ export const useTextChat = create<TextChat>((set, get) => ({
|
|
|
if(body?.contentType === EContentType.AiseekQA){
|
|
|
scrollTopValue = state.scrollTop + 200
|
|
|
}else{
|
|
|
- scrollTopValue = state.scrollTop + 1
|
|
|
+ scrollTopValue = state.scrollTop + SCROLL_STEP
|
|
|
}
|
|
|
- return { list: updatedList, scrollTop: state.autoScroll ? scrollTopValue : state.scrollTop}; // 返回新的状态
|
|
|
+
|
|
|
+ setTimeout(()=> {
|
|
|
+ set((state) => {
|
|
|
+ return {
|
|
|
+ scrollTop: state.autoScroll ? scrollTopValue : state.scrollTop
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }, 100)
|
|
|
+
|
|
|
+ return { list: updatedList }; // 返回新的状态
|
|
|
});
|
|
|
},
|
|
|
updateMessageReaction: (msgId, data)=> {
|
|
|
@@ -225,7 +235,7 @@ export const useTextChat = create<TextChat>((set, get) => ({
|
|
|
const isEmptyContent = message.content.length <= 0
|
|
|
return (message.msgUk !== msgUk && isEmptyContent)
|
|
|
});
|
|
|
- return { list: filtered, scrollTop: state.scrollTop + 1 }; // 返回新的状态
|
|
|
+ return { list: filtered, scrollTop: state.scrollTop + SCROLL_STEP }; // 返回新的状态
|
|
|
});
|
|
|
}
|
|
|
}));
|