|
|
|
@ -1,98 +1,94 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div class="message-list">
|
|
|
|
|
<h2 class="title">
|
|
|
|
|
<a-avatar :size="34" :src="avatar" style="background-color: #f59a23">
|
|
|
|
|
<div
|
|
|
|
|
v-if="!isMessage"
|
|
|
|
|
style="background-color: #f2f2f2; height: 100%; overfllow: hidden"
|
|
|
|
|
></div>
|
|
|
|
|
<div v-if="isMessage">
|
|
|
|
|
<h2 class="title">
|
|
|
|
|
<a-avatar :size="34" :src="avatar" style="background-color: #f59a23">
|
|
|
|
|
{{ name }}
|
|
|
|
|
</a-avatar>
|
|
|
|
|
{{ name }}
|
|
|
|
|
</a-avatar>
|
|
|
|
|
{{ name }}
|
|
|
|
|
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="type == 1"
|
|
|
|
|
size="small"
|
|
|
|
|
icon="file-search"
|
|
|
|
|
type="link"
|
|
|
|
|
class="more-btn"
|
|
|
|
|
style="float: right; margin-top: 3px"
|
|
|
|
|
@click="drawerVisible('Record')"
|
|
|
|
|
/>
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="type == 3"
|
|
|
|
|
size="small"
|
|
|
|
|
icon="file-search"
|
|
|
|
|
type="link"
|
|
|
|
|
class="more-btn"
|
|
|
|
|
style="float: right; margin-top: 3px"
|
|
|
|
|
@click="drawerVisible('GroupChatRecord')"
|
|
|
|
|
/>
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="type == 3"
|
|
|
|
|
icon="setting"
|
|
|
|
|
size="small"
|
|
|
|
|
type="link"
|
|
|
|
|
style="float: right; margin-top: 3px"
|
|
|
|
|
@click="drawerVisible('GroupSetting')"
|
|
|
|
|
/>
|
|
|
|
|
</h2>
|
|
|
|
|
|
|
|
|
|
<div class="message-item" style="overflow-y: scroll" ref="msgList">
|
|
|
|
|
<!-- <MessagePrivate :messageResult="messageResult" /> -->
|
|
|
|
|
<!-- 聊天窗口 -->
|
|
|
|
|
<ul class="msg-list">
|
|
|
|
|
<!-- <MessagePrivate
|
|
|
|
|
v-for="(MsgObj, index) in messageResult"
|
|
|
|
|
:key="index"
|
|
|
|
|
:index="index"
|
|
|
|
|
:MsgObj="MsgObj"
|
|
|
|
|
>
|
|
|
|
|
</MessagePrivate> -->
|
|
|
|
|
<Message :messageResult="messageResult" :type="type" />
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="message-tools">
|
|
|
|
|
<a-button icon="search" size="small" type="link" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<InputTextArea
|
|
|
|
|
ref="TextArea"
|
|
|
|
|
style="border: 0"
|
|
|
|
|
:rows="3"
|
|
|
|
|
class="textarea"
|
|
|
|
|
v-model="textdata"
|
|
|
|
|
/>
|
|
|
|
|
<span>
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="type == 1"
|
|
|
|
|
size="small"
|
|
|
|
|
icon="file-search"
|
|
|
|
|
type="link"
|
|
|
|
|
class="more-btn"
|
|
|
|
|
@click="handelSendMessage(0, {})"
|
|
|
|
|
style="float: right; margin-top: 3px"
|
|
|
|
|
>发送</a-button
|
|
|
|
|
>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
@click="drawerVisible('Record')"
|
|
|
|
|
/>
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="type == 3"
|
|
|
|
|
size="small"
|
|
|
|
|
icon="file-search"
|
|
|
|
|
type="link"
|
|
|
|
|
class="more-btn"
|
|
|
|
|
style="float: right; margin-top: 3px"
|
|
|
|
|
@click="drawerVisible('GroupChatRecord')"
|
|
|
|
|
/>
|
|
|
|
|
<a-button
|
|
|
|
|
v-if="type == 3"
|
|
|
|
|
icon="setting"
|
|
|
|
|
size="small"
|
|
|
|
|
type="link"
|
|
|
|
|
style="float: right; margin-top: 3px"
|
|
|
|
|
@click="drawerVisible('GroupSetting')"
|
|
|
|
|
/>
|
|
|
|
|
</h2>
|
|
|
|
|
|
|
|
|
|
<div class="message-item" style="overflow-y: scroll" ref="msgList">
|
|
|
|
|
<ul class="msg-list">
|
|
|
|
|
<Message :messageResult="messageResult" :type="type" />
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 抽屉 -->
|
|
|
|
|
<a-drawer
|
|
|
|
|
placement="right"
|
|
|
|
|
:closable="true"
|
|
|
|
|
:visible="visible"
|
|
|
|
|
:get-container="false"
|
|
|
|
|
:wrap-style="{ position: 'absolute' }"
|
|
|
|
|
@close="onClose"
|
|
|
|
|
width="350"
|
|
|
|
|
>
|
|
|
|
|
<Record v-if="drawerType == 'Record'" />
|
|
|
|
|
<GroupSetting v-if="drawerType == 'GroupSetting'" />
|
|
|
|
|
<GroupChatRecord v-if="drawerType == 'GroupChatRecord'" />
|
|
|
|
|
</a-drawer>
|
|
|
|
|
<div class="message-tools">
|
|
|
|
|
<a-button icon="search" size="small" type="link" />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<InputTextArea
|
|
|
|
|
ref="TextArea"
|
|
|
|
|
style="border: 0"
|
|
|
|
|
:rows="3"
|
|
|
|
|
class="textarea"
|
|
|
|
|
v-model="textdata"
|
|
|
|
|
/>
|
|
|
|
|
<span>
|
|
|
|
|
<a-button
|
|
|
|
|
size="small"
|
|
|
|
|
type="link"
|
|
|
|
|
class="more-btn"
|
|
|
|
|
@click="handelSendMessage(0, {})"
|
|
|
|
|
style="float: right; margin-top: 3px"
|
|
|
|
|
>发送</a-button
|
|
|
|
|
>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 抽屉 -->
|
|
|
|
|
<a-drawer
|
|
|
|
|
placement="right"
|
|
|
|
|
:closable="true"
|
|
|
|
|
:visible="visible"
|
|
|
|
|
:get-container="false"
|
|
|
|
|
:wrap-style="{ position: 'absolute' }"
|
|
|
|
|
@close="onClose"
|
|
|
|
|
width="350"
|
|
|
|
|
>
|
|
|
|
|
<Record v-if="drawerType == 'Record'" />
|
|
|
|
|
<GroupSetting v-if="drawerType == 'GroupSetting'" />
|
|
|
|
|
<GroupChatRecord v-if="drawerType == 'GroupChatRecord'" />
|
|
|
|
|
</a-drawer>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { Avatar, Button, Input, Drawer } from "ant-design-vue";
|
|
|
|
|
import MessagePrivate from "./MessagePrivate.vue";
|
|
|
|
|
import Message from "./Message.vue";
|
|
|
|
|
import GroupChatRecord from "./GroupChatRecord.vue";
|
|
|
|
|
import GroupSetting from "./GroupSetting.vue";
|
|
|
|
@ -103,6 +99,7 @@ export default {
|
|
|
|
|
return {
|
|
|
|
|
name: "",
|
|
|
|
|
avatar: "",
|
|
|
|
|
message: "message",
|
|
|
|
|
data: {},
|
|
|
|
|
visible: false,
|
|
|
|
|
messageResult: [],
|
|
|
|
@ -111,6 +108,9 @@ export default {
|
|
|
|
|
textdata: "",
|
|
|
|
|
targetid: "",
|
|
|
|
|
type: 0,
|
|
|
|
|
isMessage: false,
|
|
|
|
|
user_info: {},
|
|
|
|
|
target_info: {},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
@ -118,7 +118,6 @@ export default {
|
|
|
|
|
InputTextArea: Input.TextArea,
|
|
|
|
|
AButton: Button,
|
|
|
|
|
AAvatar: Avatar,
|
|
|
|
|
MessagePrivate,
|
|
|
|
|
Record,
|
|
|
|
|
Message,
|
|
|
|
|
GroupChatRecord,
|
|
|
|
@ -126,69 +125,73 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
// 第一次进入获取数据
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
// 本地存储拿数据渲染信息
|
|
|
|
|
const conversation_info = JSON.parse(
|
|
|
|
|
localStorage.getItem("conversation_info")
|
|
|
|
|
);
|
|
|
|
|
this.name = conversation_info.person_name;
|
|
|
|
|
this.avatar = conversation_info.avatar;
|
|
|
|
|
this.type = conversation_info.type;
|
|
|
|
|
this.targetid = conversation_info.targetId;
|
|
|
|
|
// this.getList(conversation_info.targetId, conversation_info.type);
|
|
|
|
|
console.log(conversation_info, 999999);
|
|
|
|
|
}, 1000);
|
|
|
|
|
// 本地存储拿数据渲染信息
|
|
|
|
|
this.user_info = JSON.parse(localStorage.getItem("user_info"));
|
|
|
|
|
this.target_info = JSON.parse(localStorage.getItem("conversation_info"));
|
|
|
|
|
|
|
|
|
|
if (this.target_info.user_id == this.user_info.id) {
|
|
|
|
|
this.isMessage = true;
|
|
|
|
|
this.getList(this.target_info.targetId, this.target_info.type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const name =
|
|
|
|
|
this.target_info.type == 1
|
|
|
|
|
? this.target_info.person_name
|
|
|
|
|
: this.target_info.group_name;
|
|
|
|
|
this.setNowMessageInfo(
|
|
|
|
|
name,
|
|
|
|
|
this.target_info.avatar,
|
|
|
|
|
this.target_info.type,
|
|
|
|
|
this.target_info.targetId
|
|
|
|
|
);
|
|
|
|
|
/* ============================================================= */
|
|
|
|
|
// 派发获取列表事件
|
|
|
|
|
this.$bus.on("getList", this.getList);
|
|
|
|
|
// 派发滚动条到底部事件
|
|
|
|
|
this.$bus.on("_scroll", this._scroll);
|
|
|
|
|
// 派发发送消息事件
|
|
|
|
|
this.$bus.on("handelSendMessage", this.handelSendMessage);
|
|
|
|
|
console.log(this.type, "messageResult");
|
|
|
|
|
this.$refs.TextArea.focus();
|
|
|
|
|
//聊天窗口焦点(不好使)
|
|
|
|
|
// this.$refs.TextArea.focus();
|
|
|
|
|
//聊天信息获取
|
|
|
|
|
this.$bus.on("setNowMessageInfo", this.setNowMessageInfo);
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
// 修改当前聊天框显示
|
|
|
|
|
setNowMessageInfo(name, avatar, type, targetId) {
|
|
|
|
|
console.log(name, avatar, type, targetId, "5555555555555555555555");
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.avatar = avatar;
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.targetId = targetId;
|
|
|
|
|
},
|
|
|
|
|
// 渲染 并 发送 ==> 信息 type= 自己发送,
|
|
|
|
|
handelSendMessage(sendType = 0, message = {}) {
|
|
|
|
|
const user_info = JSON.parse(localStorage.getItem("user_info"));
|
|
|
|
|
const conversation_info = JSON.parse(
|
|
|
|
|
localStorage.getItem("conversation_info")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (sendType == 0) {
|
|
|
|
|
message = {
|
|
|
|
|
content: { content: this.textdata },
|
|
|
|
|
expansion: {
|
|
|
|
|
person_name: user_info.name,
|
|
|
|
|
person_avatar: user_info.avatar,
|
|
|
|
|
target_name: conversation_info.person_name,
|
|
|
|
|
target_avatar: conversation_info.avatar,
|
|
|
|
|
},
|
|
|
|
|
type: this.type,
|
|
|
|
|
|
|
|
|
|
type: this.target_info.type,
|
|
|
|
|
messageType: "RC:TxtMsg",
|
|
|
|
|
senderUserId: user_info.id,
|
|
|
|
|
targetId: this.targetid,
|
|
|
|
|
targetId: this.target_info.targetId,
|
|
|
|
|
sentTime: new Date().getTime(),
|
|
|
|
|
};
|
|
|
|
|
// this.rongYunSend(
|
|
|
|
|
// conversation_info.targetId,
|
|
|
|
|
// this.textdata,
|
|
|
|
|
// this.type,
|
|
|
|
|
// "RC:TxtMsg"
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
console.log(message, "message 未发送");
|
|
|
|
|
this.rongYunSend(message);
|
|
|
|
|
}
|
|
|
|
|
console.log(message, sendType, "handelSendMessage");
|
|
|
|
|
// push进数组数据
|
|
|
|
|
this.messageResult.push(message);
|
|
|
|
|
// console.log(conversation_info, "conversation_info");
|
|
|
|
|
// console.log(this.messageResult, "messageresult");
|
|
|
|
|
},
|
|
|
|
|
// 发送消息
|
|
|
|
|
// rongYunSend(targetId, content, type, messageType) {
|
|
|
|
|
rongYunSend(message) {
|
|
|
|
|
const _this = this;
|
|
|
|
|
console.log(message, "send target Id");
|
|
|
|
|
// console.log(message, "send target Id");
|
|
|
|
|
var conversation = this.RongIMClient.Conversation.get({
|
|
|
|
|
targetId: message.targetId,
|
|
|
|
|
type: message.type,
|
|
|
|
@ -209,6 +212,7 @@ export default {
|
|
|
|
|
console.log("发送文字消息成功a", message);
|
|
|
|
|
this.saveMessage(message);
|
|
|
|
|
_this.$bus.emit("rongyunIMCGetList");
|
|
|
|
|
_this.$bus.$emit("setNowIndex", 0);
|
|
|
|
|
return message;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
@ -258,15 +262,10 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
// 获取聊天列表
|
|
|
|
|
getList(targetId, type) {
|
|
|
|
|
console.log(targetId, type, "getList");
|
|
|
|
|
console.log(targetId, type, "getList111a");
|
|
|
|
|
this.messageResult = [];
|
|
|
|
|
const conversation_info = JSON.parse(
|
|
|
|
|
localStorage.getItem("conversation_info")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.name = conversation_info.person_name;
|
|
|
|
|
this.avatar = conversation_info.avatar;
|
|
|
|
|
this.type = conversation_info.type;
|
|
|
|
|
this.type = this.target_info.type;
|
|
|
|
|
|
|
|
|
|
// console.log(targetId, type, "targetId222");
|
|
|
|
|
var conversation = this.RongIMClient.Conversation.get({
|
|
|
|
@ -279,7 +278,7 @@ export default {
|
|
|
|
|
};
|
|
|
|
|
conversation.getMessages(option).then((result) => {
|
|
|
|
|
const res = result.list;
|
|
|
|
|
console.log(result.list, "msgObj result.list");
|
|
|
|
|
// console.log(result.list, "msgObj result.list");
|
|
|
|
|
this.messageResult = result.list;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
@ -298,6 +297,7 @@ export default {
|
|
|
|
|
background-color: #f2f2f2;
|
|
|
|
|
width: 70%;
|
|
|
|
|
position: relative;
|
|
|
|
|
height: 100%;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
float: left;
|
|
|
|
|
.title {
|
|
|
|
|