feat: 对话页面的调整与增加加载loading
This commit is contained in:
@@ -42,6 +42,8 @@
|
||||
item.msg ? item.msg.length : 0
|
||||
}`"
|
||||
:text="item.msg || ''"
|
||||
,
|
||||
:isLoading="item.isLoading"
|
||||
>
|
||||
<template #content v-if="item.toolCall">
|
||||
<QuickBookingComponent
|
||||
@@ -219,6 +221,7 @@ let loadingTimer = null;
|
||||
const emits = defineEmits(["openDrawer"]);
|
||||
const openDrawer = () => emits("openDrawer");
|
||||
|
||||
/// =============事件函数↓================
|
||||
const handleTouchEnd = () => {
|
||||
clearTimeout(timer.value);
|
||||
timer.value = setTimeout(() => {
|
||||
@@ -308,6 +311,32 @@ const sendMessageAction = (inputText) => {
|
||||
setTimeoutScrollToBottom();
|
||||
};
|
||||
|
||||
/// 添加通知
|
||||
const addNoticeListener = () => {
|
||||
uni.$on(SCROLL_TO_BOTTOM, () => {
|
||||
setTimeout(() => {
|
||||
scrollToBottom();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
uni.$on(RECOMMEND_POSTS_TITLE, (value) => {
|
||||
console.log("RECOMMEND_POSTS_TITLE:", value);
|
||||
if (value && value.length > 0) {
|
||||
handleReply(value);
|
||||
}
|
||||
});
|
||||
|
||||
uni.$on(SEND_COMMAND_TEXT, (value) => {
|
||||
console.log("SEND_COMMAND_TEXT:", value);
|
||||
if (value && value.length > 0) {
|
||||
commonType = "Command.quickBooking";
|
||||
sendMessage(value, true);
|
||||
setTimeoutScrollToBottom();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/// =============生命周期函数↓================
|
||||
onLoad(() => {
|
||||
uni.getSystemInfo({
|
||||
success: (res) => {
|
||||
@@ -329,6 +358,38 @@ onMounted(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
/// =============页面配置↓================
|
||||
// 获取最近一次的会话id
|
||||
const loadRecentConversation = async () => {
|
||||
const res = await recentConversation();
|
||||
if (res.code === 0) {
|
||||
conversationId.value = res.data.conversationId;
|
||||
}
|
||||
};
|
||||
|
||||
// 加载历史消息的数据
|
||||
let historyCurrentPageNum = 1;
|
||||
const loadConversationMsgList = async () => {
|
||||
const args = {
|
||||
pageNum: historyCurrentPageNum++,
|
||||
pageSize: 10,
|
||||
conversationId: conversationId.value,
|
||||
};
|
||||
const res = await conversationMsgList(args);
|
||||
};
|
||||
|
||||
// 获取首页数据
|
||||
const getMainPageData = async () => {
|
||||
const res = await mainPageData(sceneId.value);
|
||||
if (res.code === 0) {
|
||||
mainPageDataModel.value = res.data;
|
||||
agentId.value = res.data.agentId;
|
||||
initData();
|
||||
setTimeoutScrollToBottom();
|
||||
}
|
||||
};
|
||||
|
||||
/// =============对话↓================
|
||||
// 初始化WebSocket
|
||||
const initWebSocket = () => {
|
||||
// 清理旧实例
|
||||
@@ -394,13 +455,12 @@ const handleWebSocketMessage = (data) => {
|
||||
clearInterval(loadingTimer);
|
||||
loadingTimer = null;
|
||||
}
|
||||
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//console.log("处理WebSocket消息:", data);
|
||||
|
||||
// 确保消息内容是字符串类型
|
||||
if (data.content && typeof data.content !== "string") {
|
||||
data.content = String(data.content);
|
||||
@@ -435,6 +495,7 @@ const handleWebSocketMessage = (data) => {
|
||||
console.log("全量消息内容:", msg);
|
||||
if (!msg || msg === "加载中." || msg.startsWith("加载中")) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试";
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "";
|
||||
}
|
||||
@@ -486,6 +547,7 @@ const initTypewriterManager = () => {
|
||||
onContentUpdate: (content) => {
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (aiMsgIndex >= 0 && chatMsgList.value[aiMsgIndex]) {
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
chatMsgList.value[aiMsgIndex].msg = content;
|
||||
}
|
||||
},
|
||||
@@ -493,6 +555,7 @@ const initTypewriterManager = () => {
|
||||
onTypingComplete: (finalContent) => {
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (aiMsgIndex >= 0 && chatMsgList.value[aiMsgIndex]) {
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
chatMsgList.value[aiMsgIndex].msg = finalContent;
|
||||
}
|
||||
// 打字完成后最后一次滚动到底部
|
||||
@@ -508,60 +571,6 @@ const resetMessageState = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const addNoticeListener = () => {
|
||||
uni.$on(SCROLL_TO_BOTTOM, () => {
|
||||
setTimeout(() => {
|
||||
scrollToBottom();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
uni.$on(RECOMMEND_POSTS_TITLE, (value) => {
|
||||
console.log("RECOMMEND_POSTS_TITLE:", value);
|
||||
if (value && value.length > 0) {
|
||||
handleReply(value);
|
||||
}
|
||||
});
|
||||
|
||||
uni.$on(SEND_COMMAND_TEXT, (value) => {
|
||||
console.log("SEND_COMMAND_TEXT:", value);
|
||||
if (value && value.length > 0) {
|
||||
commonType = "Command.quickBooking";
|
||||
sendMessage(value, true);
|
||||
setTimeoutScrollToBottom();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 获取最近一次的会话id
|
||||
const loadRecentConversation = async () => {
|
||||
const res = await recentConversation();
|
||||
if (res.code === 0) {
|
||||
conversationId.value = res.data.conversationId;
|
||||
}
|
||||
};
|
||||
|
||||
// 加载历史消息的数据
|
||||
let historyCurrentPageNum = 1;
|
||||
const loadConversationMsgList = async () => {
|
||||
const args = {
|
||||
pageNum: historyCurrentPageNum++,
|
||||
pageSize: 10,
|
||||
conversationId: conversationId.value,
|
||||
};
|
||||
const res = await conversationMsgList(args);
|
||||
};
|
||||
|
||||
// 获取首页数据
|
||||
const getMainPageData = async () => {
|
||||
const res = await mainPageData(sceneId.value);
|
||||
if (res.code === 0) {
|
||||
mainPageDataModel.value = res.data;
|
||||
agentId.value = res.data.agentId;
|
||||
initData();
|
||||
setTimeoutScrollToBottom();
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化数据 首次数据加载的时候
|
||||
const initData = () => {
|
||||
const msg = {
|
||||
@@ -671,6 +680,11 @@ const stopRequest = () => {
|
||||
// 发送中断消息给服务器 (messageType=2)
|
||||
sendWebSocketMessage(2, "stop_request", { silent: true });
|
||||
|
||||
if (loadingTimer) {
|
||||
clearInterval(loadingTimer);
|
||||
loadingTimer = null;
|
||||
}
|
||||
|
||||
// 停止打字机效果
|
||||
if (typewriterManager) {
|
||||
typewriterManager.stopTypewriter();
|
||||
|
||||
Reference in New Issue
Block a user