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 = {}) =>
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,
};
};

View File

@ -65,15 +65,15 @@
<view class="chat-footer">
<view class="input-area">
<input
v-model="inputValue"
v-model="messageValue"
type="text"
class="chat-input"
:focus="true"
placeholder="请输入内容"
placeholder-style="color: #adadad;"
@confirm="sendMessageFn"
@confirm="handleSend"
/>
<view class="send-btn" @click="sendMessageFn">
<view class="send-btn" @click="handleSend">
<image
class="send-icon"
src="/static/common/images/icon_send.png"
@ -154,7 +154,7 @@ export default {
],
//
inputValue: "",
messageValue: "",
//
scrollToView: "",
@ -196,48 +196,41 @@ export default {
uni.navigateBack();
},
//
sendMessage() {
if (!this.inputValue.trim()) {
uni.showToast({
title: "请输入消息内容",
icon: "none",
});
//
handleSend() {
if (!this.messageValue) {
return;
}
//
const message = {
id: Date.now(),
content: this.inputValue,
isSelf: true,
timestamp: this.formatTime(new Date()),
dialogueManagementId: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
receiverId: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
messageType: 0,
message: this.messageValue,
filePath: "",
ip: "",
};
//
this.messageList.push(message);
this.sendMsgFn(message);
},
//
this.inputValue = "";
//
this.$nextTick(() => {
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("发送失败");
});
},
//