Commit e0eaf2e3 by 施宇

11111

parent 4e38dbad
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<li class="fl"><img src="__PUBLIC__/faces/ee_12.png" alt="" data-text="[:|]"></li> <li class="fl"><img src="__PUBLIC__/faces/ee_12.png" alt="" data-text="[:|]"></li>
<li class="fl"><img src="__PUBLIC__/faces/ee_13.png" alt="" data-text="[(a)]"></li> <li class="fl"><img src="__PUBLIC__/faces/ee_13.png" alt="" data-text="[(a)]"></li>
<li class="fl"><img src="__PUBLIC__/faces/ee_14.png" alt="" data-text="[8o|]"></li> <li class="fl"><img src="__PUBLIC__/faces/ee_14.png" alt="" data-text="[8o|]"></li>
<li class="fl"><img src="__PUBLIC__/faces/ee_15.png" alt="" data-text="[|]"></li> <li class="fl"><img src="__PUBLIC__/faces/ee_15.png" alt="" data-text="[8-|]"></li>
<li class="fl"><img src="__PUBLIC__/faces/ee_16.png" alt="" data-text="[+o(]"></li> <li class="fl"><img src="__PUBLIC__/faces/ee_16.png" alt="" data-text="[+o(]"></li>
<li class="fl"><img src="__PUBLIC__/faces/ee_17.png" alt="" data-text="[o)]"></li> <li class="fl"><img src="__PUBLIC__/faces/ee_17.png" alt="" data-text="[o)]"></li>
<li class="fl"><img src="__PUBLIC__/faces/ee_18.png" alt="" data-text="[|-)]"></li> <li class="fl"><img src="__PUBLIC__/faces/ee_18.png" alt="" data-text="[|-)]"></li>
......
...@@ -3,7 +3,8 @@ $(function () { ...@@ -3,7 +3,8 @@ $(function () {
conn: {}, conn: {},
orgName: "1113190618181018", orgName: "1113190618181018",
appName: "icsales", appName: "icsales",
defaultName: "18664936975", defaultName: "001",
customerNum: "",
templateObj: JSON.parse(Util.getCookie('template') || "{}"), templateObj: JSON.parse(Util.getCookie('template') || "{}"),
customerText: Util.getCookie('customer') || "", customerText: Util.getCookie('customer') || "",
isLoginSuccess: false, isLoginSuccess: false,
...@@ -31,6 +32,7 @@ $(function () { ...@@ -31,6 +32,7 @@ $(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.customerNum = res.data.im_username || '';
self.getHistoryUsers(res.data.im_username, res.data.im_password); self.getHistoryUsers(res.data.im_username, res.data.im_password);
} else { } else {
...@@ -68,15 +70,21 @@ $(function () { ...@@ -68,15 +70,21 @@ $(function () {
}, false); }, false);
}, },
rendChatSection: function (data) { rendChatSection: function (data) {
console.log('获取成员') if (this.customerNum !== this.defaultName) {
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])
} }
}, },
singleChat: function () { singleChat: function () {
if (JSON.stringify(this.templateObj) == '{}') { if (JSON.stringify(this.templateObj) == '{}') {
if (this.customerNum !== this.defaultName) {
$(".notice_classify[userid=" + this.defaultName + "]").click(); $(".notice_classify[userid=" + this.defaultName + "]").click();
} else {
$(".notice_classify").first().click();
}
} else { } else {
Util.delCookie('template', cookieHostname); Util.delCookie('template', cookieHostname);
this.addUser({}, false, true); this.addUser({}, false, true);
...@@ -98,24 +106,29 @@ $(function () { ...@@ -98,24 +106,29 @@ $(function () {
}, },
addUser: function (obj, isDefault, isFirst) { addUser: function (obj, isDefault, isFirst) {
var id, name, img, touserid; var id, name, img, touserid, img1;
if (isDefault) { if (isDefault) {
id = this.defaultName; id = this.defaultName;
name = 'IC助手客服'; name = 'IC助手客服';
touserid = ""; touserid = "";
img = dist + "/images/timg.jpg"; img = dist + "/images/timg.jpg";
img1 = dist + "/images/timg.jpg";
} else { } else {
if (isFirst) { if (isFirst) {
id = this.templateObj.userId; id = this.templateObj.userId;
touserid = this.templateObj.touserid; touserid = this.templateObj.touserid;
name = this.templateObj.userName; name = this.templateObj.userName;
img = this.templateObj.userImg || (dist + "/images/default.jpg"); img = this.templateObj.userImg || (dist + "/images/default.jpg");
img1 = this.templateObj.userImg || ""
} else { } else {
id = obj.im_username; id = obj.im_username;
name = obj.company_name || '--'; name = obj.company_name || '--';
touserid = obj.user_id; touserid = obj.user_id;
img = obj.avatar || (dist + "/images/default.jpg") img = obj.avatar || (dist + "/images/default.jpg");
img1 = obj.avatar || ""
} }
} }
...@@ -123,11 +136,11 @@ $(function () { ...@@ -123,11 +136,11 @@ $(function () {
if (userLen) { //用户存在 if (userLen) { //用户存在
return; return;
} else { //用户不存在 } else { //用户不存在
var lefthtml = '<div class="notice_classify" userid="' + id + '" firstClick="true" touserid=' + touserid + '>' + this.userHtml(0, { var lefthtml = '<div class="notice_classify" userid="' + id + '" firstClick="true" touserid="' + touserid + '"name="' + name + '" img="' + img1 + '">' + this.userHtml(0, {
name: name, name: name,
id: id, id: id,
img: img img: img
}, '') + '</div>';; }, '') + '</div>';
var righthtml = '<div class="chat_item" id="' + id + '">' + var righthtml = '<div class="chat_item" id="' + id + '">' +
'<div class="title clr">' + '<div class="title clr">' +
// '<div class="fr btn btn_border">' + // '<div class="fr btn btn_border">' +
...@@ -183,7 +196,7 @@ $(function () { ...@@ -183,7 +196,7 @@ $(function () {
'[:|]': 'ee_12.png', '[:|]': 'ee_12.png',
'[(a)]': 'ee_13.png', '[(a)]': 'ee_13.png',
'[8o|]': 'ee_14.png', '[8o|]': 'ee_14.png',
'[|]': 'ee_15.png', '[8-|]': 'ee_15.png',
'[+o(]': 'ee_16.png', '[+o(]': 'ee_16.png',
'[o)]': 'ee_17.png', '[o)]': 'ee_17.png',
'[|-)]': 'ee_18.png', '[|-)]': 'ee_18.png',
...@@ -376,11 +389,17 @@ $(function () { ...@@ -376,11 +389,17 @@ $(function () {
if (!len) { if (!len) {
//新用户 //新用户
Util.delCookie('templateBoolean', cookieHostname); Util.delCookie('templateBoolean', cookieHostname);
var userStr = '<div class="notice_classify active" userid="' + message.from + '" firstClick="true" newMember="true" touserid=' + message.touserid + '>' + var userStr = '<div class="notice_classify active" userid="' + message.from + '" firstClick="true" newMember="true" touserid="' + message.touserid + '"name="' + message.name + '" img="' + message.img + '">' +
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>'
if (self.defaultName != self.customerNum) {
if (self.defaultName != message.from) {
$(".notice_classify[userid=" + self.defaultName + "]").after(userStr); $(".notice_classify[userid=" + self.defaultName + "]").after(userStr);
}
} else {
$(".notice_left_content").prepend(userStr);
}
// $('.notice_left_content').append(userStr); // $('.notice_left_content').append(userStr);
$('.chat_item_content').append(messageStr) $('.chat_item_content').append(messageStr)
} else { } else {
...@@ -422,8 +441,15 @@ $(function () { ...@@ -422,8 +441,15 @@ $(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));
var html = $(this).clone(); var html = $(this).clone();
if (self.defaultName != self.customerNum) { //不是客服
if (message.from != self.defaultName) {
$(this).remove(); $(this).remove();
$(".notice_classify[userid=" + self.defaultName + "]").after(html); $(".notice_classify[userid=" + self.defaultName + "]").after(html);
}
} else {
$(this).remove();
$(".notice_left_content").prepend(html);
}
if (!firstClick) { if (!firstClick) {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2, $('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate)); htmlStr, isTemplate));
...@@ -436,12 +462,18 @@ $(function () { ...@@ -436,12 +462,18 @@ $(function () {
//新用户 //新用户
Util.delCookie('templateBoolean', cookieHostname); Util.delCookie('templateBoolean', cookieHostname);
var userStr = '<div class="notice_classify" userid="' + var userStr = '<div class="notice_classify" userid="' +
message.from + '" newMember="true" touserid=' + message.touserid + '>' + message.from + '" newMember="true" touserid="' + message.touserid + '"name="' + message.name + '" img="' + message.img + '">' +
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>';
if (self.defaultName != self.customerNum) {
if (self.defaultName != message.from) {
$(".notice_classify[userid=" + self.defaultName + "]").after(userStr); $(".notice_classify[userid=" + self.defaultName + "]").after(userStr);
}
} else {
$(".notice_left_content").prepend(userStr);
}
$('.chat_item_content').append(messageStr) $('.chat_item_content').append(messageStr)
} }
} }
...@@ -460,31 +492,36 @@ $(function () { ...@@ -460,31 +492,36 @@ $(function () {
}, },
onTextMessage: function (message) { onTextMessage: function (message) {
self.receiveData(1, { self.receiveData(1, {
name: message.ext.name || '--', name: self.judgeCustomer(message).name,
id: message.ext.id, id: message.ext.id,
img: message.ext.img || (dist + "/images/default.jpg"), img: self.judgeCustomer(message).img,
message: message.data, message: message.data,
from: message.from, from: message.from,
touserid: message.ext.touserid touserid: message.ext.touserid
}, false) }, false);
if (self.customerNum == self.defaultName) {
self.addChatMember(message.ext.id)
}
}, //收到文本消息; }, //收到文本消息;
onEmojiMessage: function (message) { onEmojiMessage: function (message) {
self.receiveData(3, { self.receiveData(3, {
name: message.ext.name || '--', name: self.judgeCustomer(message).name,
id: message.ext.id, id: message.ext.id,
img: message.ext.img || (dist + "/images/default.jpg"), img: self.judgeCustomer(message).img,
message: message.data, message: message.data,
from: message.from, from: message.from,
touserid: message.ext.touserid touserid: message.ext.touserid
}, false) }, false);
if (self.customerNum == self.defaultName) {
self.addChatMember(message.ext.id)
}
}, //收到表情消息; }, //收到表情消息;
onCmdMessage: function (message) { onCmdMessage: function (message) {
console.log(message)
self.receiveData(1, { self.receiveData(1, {
name: message.ext.name || '--', name: self.judgeCustomer(message).name,
id: message.ext.id, id: message.ext.id,
img: message.ext.img || (dist + "/images/default.jpg"), img: self.judgeCustomer(message).img,
from: message.from, from: message.from,
type: message.ext.type, type: message.ext.type,
price: message.ext.price, price: message.ext.price,
...@@ -505,15 +542,16 @@ $(function () { ...@@ -505,15 +542,16 @@ $(function () {
options.onFileDownloadComplete = function () { options.onFileDownloadComplete = function () {
// 图片下载成功; // 图片下载成功;
self.receiveData(2, { self.receiveData(2, {
name: message.ext.name || '--', name: self.judgeCustomer(message).name,
id: message.ext.id, id: message.ext.id,
img: message.ext.img || (dist + "/images/default.jpg"), img: self.judgeCustomer(message).img,
from: message.from, from: message.from,
url: message.url, url: message.url,
touserid: message.ext.touserid touserid: message.ext.touserid
}, false) }, false);
if (self.customerNum == self.defaultName) {
self.addChatMember(message.ext.id)
}
}; };
options.onFileDownloadError = function () { options.onFileDownloadError = function () {
// 图片下载失败 // 图片下载失败
...@@ -536,6 +574,17 @@ $(function () { ...@@ -536,6 +574,17 @@ $(function () {
}, //失败回调; }, //失败回调;
}); });
}, },
judgeCustomer: function (message) {//1 标题 2//图片
var obj = {name:"",img:""};
if (message.from == this.defaultName) {
obj.img = dist + "/images/timg.jpg";
obj.name = 'IC助手客服';
} else {
obj.img = message.ext.img || (dist + "/images/default.jpg");
obj.name = message.ext.name || '--';
}
return obj
},
login: function (user, password) { login: function (user, password) {
// open,登录; // open,登录;
...@@ -559,6 +608,8 @@ $(function () { ...@@ -559,6 +608,8 @@ $(function () {
// 私聊发送文本消息,发送表情同发送文本消息,只是会在对方客户端将表情文本进行解析成图片; // 私聊发送文本消息,发送表情同发送文本消息,只是会在对方客户端将表情文本进行解析成图片;
var userId = $('.notice_left ').find('.active').attr('userid'); var userId = $('.notice_left ').find('.active').attr('userid');
var touserid = $('.notice_left ').find('.active').attr('touserid'); var touserid = $('.notice_left ').find('.active').attr('touserid');
var name = $('.notice_left ').find('.active').attr('name');
var img = $('.notice_left ').find('.active').attr('img');
var id = this.conn.getUniqueId(); var id = this.conn.getUniqueId();
var msg = new WebIM.default.message('txt', id); var msg = new WebIM.default.message('txt', id);
var emojiMessage = WebIM.default.utils.parseEmoji(content); //表情解析工具 var emojiMessage = WebIM.default.utils.parseEmoji(content); //表情解析工具
...@@ -567,7 +618,9 @@ $(function () { ...@@ -567,7 +618,9 @@ $(function () {
id: self.id, id: self.id,
name: self.name, name: self.name,
img: self.img, img: self.img,
touserid: touserid touserid: touserid,
name1: name,
img1: img
}; };
msg.set({ msg.set({
msg: content, // 消息内容; msg: content, // 消息内容;
...@@ -576,8 +629,8 @@ $(function () { ...@@ -576,8 +629,8 @@ $(function () {
success: function (id, serverMsgId) { success: function (id, serverMsgId) {
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1, { $('#' + userId).find('.notice_item_content').append(self.messageHtml(1, {
message: emojiMessage, message: emojiMessage,
name: self.name, name: self.customerNum == self.defaultName ? 'IC助手客服' : self.name,
img: self.img, img: self.customerNum == self.defaultName ? dist + "/images/timg.jpg" : self.img,
id: self.id id: self.id
}, false)); }, false));
...@@ -612,6 +665,8 @@ $(function () { ...@@ -612,6 +665,8 @@ $(function () {
var self = this; var self = this;
var userId = $('.notice_left ').find('.active').attr('userid'); var userId = $('.notice_left ').find('.active').attr('userid');
var touserid = $('.notice_left ').find('.active').attr('touserid'); var touserid = $('.notice_left ').find('.active').attr('touserid');
var name = $('.notice_left ').find('.active').attr('name');
var img = $('.notice_left ').find('.active').attr('img');
var id = this.conn.getUniqueId(); var id = this.conn.getUniqueId();
var msg = new WebIM.default.message('cmd', id); var msg = new WebIM.default.message('cmd', id);
var params = $.extend({}, templateObj, { var params = $.extend({}, templateObj, {
...@@ -619,7 +674,9 @@ $(function () { ...@@ -619,7 +674,9 @@ $(function () {
name: self.name, name: self.name,
id: self.id, id: self.id,
img: self.img, img: self.img,
touserid: touserid touserid: touserid,
name1: name,
img1: img
}); });
msg.set({ msg.set({
msg: 'template', msg: 'template',
...@@ -665,7 +722,8 @@ $(function () { ...@@ -665,7 +722,8 @@ $(function () {
var file = WebIM.default.utils.getFileUrl(input); // 将图片转化为二进制文件; var file = WebIM.default.utils.getFileUrl(input); // 将图片转化为二进制文件;
var userId = $('.notice_left').find('.active').attr('userid'); var userId = $('.notice_left').find('.active').attr('userid');
var touserid = $('.notice_left ').find('.active').attr('touserid'); var touserid = $('.notice_left ').find('.active').attr('touserid');
var name = $('.notice_left ').find('.active').attr('name');
var img = $('.notice_left ').find('.active').attr('img');
var option = { var option = {
apiUrl: WebIM.config.apiURL, apiUrl: WebIM.config.apiURL,
file: file, file: file,
...@@ -673,9 +731,11 @@ $(function () { ...@@ -673,9 +731,11 @@ $(function () {
ext: { ext: {
timer: self.curentTime(), timer: self.curentTime(),
id: self.id, id: self.id,
name: self.name, name:self.name,
img: self.img, img: self.img,
touserid: touserid touserid: touserid,
name1: name,
img1: img
}, },
flashUpload: WebIM.flashUpload, flashUpload: WebIM.flashUpload,
onFileUploadError: function () { onFileUploadError: function () {
...@@ -688,8 +748,8 @@ $(function () { ...@@ -688,8 +748,8 @@ $(function () {
var htmlStr = '<img src ="' + file.url + '" class="edit_img"/>'; var htmlStr = '<img src ="' + file.url + '" class="edit_img"/>';
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1, { $('#' + userId).find('.notice_item_content').append(self.messageHtml(1, {
message: htmlStr, message: htmlStr,
name: self.name, name: self.customerNum == self.defaultName ? 'IC助手客服' : self.name,
img: self.img, img: self.customerNum == self.defaultName ? dist + "/images/timg.jpg" : self.img,
id: self.id id: self.id
}, false)); }, false));
var imgLen = $('#' + userId).find('img').length; var imgLen = $('#' + userId).find('img').length;
...@@ -716,7 +776,6 @@ $(function () { ...@@ -716,7 +776,6 @@ $(function () {
} }
}; };
msg.set(option); msg.set(option);
console.log(msg.body)
this.conn.send(msg.body); this.conn.send(msg.body);
}, },
...@@ -855,6 +914,7 @@ $(function () { ...@@ -855,6 +914,7 @@ $(function () {
}) })
}, },
rendHistoryMessage: function (id, data, isTemplate) { rendHistoryMessage: function (id, data, isTemplate) {
console.log(data)
var chatCon = ""; var chatCon = "";
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var fromId = data[i].from; var fromId = data[i].from;
...@@ -867,8 +927,8 @@ $(function () { ...@@ -867,8 +927,8 @@ $(function () {
if (typeof (data[i].data) == 'string') { if (typeof (data[i].data) == 'string') {
chatCon += this.messageHtml(rightOrLeft, { chatCon += this.messageHtml(rightOrLeft, {
message: data[i].data, message: data[i].data,
name: data[i].ext.name, name:this.judgeCustomer(data[i]).name,
img: data[i].ext.img, img:this.judgeCustomer(data[i]).img,
id: data[i].ext.id id: data[i].ext.id
}, false, true, data[i].ext.timer); }, false, true, data[i].ext.timer);
} else { } else {
...@@ -881,8 +941,8 @@ $(function () { ...@@ -881,8 +941,8 @@ $(function () {
} }
chatCon += this.messageHtml(rightOrLeft, { chatCon += this.messageHtml(rightOrLeft, {
message: emojiTxt, message: emojiTxt,
name: data[i].ext.name, name:this.judgeCustomer(data[i]).name,
img: data[i].ext.img, img:this.judgeCustomer(data[i]).img,
id: data[i].ext.id id: data[i].ext.id
}, false, true, data[i].ext.timer); }, false, true, data[i].ext.timer);
} }
...@@ -890,8 +950,8 @@ $(function () { ...@@ -890,8 +950,8 @@ $(function () {
} else if (data[i].url) { //图片 } else if (data[i].url) { //图片
chatCon += this.messageHtml(rightOrLeft, { chatCon += this.messageHtml(rightOrLeft, {
message: '<img src ="' + data[i].url + '" class="edit_img"/>', message: '<img src ="' + data[i].url + '" class="edit_img"/>',
name: data[i].ext.name, name:this.judgeCustomer(data[i]).name,
img: data[i].ext.img, img:this.judgeCustomer(data[i]).img,
id: data[i].ext.id id: data[i].ext.id
}, false, true, data[i].ext.timer); }, false, true, data[i].ext.timer);
} else if (data[i].action == 'template') { //模板 } else if (data[i].action == 'template') { //模板
......
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