feat(聊天): 添加教师聊天记录功能并分离AI/教师聊天数据

This commit is contained in:
yangzhe 2025-12-16 11:44:35 +08:00
parent eab59c8259
commit bedc1a65cd
3 changed files with 88 additions and 33 deletions

View File

@ -44,7 +44,7 @@
>
<!-- 使用新的数据结构渲染聊天历史 -->
<view
v-for="(group, groupIndex) in chatHistoryList3"
v-for="(group, groupIndex) in currentChatHistory"
:key="'group-' + group.id + groupIndex"
@click="closePopover"
>
@ -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)
"
>
<view class="chat-item-content">
@ -90,12 +90,7 @@
<view
class="popover-item"
@click.stop="
selectChatItem(
groupIndex,
index,
item.id,
item.conversationId
)
selectChatItem(item.id, item.conversationId, item.receiverId)
"
>
<u-icon
@ -155,7 +150,11 @@ export default {
type: Boolean,
default: false,
},
chatHistoryList3: {
chatHistoryAI: {
type: Array,
default: () => [],
},
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);
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() {

View File

@ -259,7 +259,8 @@
<!-- 对话弹出层 -->
<chat-history
:show.sync="popupShow"
:chat-history-list3="chatHistoryList3"
:chatHistoryAI="chatHistoryAI"
:chatHistoryTeacher="chatHistoryTeacher"
:user-name="vuex_user ? vuex_user.Name : ''"
@select-conversation="handleSelectConversation"
@create-conversation="handleCreateConversation"
@ -353,7 +354,7 @@ export default {
},
],
popupShow: false,
chatHistoryList3: [
chatHistoryAI: [
// {
// "id": "",
// "conversation": [
@ -385,6 +386,7 @@ export default {
// ]
// }
],
chatHistoryTeacher: [],
activeIndex: 0,
commonQuestions: [
"新生报到流程",
@ -467,6 +469,7 @@ export default {
methods: {
async handleLeftClick() {
await this.getChatHistoryList();
await this.GetDialogueList_User();
this.handlePopupShow();
},
@ -493,11 +496,12 @@ export default {
}
},
async getChatHistoryList() {
this.$u.api.GetConversationPage().then((res) => {
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);
});
},

View File

@ -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({