feat(chat): 实现聊天功能接口集成和消息发送逻辑
This commit is contained in:
parent
cb4f5913e0
commit
31ba17200a
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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("发送失败");
|
||||
});
|
||||
},
|
||||
|
||||
// 接收消息
|
||||
|
|
|
|||
Loading…
Reference in New Issue