Commit 47589bcc by 施宇

1111

parent ab06d6e9
......@@ -151,7 +151,7 @@
</div> -->
</div>
<div class="bottom clr">
<div class="gt_div fl btn btn_yellow" imid="{{item.im_username}}" userid="{{item.user_id}}">
<div class="gt_div fl btn btn_yellow" imid="{{item.im_username}}" userid="{{item.user_id}}" avatar="{{item.avatar}}">
<span class="icon iconfont iconjuxing7 va-m"></span>
在线沟通
</div>
......
......@@ -10,11 +10,11 @@ $(function () {
name: "",
id: "",
init: function () {
this.ieFun();
this.getUserInfo();
// this.ieFun();
this.connection();
this.connListen();
this.bindFunction();
this.getUserInfo();
},
getUserInfo: function () { //获取用户的基本信息
var self = this;
......@@ -25,14 +25,15 @@ $(function () {
self.img = res.data.avatar;
self.name = res.data.company_name;
self.id = res.data.user_id + '';
self.login(res.data.im_username, res.data.im_password);
self.getHistoryUsers(res.data.im_username, res.data.im_password);
} else {
console.log('获取用户名失败');
layer.msg('聊天系统出错');
}
}, true, false)
},
getHistoryUsers: function () {
getHistoryUsers: function (name, password) {
//获取用户聊天的成员记录
var self = this;
IcController.getData(apis.listrecord, 'GET', {
......@@ -40,25 +41,27 @@ $(function () {
}, function (res) {
if (res.errcode === 0) {
self.rendChatSection(res.data);
self.singleChat();
self.login(name, password);
} else {
layer.msg('获取历史纪录失败');
}
});
},
addChatMember: function (id) {
IcController.getData(apis.addrecord, 'GET', {
"token": Util.getCookie('token') || '',
"user_id": id
}, function (res) {
if (res.errcode === 0) {
console.log(id)
// IcController.getData(apis.addrecord, 'GET', {
// "token": Util.getCookie('token') || '',
// "user_id": id
// }, function (res) {
// if (res.errcode === 0) {
} else {
console.log('添加聊天成员失败')
}
},false);
// } else {
// console.log('添加聊天成员失败')
// }
// },false);
},
rendChatSection: function (data) {
console.log('获取成员')
this.addUser({}, true);
for (var i = 0; i < data.length; i++) {
this.addUser(data[i])
......@@ -70,6 +73,9 @@ $(function () {
} else {
Util.delCookie('template', cookieHostname);
this.addUser({}, false, true);
var html = $(".notice_classify[userid=" + this.templateObj.userId + "]").clone();
$(".notice_classify[userid=" + this.templateObj.userId + "]").remove();
$(".notice_classify[userid=" + this.defaultName + "]").after(html);
$(".notice_classify[userid=" + this.templateObj.userId + "]").attr('isTemplate', true); //先获取历史纪录再发送模板,否则可能出现发送的消息显示两条
$(".notice_classify[userid=" + this.templateObj.userId + "]").click();
......@@ -84,9 +90,10 @@ $(function () {
img = dist + "/images/default.jpg";
} else {
if (isFirst) {
console.log(this.templateObj)
id = this.templateObj.userId;
name = this.templateObj.userName;
img = this.templateObj.img || (dist + "/images/default.jpg")
img = this.templateObj.userImg || (dist + "/images/default.jpg")
} else {
id = obj.im_username;
name = obj.company_name;
......@@ -98,7 +105,7 @@ $(function () {
if (userLen) { //用户存在
return;
} else { //用户不存在
var lefthtml = '<div class="notice_classify" userid="' + id + '">' + this.userHtml(0, {
var lefthtml = '<div class="notice_classify" userid="' + id + '" firstClick="true">' + this.userHtml(0, {
name: name,
id: id,
img: img
......@@ -309,10 +316,10 @@ $(function () {
} else if (type == 2) {
regContent = '[图片]';
htmlStr = {
message:'<img src ="' + message.url + '" class="edit_img"/>',
message: '<img src ="' + message.url + '" class="edit_img"/>',
name: message.name,
img: message.img,
id: message.id
id: message.id
}
} else {
var data = message.message;
......@@ -326,10 +333,10 @@ $(function () {
}
};
htmlStr = {
message:emojiTxt,
message: emojiTxt,
name: message.name,
img: message.img,
id: message.id
id: message.id
}
}
var len = $('.notice_classify').length;
......@@ -350,23 +357,29 @@ $(function () {
if (!len) {
//新用户
var userStr = '<div class="notice_classify active" userid="' + message.from + '">' +
var userStr = '<div class="notice_classify active" userid="' + message.from + '" firstClick="true" newMember="true">' +
self.userHtml(0, message, regContent) + '</div>';
var messageStr = '<div class="chat_item active" id="' + message.from + '">' +
messageSigleStr + '</div>'
$('.notice_left_content').append(userStr);
$(".notice_classify[userid=" + this.defaultName + "]").after(userStr);
// $('.notice_left_content').append(userStr);
$('.chat_item_content').append(messageStr)
} else {
$('.notice_classify').each(function (index) {
var userId = $(this).attr('userid');
var isNowChat = $('.notice_classify').eq(index).hasClass('active');
var firstClick = $(this).attr('firstClick');
if (userId == message.from) {
//已有用户
if (isNowChat) {
//当前用户
$(this).html(self.userHtml(0, message, regContent));
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate));
if (Util.getCookie('templateBoolean')) {
Util.delCookie('templateBoolean', cookieHostname);
} else {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate));
}
var contentHeight = $('#' + userId).find('.notice_item_content')
.height();
$('#' + userId).find('.notice_list').scrollTop(contentHeight);
......@@ -375,8 +388,14 @@ $(function () {
//非当前用户
var num = Number($(this).find('.num').text());
$(this).html(self.userHtml(num + 1, message, regContent));
// $('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
// htmlStr, isTemplate));
var html = $(this).clone();
$(this).remove();
$(".notice_classify[userid=" + this.defaultName + "]").after(html);
if (!firstClick) {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate));
}
}
return false;
......@@ -384,12 +403,12 @@ $(function () {
if (index == len - 1) {
//新用户
var userStr = '<div class="notice_classify" userid="' +
message.from + '">' +
message.from + '" newMember="true">' +
self.userHtml(1, message, regContent) + '</div>';
var messageStr = '<div class="chat_item" id="' +
message.from + '">' +
messageSigleStr + '</div>'
$('.notice_left_content').append(userStr);
$(".notice_classify[userid=" + this.defaultName + "]").after(userStr)
$('.chat_item_content').append(messageStr)
}
}
......@@ -403,7 +422,7 @@ $(function () {
onOpened: function (message) {
console.log('登入成功')
self.isLoginSuccess = true;
self.getHistoryUsers();
self.singleChat();
},
onTextMessage: function (message) {
self.receiveData(1, {
......@@ -430,14 +449,14 @@ $(function () {
id: message.ext.id,
img: message.ext.img,
from: message.from,
type:message.ext.type,
price:message.ext.price,
goodImage:message.ext.goodImage,
brand:message.ext.brand,
hq:message.ext.hq,
num:message.ext.num,
hq:message.ext.hq,
time:message.ext.time
type: message.ext.type,
price: message.ext.price,
goodImage: message.ext.goodImage,
brand: message.ext.brand,
hq: message.ext.hq,
num: message.ext.num,
hq: message.ext.hq,
time: message.ext.time
}, true);
self.addChatMember(message.ext.id)
}, //收到命令消息;
......@@ -535,6 +554,7 @@ $(function () {
this.conn.send(msg.body);
},
sendCmd: function (templateObj) {
console.log('发送模板')
var self = this;
var userId = $('.notice_left ').find('.active').attr('userid');
var id = this.conn.getUniqueId();
......@@ -657,17 +677,35 @@ $(function () {
$('.notice_left').on('click', '.notice_classify', function () {
var id = $(this).attr('userid');
var isTemplate = $(this).attr('isTemplate');
var firstClick = $(this).attr('firstClick');
var newMember = $(this).attr('newMember');
$('#' + id).addClass('active').siblings('.chat_item').removeClass('active');
$(this).find('.num').remove();
$(this).addClass('active').siblings('.notice_classify').removeClass('active');
if (isTemplate) {
$(this).removeAttr('isTemplate');
}
if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id, isTemplate)
$(this).removeAttr('firstClick');
if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id, isTemplate)
} else {
layer.msg('聊天系统出错');
return;
}
} else {
layer.msg('聊天系统出错');
return;
var contentHeight = $('#' + id).find('.notice_item_content').height();
$('#' + id).find('.notice_list').scrollTop(contentHeight);
if (newMember) {
return
}
if (firstClick) {
$(this).removeAttr('firstClick');
if (self.isLoginSuccess) { //登入成功 获取聊天记录
self.getHistoryData(id)
} else {
layer.msg('聊天系统出错');
return;
}
}
}
});
$('.notice_right ').on('click', '.edit_img', function () {
......
......@@ -81,6 +81,7 @@ $(function () {
self.isClick = false;
var userId = $(this).attr('imid'),
id = $(this).attr('userid'),
userImg = $(this).attr('avatar'),
parent = $(this).parents('.bj_item'),
type = parent.find('.goods_name').text(),
price = parent.find('.price').text(),
......@@ -103,8 +104,10 @@ $(function () {
time: time,
goodImage: img,
userName: name,
targetId:id
targetId:id,
userImg:userImg
};
Util.setCookie('templateBoolean', '1', 1, cookieHostname)
Util.setCookie('template', JSON.stringify(obj), 1, cookieHostname)
window.location.href = '/chat'
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment