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 <view
v-for="(group, groupIndex) in chatHistoryList3" v-for="(group, groupIndex) in currentChatHistory"
:key="'group-' + group.id + groupIndex" :key="'group-' + group.id + groupIndex"
@click="closePopover" @click="closePopover"
> >
@ -63,7 +63,7 @@
'chat-item-active': item.isActiveChat, 'chat-item-active': item.isActiveChat,
}" }"
@click.stop=" @click.stop="
selectChatItem(groupIndex, index, item.id, item.conversationId) selectChatItem(item.id, item.conversationId, item.receiverId)
" "
> >
<view class="chat-item-content"> <view class="chat-item-content">
@ -90,12 +90,7 @@
<view <view
class="popover-item" class="popover-item"
@click.stop=" @click.stop="
selectChatItem( selectChatItem(item.id, item.conversationId, item.receiverId)
groupIndex,
index,
item.id,
item.conversationId
)
" "
> >
<u-icon <u-icon
@ -155,7 +150,11 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
chatHistoryList3: { chatHistoryAI: {
type: Array,
default: () => [],
},
chatHistoryTeacher: {
type: Array, type: Array,
default: () => [], default: () => [],
}, },
@ -172,8 +171,6 @@ export default {
return { return {
baseUrl: "", baseUrl: "",
showPopup: false, showPopup: false,
currentActiveGroup: -1,
currentActiveIndex: -1,
activeItemId: "", // ID activeItemId: "", // ID
scrollToView: "", // scroll-into-view scrollToView: "", // scroll-into-view
tabList: [ tabList: [
@ -193,6 +190,12 @@ export default {
}, },
computed: { computed: {
currentChatHistory() {
return this.currentTab === 0
? this.chatHistoryAI
: this.chatHistoryTeacher;
},
headSculptureUrl() { headSculptureUrl() {
if (this.vuex_user.HeadSculptureUrl) { if (this.vuex_user.HeadSculptureUrl) {
return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl; return this.baseUrl + "/" + this.vuex_user.HeadSculptureUrl;
@ -224,7 +227,7 @@ export default {
} }
}, },
// //
chatHistoryList3: { chatHistoryAI: {
handler() { handler() {
this.$nextTick(() => { this.$nextTick(() => {
this.scrollToActiveItem(); this.scrollToActiveItem();
@ -308,10 +311,10 @@ export default {
for ( for (
let groupIndex = 0; let groupIndex = 0;
groupIndex < this.chatHistoryList3.length; groupIndex < this.chatHistoryAI.length;
groupIndex++ groupIndex++
) { ) {
const group = this.chatHistoryList3[groupIndex]; const group = this.chatHistoryAI[groupIndex];
for (let index = 0; index < group.conversation.length; index++) { for (let index = 0; index < group.conversation.length; index++) {
const item = group.conversation[index]; const item = group.conversation[index];
if (item.isActiveChat) { if (item.isActiveChat) {
@ -326,16 +329,21 @@ export default {
} }
}, },
selectChatItem(groupIndex, index, id, conversationId) { selectChatItem(id, conversationId = null, receiverId = null) {
// this.currentActiveGroup = groupIndex; if (this.currentTab === 0) {
// this.currentActiveIndex = index; // AI
console.log("selectChatItem", groupIndex, index, id, conversationId); //
this.$emit("select-conversation", {
// id,
this.$emit("select-conversation", { conversationId,
id, });
conversationId, } else {
}); //
this.$store.dispatch("selectTeacherChatItem", {
id,
receiverId,
});
}
}, },
handleCreateConversation() { handleCreateConversation() {

View File

@ -259,7 +259,8 @@
<!-- 对话弹出层 --> <!-- 对话弹出层 -->
<chat-history <chat-history
:show.sync="popupShow" :show.sync="popupShow"
:chat-history-list3="chatHistoryList3" :chatHistoryAI="chatHistoryAI"
:chatHistoryTeacher="chatHistoryTeacher"
:user-name="vuex_user ? vuex_user.Name : ''" :user-name="vuex_user ? vuex_user.Name : ''"
@select-conversation="handleSelectConversation" @select-conversation="handleSelectConversation"
@create-conversation="handleCreateConversation" @create-conversation="handleCreateConversation"
@ -353,7 +354,7 @@ export default {
}, },
], ],
popupShow: false, popupShow: false,
chatHistoryList3: [ chatHistoryAI: [
// { // {
// "id": "", // "id": "",
// "conversation": [ // "conversation": [
@ -385,6 +386,7 @@ export default {
// ] // ]
// } // }
], ],
chatHistoryTeacher: [],
activeIndex: 0, activeIndex: 0,
commonQuestions: [ commonQuestions: [
"新生报到流程", "新生报到流程",
@ -467,6 +469,7 @@ export default {
methods: { methods: {
async handleLeftClick() { async handleLeftClick() {
await this.getChatHistoryList(); await this.getChatHistoryList();
await this.GetDialogueList_User();
this.handlePopupShow(); this.handlePopupShow();
}, },
@ -493,11 +496,12 @@ export default {
} }
}, },
async getChatHistoryList() { //
this.$u.api.GetConversationPage().then((res) => { async GetDialogueList_User() {
this.chatHistoryList3 = res.data; this.$u.api.GetDialogueList_UserApi().then((res) => {
if (this.chatHistoryList3.length > 0) { this.chatHistoryTeacher = res.data;
this.chatHistoryList3 = res.data.map((group) => { if (this.chatHistoryTeacher.length > 0) {
this.chatHistoryTeacher = res.data.map((group) => {
// conversation // conversation
return { return {
...group, ...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) 创建新会话 // 1) 创建新会话
// 2) 获取接收者信息 // 2) 获取接收者信息
@ -271,7 +289,10 @@ const store = new Vuex.Store({
// 清空消息列表,避免旧消息干扰 // 清空消息列表,避免旧消息干扰
commit("push_MsgList", []); commit("push_MsgList", []);
if (dialogueManagementId) { if (
dialogueManagementId &&
dialogueManagementId !== "00000000-0000-0000-0000-000000000000"
) {
// 有会话ID直接进入会话 // 有会话ID直接进入会话
commit("set_MsgUser", { ...user }); commit("set_MsgUser", { ...user });
uni.navigateTo({ uni.navigateTo({