init
xialiang 4 years ago
parent 2b41d52538
commit a32438e379

@ -55,6 +55,7 @@ function getTotalUnreadCount() {
// Vue.prototype.RongIMClientNum = totalUnreadCount
vueCom.$bus.emit('totalNoticeChange', totalUnreadCount);
console.log("获取未读总数成功", totalUnreadCount);
// this.notice_count = total_notice(totalUnreadCount);
});
@ -62,52 +63,6 @@ function getTotalUnreadCount() {
}
mineReadfile().then(value => {
RongIMClient = RongIMLib.init({
appkey: value.key,
});
RongIMClient.connect({ token: value.token })
.then((user) => {
console.log("连接成功, 用户 id 为:", user.id);
localStorage.setItem("user_info", JSON.stringify({ id: user.id }));
// 获取消息数量
getTotalUnreadCount()
// 添加事件监听
RongIMClient.watch({
// 监听消息通知
message(event) {
// 新接收到的消息内容
const message = event.message;
console.log("event", event);
getTotalUnreadCount()
if (event.message.type === 1) {
vueCom.$bus.emit("handelSendMessage", 1, event.message);
}
},
// 监听 IM 连接状态变化
status(event) {
// 链接监听失败回调
console.log('connection status:', event.status);
}
});
// 发送全局融云以便其他地方调取融云方法
Vue.prototype.RongIMClient = RongIMClient
})
.catch((error) => {
console.log("连接失败: ", error.code, error.msg);
});
}, reason => {
console.log(reason, 222)
})
Vue.use(Toast);
@ -216,6 +171,57 @@ function gotoPage(to, from, next) {
if (to.name === 'login') {
next({ replace: true, name: 'mainPlatform' });
} else {
mineReadfile().then(value => {
RongIMClient = RongIMLib.init({
appkey: value.key,
});
RongIMClient.connect({ token: value.token })
.then((user) => {
console.log("连接成功, 用户 id 为:", user.id);
localStorage.setItem("user_info", JSON.stringify({ id: user.id }));
// 获取消息数量
getTotalUnreadCount()
// 添加事件监听
RongIMClient.watch({
// 监听消息通知
message(event) {
// 新接收到的消息内容
const message = event.message;
console.log("event", event);
// 未读数计算
getTotalUnreadCount()
// 个人对话消息发送
if (event.message.type === 1) {
vueCom.$bus.emit("handelSendMessage", 1, event.message);
}
// 刷新会话列表
vueCom.$bus.emit('rongyunIMCGetList');
},
// 监听 IM 连接状态变化
status(event) {
// 链接监听失败回调
console.log('connection status:', event.status);
}
});
// 发送全局融云以便其他地方调取融云方法
Vue.prototype.RongIMClient = RongIMClient
})
.catch((error) => {
console.log("连接失败: ", error.code, error.msg);
});
}, reason => {
console.log(reason, 222)
})
next();
}
}

File diff suppressed because it is too large Load Diff

@ -20,12 +20,12 @@
<vue-scroll style="height: calc(100% - 40px)">
<ConversationItem
v-for="(item, index) in this.list"
:key="item.senderUserId"
:key="index"
:value="item"
:ind="index"
:nowIndex.sync="nowConversationIndex"
:targetId.sync="targetId"
:nowInfo.sync="nowInfo"
:v-if="showCard"
:nowTargetId.sync="nowTargetId"
:target_info="target_info"
:user_info="user_info"
>
</ConversationItem>
</vue-scroll>
@ -41,12 +41,15 @@ export default {
data() {
return {
list: [],
nowConversationIndex: 0,
nowTargetId: "",
targetId: "",
nowInfo: {
targetId: "",
type: 0,
},
// nowInfo: {
// targetId: "",
// type: 0,
// },
showCard: false,
target_info: {},
user_info: {},
};
},
components: {
@ -55,37 +58,51 @@ export default {
AInput: Input,
ConversationItem,
},
props: ["getTargetId"],
mounted() {
console.log(this, "this111111");
this.rongyunIMCGetList();
this.$bus.on("rongyunIMCGetList", this.rongyunIMCGetList);
this.$bus.on("setNowIndex", this.setNowIndex);
this.target_info = JSON.parse(localStorage.getItem("conversation_info"));
this.user_info = JSON.parse(localStorage.getItem("user_info"));
this.nowTargetId = this.target_info.targetId;
},
watch: {
// targetid
// targetId(e) {
// this.$bus.emit("getList", e, 1);
// },
nowInfo(e) {
// console.log(e, "nowInfo");
this.$bus.emit("getList", e.targetId, e.type);
},
// nowInfo(e) {
// console.log(e, "nowInfo");
// this.$bus.emit("getList", e.targetId, e.type);
// },
// list(e) {
// console.log(e, "e list");
// e[0] ? (this.nowTargetId = e[0].targetId) : "";
// },
},
methods: {
//
// setNowIndex(e) {
// this.nowTargetId = e;
// },
//
rongyunIMCGetList() {
this.list = [];
this.showCard = false;
this.RongIMClient.Conversation.getList({
count: 30,
startTime: 0,
order: 0,
}).then((conversationList) => {
this.list = conversationList;
console.log("获取会话列表成功~", conversationList);
});
})
.then((conversationList) => {
// this.list = conversationList;
console.log("获取会话列表成功~", conversationList);
return conversationList;
})
.then((result) => {
this.list = result;
});
},
},
};

@ -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 {

Loading…
Cancel
Save