feat(chat): 实现聊天功能接口集成和消息发送逻辑

This commit is contained in:
yangzhe 2025-12-09 09:19:02 +08:00
parent cb4f5913e0
commit 31ba17200a
2 changed files with 55 additions and 38 deletions

View File

@ -218,6 +218,24 @@ const install = (Vue, vm) => {
// 获取教师列表(学生端-招办在线) // 获取教师列表(学生端-招办在线)
let GetTeacherListApi = (params = {}) => let GetTeacherListApi = (params = {}) =>
vm.$u.get("api/Dialogue/GetTeacherList", 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(因为vm就是this也即this.$u.api)下
vm.$u.api = { vm.$u.api = {
@ -278,6 +296,12 @@ const install = (Vue, vm) => {
GetUserApi, GetUserApi,
UpdateUserApi, UpdateUserApi,
GetTeacherListApi, GetTeacherListApi,
GetDialogueListApi,
AddDialogueApi,
SendMessage_PrivateApi,
GetChatHistoryDataApi,
GetReceiverUserInfoApi,
OverheadOneDialogueApi,
}; };
}; };

View File

@ -65,15 +65,15 @@
<view class="chat-footer"> <view class="chat-footer">
<view class="input-area"> <view class="input-area">
<input <input
v-model="inputValue" v-model="messageValue"
type="text" type="text"
class="chat-input" class="chat-input"
:focus="true" :focus="true"
placeholder="请输入内容" placeholder="请输入内容"
placeholder-style="color: #adadad;" placeholder-style="color: #adadad;"
@confirm="sendMessageFn" @confirm="handleSend"
/> />
<view class="send-btn" @click="sendMessageFn"> <view class="send-btn" @click="handleSend">
<image <image
class="send-icon" class="send-icon"
src="/static/common/images/icon_send.png" src="/static/common/images/icon_send.png"
@ -154,7 +154,7 @@ export default {
], ],
// //
inputValue: "", messageValue: "",
// //
scrollToView: "", scrollToView: "",
@ -196,48 +196,41 @@ export default {
uni.navigateBack(); uni.navigateBack();
}, },
// //
sendMessage() { handleSend() {
if (!this.inputValue.trim()) { if (!this.messageValue) {
uni.showToast({
title: "请输入消息内容",
icon: "none",
});
return; return;
} }
// //
const message = { const message = {
id: Date.now(), dialogueManagementId: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
content: this.inputValue, receiverId: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
isSelf: true, messageType: 0,
timestamp: this.formatTime(new Date()), message: this.messageValue,
filePath: "",
ip: "",
}; };
this.sendMsgFn(message);
},
//
sendMsgFn(message) {
SendMessage_PrivateApi(message)
.then((res) => {
// //
this.messageList.push(message); this.messageList.push(message);
// //
this.inputValue = ""; this.messageValue = "";
// //
this.$nextTick(() => { this.$nextTick(() => {
this.scrollToBottom(); this.scrollToBottom();
}); });
})
// TODO: WebSocket .catch((error) => {
// wsManager.send({ return msg.warning("发送失败");
// type: 'message', });
// toUserId: this.userId,
// content: message.content
// })
console.log("[聊天详情] 发送消息:", message);
//
setTimeout(() => {
this.receiveMessage("收到,我马上处理");
}, 1000);
}, },
// //