From bedc1a65cdb713815aac4f18b3e32dea7a44cd1d Mon Sep 17 00:00:00 2001 From: yangzhe Date: Tue, 16 Dec 2025 11:44:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=81=8A=E5=A4=A9):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=95=99=E5=B8=88=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=B9=B6=E5=88=86=E7=A6=BBAI/=E6=95=99=E5=B8=88?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ChatHistory.vue | 56 ++++++++++++++++++++++---------------- pages/home/index/index.vue | 42 ++++++++++++++++++++++------ store/index.js | 23 +++++++++++++++- 3 files changed, 88 insertions(+), 33 deletions(-) diff --git a/components/ChatHistory.vue b/components/ChatHistory.vue index 5ec355f..c81f474 100644 --- a/components/ChatHistory.vue +++ b/components/ChatHistory.vue @@ -44,7 +44,7 @@ > @@ -63,7 +63,7 @@ 'chat-item-active': item.isActiveChat, }" @click.stop=" - selectChatItem(groupIndex, index, item.id, item.conversationId) + selectChatItem(item.id, item.conversationId, item.receiverId) " > @@ -90,12 +90,7 @@ [], + }, + chatHistoryTeacher: { type: Array, default: () => [], }, @@ -172,8 +171,6 @@ export default { return { baseUrl: "", showPopup: false, - currentActiveGroup: -1, - currentActiveIndex: -1, activeItemId: "", // 存储当前激活项的ID scrollToView: "", // 用于scroll-into-view属性 tabList: [ @@ -193,6 +190,12 @@ export default { }, computed: { + currentChatHistory() { + return this.currentTab === 0 + ? this.chatHistoryAI + : this.chatHistoryTeacher; + }, + headSculptureUrl() { if (this.vuex_user.HeadSculptureUrl) { return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl; @@ -224,7 +227,7 @@ export default { } }, // 监听聊天历史数据变化,找到激活项并滚动 - chatHistoryList3: { + chatHistoryAI: { handler() { this.$nextTick(() => { this.scrollToActiveItem(); @@ -308,10 +311,10 @@ export default { for ( let groupIndex = 0; - groupIndex < this.chatHistoryList3.length; + groupIndex < this.chatHistoryAI.length; groupIndex++ ) { - const group = this.chatHistoryList3[groupIndex]; + const group = this.chatHistoryAI[groupIndex]; for (let index = 0; index < group.conversation.length; index++) { const item = group.conversation[index]; if (item.isActiveChat) { @@ -326,16 +329,21 @@ export default { } }, - selectChatItem(groupIndex, index, id, conversationId) { - // this.currentActiveGroup = groupIndex; - // this.currentActiveIndex = index; - console.log("selectChatItem", groupIndex, index, id, conversationId); - - // 向父组件发送选中的对话信息 - this.$emit("select-conversation", { - id, - conversationId, - }); + selectChatItem(id, conversationId = null, receiverId = null) { + if (this.currentTab === 0) { + // 点击AI聊天项 + // 向父组件发送选中的对话信息 + this.$emit("select-conversation", { + id, + conversationId, + }); + } else { + // 点击教师聊天项 + this.$store.dispatch("selectTeacherChatItem", { + id, + receiverId, + }); + } }, handleCreateConversation() { diff --git a/pages/home/index/index.vue b/pages/home/index/index.vue index c32cd18..783d8c6 100644 --- a/pages/home/index/index.vue +++ b/pages/home/index/index.vue @@ -259,7 +259,8 @@ { - this.chatHistoryList3 = res.data; - if (this.chatHistoryList3.length > 0) { - this.chatHistoryList3 = res.data.map((group) => { + // 获取人工咨询历史记录 + async GetDialogueList_User() { + this.$u.api.GetDialogueList_UserApi().then((res) => { + this.chatHistoryTeacher = res.data; + if (this.chatHistoryTeacher.length > 0) { + this.chatHistoryTeacher = res.data.map((group) => { // 对每个组的conversation数组进行倒序排序 return { ...group, @@ -511,7 +515,29 @@ export default { }; }); } - console.log("this.chatHistoryList3", this.chatHistoryList3); + }); + }, + + // 获取ai历史记录 + async getChatHistoryList() { + this.$u.api.GetConversationPage().then((res) => { + this.chatHistoryAI = res.data; + if (this.chatHistoryAI.length > 0) { + this.chatHistoryAI = res.data.map((group) => { + // 对每个组的conversation数组进行倒序排序 + return { + ...group, + conversation: group.conversation.sort((a, b) => { + // 将日期字符串转换为时间戳并比较(倒序) + return ( + new Date(b.startTime).getTime() - + new Date(a.startTime).getTime() + ); + }), + }; + }); + } + console.log("this.chatHistoryAI", this.chatHistoryAI); }); }, diff --git a/store/index.js b/store/index.js index 53ac51f..75f9025 100644 --- a/store/index.js +++ b/store/index.js @@ -260,6 +260,24 @@ const store = new Vuex.Store({ } }, + // 点击聊天记录,切换到该会话 + selectTeacherChatItem({ commit, dispatch }, { id, receiverId }) { + // 清空消息列表,避免旧消息干扰 + commit("push_MsgList", []); + + Vue.prototype.$u.api + .GetReceiverUserInfoApi({ Id: receiverId }) + .then((res) => { + if (res.succeed && res.data) { + commit("set_MsgUser", { ...res.data, dialogueManagementId: id }); + uni.navigateTo({ + url: `/pages/chat/index`, + }); + return; + } + }); + }, + // 点击立即提问进入会话 // 1) 创建新会话 // 2) 获取接收者信息 @@ -271,7 +289,10 @@ const store = new Vuex.Store({ // 清空消息列表,避免旧消息干扰 commit("push_MsgList", []); - if (dialogueManagementId) { + if ( + dialogueManagementId && + dialogueManagementId !== "00000000-0000-0000-0000-000000000000" + ) { // 有会话ID,直接进入会话 commit("set_MsgUser", { ...user }); uni.navigateTo({