feat(chat): 实现聊天功能接口集成和消息发送逻辑
This commit is contained in:
parent
cb4f5913e0
commit
31ba17200a
|
|
@ -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,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
this.messageList.push(message);
|
},
|
||||||
|
|
||||||
// 清空输入框
|
// 发送消息
|
||||||
this.inputValue = "";
|
sendMsgFn(message) {
|
||||||
|
SendMessage_PrivateApi(message)
|
||||||
// 滚动到底部
|
.then((res) => {
|
||||||
this.$nextTick(() => {
|
// 添加到消息列表
|
||||||
this.scrollToBottom();
|
this.messageList.push(message);
|
||||||
});
|
// 清空输入框
|
||||||
|
this.messageValue = "";
|
||||||
// TODO: 通过 WebSocket 发送消息
|
// 滚动到底部
|
||||||
// wsManager.send({
|
this.$nextTick(() => {
|
||||||
// type: 'message',
|
this.scrollToBottom();
|
||||||
// toUserId: this.userId,
|
});
|
||||||
// content: message.content
|
})
|
||||||
// })
|
.catch((error) => {
|
||||||
|
return msg.warning("发送失败");
|
||||||
console.log("[聊天详情] 发送消息:", message);
|
});
|
||||||
|
|
||||||
// 模拟对方回复
|
|
||||||
setTimeout(() => {
|
|
||||||
this.receiveMessage("收到,我马上处理");
|
|
||||||
}, 1000);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 接收消息
|
// 接收消息
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue