xbx #125
@ -193,6 +193,10 @@
|
|||||||
sendMessage() {//发送消息
|
sendMessage() {//发送消息
|
||||||
if (this.content.trim() != '') {
|
if (this.content.trim() != '') {
|
||||||
this.imService.sendPrivateTextMessage(this.friend.uuid, this.content);
|
this.imService.sendPrivateTextMessage(this.friend.uuid, this.content);
|
||||||
|
let that = this
|
||||||
|
setTimeout(function(){
|
||||||
|
that.scrollToBottom();
|
||||||
|
},500)
|
||||||
}
|
}
|
||||||
this.content = "";
|
this.content = "";
|
||||||
},
|
},
|
||||||
@ -322,7 +326,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.chatInterface .message-item{
|
.chatInterface .message-item{
|
||||||
max-height: 400rpx;
|
/* max-height: 400rpx; */
|
||||||
margin-top: 40rpx;
|
margin-top: 40rpx;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
@ -342,7 +346,7 @@
|
|||||||
.chatInterface .content{
|
.chatInterface .content{
|
||||||
font-size: 34rpx;
|
font-size: 34rpx;
|
||||||
line-height: 44rpx;
|
line-height: 44rpx;
|
||||||
max-height: 400rpx;
|
/* max-height: 400rpx; */
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: right;
|
justify-content: right;
|
||||||
@ -356,6 +360,7 @@
|
|||||||
.chatInterface .content .text-content{
|
.chatInterface .content .text-content{
|
||||||
padding: 16rpx;
|
padding: 16rpx;
|
||||||
border-radius: 12rpx;
|
border-radius: 12rpx;
|
||||||
|
max-width: 520rpx;
|
||||||
}
|
}
|
||||||
.chatInterface .content .pending{
|
.chatInterface .content .pending{
|
||||||
background: url("../images/pending.gif") no-repeat center;
|
background: url("../images/pending.gif") no-repeat center;
|
||||||
@ -528,5 +533,83 @@
|
|||||||
left: 50%;
|
left: 50%;
|
||||||
margin:-20rpx;
|
margin:-20rpx;
|
||||||
}
|
}
|
||||||
|
.chatInterface .avatar{
|
||||||
|
overflow: hidden;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
.chatInterface .avatar img{
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.chatInterface .content{
|
||||||
|
float: left;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.chatInterface .content span{
|
||||||
|
font-family: Source Han Sans CN;
|
||||||
|
letter-spacing: -0.41px;
|
||||||
|
color: #262628;
|
||||||
|
background: #efefef;
|
||||||
|
display: inline-block;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
.chatInterface .message-item.self{
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
.chatInterface .message-item.self .avatar{
|
||||||
|
margin-right: 0;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
.chatInterface .message-item.self .content{
|
||||||
|
text-align: right;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
.chatInterface .message-item.self .content span{
|
||||||
|
color: #ffffff;
|
||||||
|
background:#D02129;
|
||||||
|
word-break: break-all;
|
||||||
|
text-align: left;
|
||||||
|
max-width: 520rpx;
|
||||||
|
}
|
||||||
|
.chatInterface .action-box{
|
||||||
|
background: #FAFAFA;
|
||||||
|
display: flex;
|
||||||
|
align-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.chatInterface .message-input{
|
||||||
|
background: #efefef;
|
||||||
|
border: 0;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatInterface .send-message-btn{
|
||||||
|
flex-grow: 1;
|
||||||
|
text-align: center;
|
||||||
|
color: #95949A;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatInterface .member-layer{
|
||||||
|
width:100%;
|
||||||
|
height: 100%;
|
||||||
|
background: #FFFFFF;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
.member-layer .member{
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatInterface .group-icon{
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatInterface .gray{
|
||||||
|
color: gray!important;
|
||||||
|
text-decoration: none!important;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<image :src="item.avatar"></image>
|
<image :src="item.avatar"></image>
|
||||||
</view>
|
</view>
|
||||||
<view class="title">{{item.name}}</view>
|
<view class="title">{{item.name}}</view>
|
||||||
<view class="contentes">{{item.text}}</view>
|
<view class="contentes u-line-1">{{item.text}}</view>
|
||||||
<view class="times">{{item.time}}</view>
|
<view class="times">{{item.time}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -129,7 +129,8 @@
|
|||||||
onFriendListChange(onlineFriends) {
|
onFriendListChange(onlineFriends) {
|
||||||
//todo:比较垃圾的处理方式,因为Uniapp的基于MAP的双向绑定在H5端不稳定,H5端偶尔会抽风
|
//todo:比较垃圾的处理方式,因为Uniapp的基于MAP的双向绑定在H5端不稳定,H5端偶尔会抽风
|
||||||
// 下边这一行删掉,有时候页面可以更新,有时候不行,大家有优雅的方式,也欢迎跟我们沟通
|
// 下边这一行删掉,有时候页面可以更新,有时候不行,大家有优雅的方式,也欢迎跟我们沟通
|
||||||
this.information_dl = this.imService.friends;
|
console.log(onlineFriends,121212)
|
||||||
|
this.information_dl = onlineFriends;
|
||||||
|
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
},
|
},
|
||||||
|
@ -8,14 +8,15 @@
|
|||||||
import GoEasyIM from './goeasy-im-1.0.9';
|
import GoEasyIM from './goeasy-im-1.0.9';
|
||||||
import restApi from './restapi';
|
import restApi from './restapi';
|
||||||
|
|
||||||
function Friend(uuid, name, avatar) {
|
function Friend(uuid, name, avatar,time = "", text = "",date = "") {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
this.online = false;
|
this.online = false;
|
||||||
this.unReadMessage = 0;
|
this.unReadMessage = 0;
|
||||||
this.text = "";
|
this.text = text;
|
||||||
this.time = "";
|
this.time = time;
|
||||||
|
this.date = date
|
||||||
}
|
}
|
||||||
|
|
||||||
function Group(uuid, name, avatar) {
|
function Group(uuid, name, avatar) {
|
||||||
@ -40,6 +41,7 @@ function IMService() {
|
|||||||
this.currentUser = null;
|
this.currentUser = null;
|
||||||
//我的好友
|
//我的好友
|
||||||
this.friends = {};
|
this.friends = {};
|
||||||
|
this.friendsarr = [];
|
||||||
//我的群
|
//我的群
|
||||||
this.groups = {};
|
this.groups = {};
|
||||||
//私聊消息记录,map格式,每个好友对应一个数组
|
//私聊消息记录,map格式,每个好友对应一个数组
|
||||||
@ -74,7 +76,7 @@ IMService.prototype.login = function (uuid, name, avatar) {
|
|||||||
//初始化当前用户
|
//初始化当前用户
|
||||||
this.currentUser = new CurrentUser(uuid, name, avatar);
|
this.currentUser = new CurrentUser(uuid, name, avatar);
|
||||||
//初始化联系人信息,包括群
|
//初始化联系人信息,包括群
|
||||||
// this.initialContacts();
|
this.initialContacts();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -83,11 +85,56 @@ IMService.prototype.login = function (uuid, name, avatar) {
|
|||||||
IMService.prototype.initialContacts = function (friendList) {
|
IMService.prototype.initialContacts = function (friendList) {
|
||||||
//查询并初始化好友信息
|
//查询并初始化好友信息
|
||||||
// let friendList = restApi.findFriends(this.currentUser);
|
// let friendList = restApi.findFriends(this.currentUser);
|
||||||
|
let value = uni.getStorageSync('imlist');
|
||||||
|
if(value != undefined && !value){
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
value = JSON.parse(value)
|
||||||
|
let that = this
|
||||||
|
console.log(value)
|
||||||
|
for(let i of value){
|
||||||
|
const token = uni.getStorageSync('token');
|
||||||
|
console.log(token)
|
||||||
|
uni.request({
|
||||||
|
url:"https://dmmall.sdbairui.com/api/Specialci/getAtwillUserInfo",
|
||||||
|
data:{
|
||||||
|
userId:i[0]
|
||||||
|
},
|
||||||
|
method:"POST",
|
||||||
|
header:{
|
||||||
|
"Authorization" : 'Bearer' + " " + token
|
||||||
|
},
|
||||||
|
success(res){
|
||||||
|
console.log(res)
|
||||||
|
that.friends[i[0]] = new Friend(res.data.data.member_id, res.data.data.member_nickname, res.data.data.member_avatar,i[1],i[2]);
|
||||||
|
console.log(that.friends)
|
||||||
|
let sorts = function (friends){
|
||||||
|
let paixu = function (a,b){
|
||||||
|
if(a.date > b.date){
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
friends.sort(paixu)
|
||||||
|
|
||||||
|
}
|
||||||
|
that.friendsarr = []
|
||||||
|
for(let i in that.friends){
|
||||||
|
console.log(i)
|
||||||
|
that.friendsarr.push(that.friends[i])
|
||||||
|
}
|
||||||
|
sorts(that.friendsarr)
|
||||||
|
that.onFriendListChange(that.friends);
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
//将用户列表初始化为一个map,便于后续根据friendId得到friend
|
//将用户列表初始化为一个map,便于后续根据friendId得到friend
|
||||||
friendList.map(friend => {
|
// friendList.map(friend => {
|
||||||
this.friends[friend.uuid] = new Friend(friend.uuid, friend.name, friend.avatar);
|
// this.friends[friend.uuid] = new Friend(friend.uuid, friend.name, friend.avatar);
|
||||||
});
|
// });
|
||||||
|
|
||||||
//查询并初始化与自己相关的群信息
|
//查询并初始化与自己相关的群信息
|
||||||
// let groupList = restApi.findGroups(this.currentUser);
|
// let groupList = restApi.findGroups(this.currentUser);
|
||||||
@ -207,6 +254,19 @@ IMService.prototype.initialIMListeners = function () {
|
|||||||
let friend = this.friends[message.senderId];
|
let friend = this.friends[message.senderId];
|
||||||
console.log(friend)
|
console.log(friend)
|
||||||
// return ;
|
// return ;
|
||||||
|
let sorts = function (friends){
|
||||||
|
let paixu = function (a,b){
|
||||||
|
if(a.date > b.date){
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
friends.sort(paixu)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
let that = this
|
let that = this
|
||||||
if(!friend && friend == undefined){
|
if(!friend && friend == undefined){
|
||||||
const token = uni.getStorageSync('token');
|
const token = uni.getStorageSync('token');
|
||||||
@ -228,9 +288,24 @@ IMService.prototype.initialIMListeners = function () {
|
|||||||
friend.unReadMessage++;
|
friend.unReadMessage++;
|
||||||
friend.text = message.type != "text" ? "其他消息" : message.payload.text
|
friend.text = message.type != "text" ? "其他消息" : message.payload.text
|
||||||
let time = new Date(message.timestamp)
|
let time = new Date(message.timestamp)
|
||||||
|
friend.date = message.timestamp
|
||||||
friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()
|
friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()
|
||||||
that.onFriendListChange(that.friends);
|
|
||||||
console.log(that.friends)
|
console.log(that.friends)
|
||||||
|
that.friendsarr = []
|
||||||
|
for(let i in that.friends){
|
||||||
|
console.log(i)
|
||||||
|
that.friendsarr.push(that.friends[i])
|
||||||
|
}
|
||||||
|
sorts(that.friendsarr)
|
||||||
|
let arr = []
|
||||||
|
for(let i in that.friends){
|
||||||
|
arr.push([that.friends[i].uuid,that.friends[i].time,that.friends[i].text,that.friends[i].date])
|
||||||
|
}
|
||||||
|
console.log(arr)
|
||||||
|
uni.setStorageSync('imlist',JSON.stringify(arr))
|
||||||
|
|
||||||
|
that.onFriendListChange(that.friends);
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
@ -238,11 +313,29 @@ IMService.prototype.initialIMListeners = function () {
|
|||||||
friend.unReadMessage++;
|
friend.unReadMessage++;
|
||||||
friend.text = message.type != "text" ? "其他消息" : message.payload.text
|
friend.text = message.type != "text" ? "其他消息" : message.payload.text
|
||||||
let time = new Date(message.timestamp)
|
let time = new Date(message.timestamp)
|
||||||
|
friend.date = message.timestamp
|
||||||
friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()
|
friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()
|
||||||
this.onFriendListChange(this.friends);
|
|
||||||
console.log(this.friends)
|
console.log(this.friends)
|
||||||
}
|
that.friendsarr = []
|
||||||
|
for(let i in this.friends){
|
||||||
|
that.friendsarr.push(this.friends[i])
|
||||||
|
}
|
||||||
|
sorts(that.friendsarr)
|
||||||
|
let arr = []
|
||||||
|
for(let i in that.friends){
|
||||||
|
arr.push([that.friends[i].uuid,that.friends[i].time,that.friends[i].text,that.friends[i].date])
|
||||||
|
}
|
||||||
|
console.log(arr)
|
||||||
|
uni.setStorageSync('imlist',JSON.stringify(arr))
|
||||||
|
this.onFriendListChange(this.friends);
|
||||||
|
|
||||||
|
}
|
||||||
|
// let value = uni.getStorageSync('imlist');
|
||||||
|
// value = JSON.parse(value)
|
||||||
|
// if(value.indexOf(message.senderId) == -1){
|
||||||
|
// value.unshift(message.senderId)
|
||||||
|
// }
|
||||||
|
// uni.setStorageSync('imlist',JSON.stringify(value))
|
||||||
|
|
||||||
}
|
}
|
||||||
//更新私聊消息记录
|
//更新私聊消息记录
|
||||||
|
Loading…
Reference in New Issue
Block a user