Bläddra i källkod

机器人对话消息持久化

wangqi49 1 månad sedan
förälder
incheckning
3f3933c0a5
1 ändrade filer med 21 tillägg och 1 borttagningar
  1. 21 1
      webchat-front-client/src/views/ChatRobot.vue

+ 21 - 1
webchat-front-client/src/views/ChatRobot.vue

@@ -68,10 +68,30 @@
         const running = ref(false);
         const md = new MarkdownIt();
         const robotMessage = ref('');
-        const chatCoreContainerRef = ref(null); // 消息列表容器的 ref
+        const chatCoreContainerRef = ref(null);
+        
+        const loadChatMessages = (chatUserId) => {
+            // 先清空
+            axios.get(`/client-service/chat/message/list/`+chatUserId, {})
+            .then(function (response) {
+                if (response.data.code === 40001) {
+                    // 未登录
+                    window.location.href = response.data.redirect_url;
+                } else if (response.data.code === 200) {
+                    if (response.data.data.length > 0) {
+                        chatMessageArr.value = response.data.data;
+                    }
+                }
+            }).catch(function (error) {
+                // 处理错误
+                console.error(error);
+            });
+        }
+        loadChatMessages( selectChatUser.value.userId);
         // 切换对话用户,父组件传递选中用户信息,监听选中用户变化
         watch(() => props.selectChatUserRef, (newValue) => {
             selectChatUser.value = newValue;
+            loadChatMessages(selectChatUser.value.userId);
         });    
         
         // SSE链接,用户机器人对话