From 31ba17200a7b8f3128a75e2f4ee3ff164fe2f0d7 Mon Sep 17 00:00:00 2001 From: yangzhe Date: Tue, 9 Dec 2025 09:19:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat):=20=E5=AE=9E=E7=8E=B0=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E5=8A=9F=E8=83=BD=E6=8E=A5=E5=8F=A3=E9=9B=86=E6=88=90?= =?UTF-8?q?=E5=92=8C=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/http.api.js | 24 +++++++++++++++ pages/chat/index.vue | 69 ++++++++++++++++++++------------------------ 2 files changed, 55 insertions(+), 38 deletions(-) diff --git a/common/http.api.js b/common/http.api.js index f2a3beb..01596bd 100644 --- a/common/http.api.js +++ b/common/http.api.js @@ -218,6 +218,24 @@ const install = (Vue, vm) => { // 获取教师列表(学生端-招办在线) let GetTeacherListApi = (params = {}) => vm.$u.get("api/Dialogue/GetTeacherList", params); + // 获取会话列表 + let GetDialogueListApi = (params = {}) => + vm.$u.get("api/Dialogue/GetDialogueList", params); + // 创建会话 + let AddDialogueApi = (params = {}) => + vm.$u.post("api/Dialogue/AddDialogue", params); + // 发送私聊消息 + let SendMessage_PrivateApi = (params = {}) => + vm.$u.post("api/Dialogue/SendAPrivateChatMessage", params); + // 获取会话聊天记录 + let GetChatHistoryDataApi = (params = {}) => + vm.$u.get("api/Dialogue/GetChatHistoryData", params); + // 获取消息接收方用户信息 + let GetReceiverUserInfoApi = (params = {}) => + vm.$u.get("api/Dialogue/GetReceiverUserInfo", params); + // 置顶一个会话 + let OverheadOneDialogueApi = (params = {}) => + vm.$u.post("api/Dialogue/OverheadOneDialogue", params); // 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下 vm.$u.api = { @@ -278,6 +296,12 @@ const install = (Vue, vm) => { GetUserApi, UpdateUserApi, GetTeacherListApi, + GetDialogueListApi, + AddDialogueApi, + SendMessage_PrivateApi, + GetChatHistoryDataApi, + GetReceiverUserInfoApi, + OverheadOneDialogueApi, }; }; diff --git a/pages/chat/index.vue b/pages/chat/index.vue index 1bac42c..f6c238f 100644 --- a/pages/chat/index.vue +++ b/pages/chat/index.vue @@ -65,15 +65,15 @@ - + { - this.scrollToBottom(); - }); - - // TODO: 通过 WebSocket 发送消息 - // wsManager.send({ - // type: 'message', - // toUserId: this.userId, - // content: message.content - // }) - - console.log("[聊天详情] 发送消息:", message); - - // 模拟对方回复 - setTimeout(() => { - this.receiveMessage("收到,我马上处理"); - }, 1000); + // 发送消息 + sendMsgFn(message) { + SendMessage_PrivateApi(message) + .then((res) => { + // 添加到消息列表 + this.messageList.push(message); + // 清空输入框 + this.messageValue = ""; + // 滚动到底部 + this.$nextTick(() => { + this.scrollToBottom(); + }); + }) + .catch((error) => { + return msg.warning("发送失败"); + }); }, // 接收消息