diff --git a/pages/chat/ChatCardAI.vue b/pages/chat/ChatCardAI.vue
index bb4a7e3..d86bcba 100644
--- a/pages/chat/ChatCardAI.vue
+++ b/pages/chat/ChatCardAI.vue
@@ -1,11 +1,14 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
\ No newline at end of file
+
+.loading-container {
+ display: flex;
+ align-items: center;
+ padding: 4px 0;
+}
+
+.loading-img {
+ margin-left: -4px;
+ width: 32px;
+ height: 32px;
+}
+
+
diff --git a/pages/chat/ChatMainList.vue b/pages/chat/ChatMainList.vue
index 43e4708..ad3c640 100644
--- a/pages/chat/ChatMainList.vue
+++ b/pages/chat/ChatMainList.vue
@@ -42,6 +42,8 @@
item.msg ? item.msg.length : 0
}`"
:text="item.msg || ''"
+ ,
+ :isLoading="item.isLoading"
>
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();
diff --git a/pages/chat/ChatTopWelcome.vue b/pages/chat/ChatTopWelcome.vue
index a9ce4b6..f1a08c6 100644
--- a/pages/chat/ChatTopWelcome.vue
+++ b/pages/chat/ChatTopWelcome.vue
@@ -1,69 +1,75 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/static/msg_loading.svg b/static/msg_loading.svg
new file mode 100644
index 0000000..18f4786
--- /dev/null
+++ b/static/msg_loading.svg
@@ -0,0 +1,49 @@
+
\ No newline at end of file