Commit 47589bcc by 施宇

1111

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