Commit 91257f3c by 施宇

11

parent 20e61a7f
Showing with 31 additions and 25 deletions
...@@ -56,7 +56,7 @@ $(function () { ...@@ -56,7 +56,7 @@ $(function () {
} else { } else {
console.log('添加聊天成员失败') console.log('添加聊天成员失败')
} }
}); },false);
}, },
rendChatSection: function (data) { rendChatSection: function (data) {
this.addUser({}, true); this.addUser({}, true);
...@@ -242,9 +242,7 @@ $(function () { ...@@ -242,9 +242,7 @@ $(function () {
messageHtml: function (leftOrRight, html, isTemplate, isHistory, time) { messageHtml: function (leftOrRight, html, isTemplate, isHistory, time) {
//右边消息的dom拼接 isTemplate 是否是模板 //右边消息的dom拼接 isTemplate 是否是模板
var htmlp = '<p>' + html.message + '</p>'; var htmlp = '<p>' + html.message + '</p>';
var img = html.img || (dist + '/images/default.jpg') var img = html.img || (dist + '/images/default.jpg')
if (isTemplate) { if (isTemplate) {
var htmlp = '<div class="template lineBlock boxsiz">' + var htmlp = '<div class="template lineBlock boxsiz">' +
'<img src="' + (html.goodImage || dist + "/images/defaultgood.png") + '" alt="">' + '<img src="' + (html.goodImage || dist + "/images/defaultgood.png") + '" alt="">' +
...@@ -279,11 +277,10 @@ $(function () { ...@@ -279,11 +277,10 @@ $(function () {
} else { } else {
return '' return ''
} }
} else { //左边 } else { //左边
if (html) { if (html) {
return '<div class = "notice_item left clr" > ' + return '<div class = "notice_item left clr" > ' +
'<img src="' + dist + '/images/default.jpg" alt="" class="fl user_logo">' + '<img src="' + img + '" alt="" class="fl user_logo">' +
'<div class="notice_content">' + '<div class="notice_content">' +
htmlp + htmlp +
'<div>' + (isHistory ? time : this.curentTime()) + '</div>' + '<div>' + (isHistory ? time : this.curentTime()) + '</div>' +
...@@ -300,28 +297,40 @@ $(function () { ...@@ -300,28 +297,40 @@ $(function () {
var regContent = ""; var regContent = "";
var htmlStr = ""; var htmlStr = "";
var self = this; var self = this;
var emojiTxt = ""
if (type == 1) { if (type == 1) {
if (isTemplate) { if (isTemplate) {
regContent = message.type + ' ' + message.price; regContent = message.type + ' ' + message.price;
htmlStr = message; htmlStr = message;
} else { } else {
regContent = message.message; regContent = message.message;
htmlStr = message.message; htmlStr = message;
} }
} else if (type == 2) { } else if (type == 2) {
regContent = '[图片]'; regContent = '[图片]';
htmlStr = '<img src ="' + message.url + '" class="edit_img"/>'; htmlStr = {
message:'<img src ="' + message.url + '" class="edit_img"/>',
name: message.name,
img: message.img,
id: message.id
}
} else { } else {
var data = message.message; var data = message.message;
for (var i = 0, l = data.length; i < l; i++) { for (var i = 0, l = data.length; i < l; i++) {
if (data[i].type == 'emoji') { if (data[i].type == 'emoji') {
regContent += '[表情]'; regContent += '[表情]';
htmlStr += '<img src ="' + data[i].data + '" width=25 height=25/>'; emojiTxt += '<img src ="' + data[i].data + '" width=25 height=25/>';
} else { } else {
regContent += data[i].data; regContent += data[i].data;
htmlStr += data[i].data; emojiTxt += data[i].data;
} }
}; };
htmlStr = {
message:emojiTxt,
name: message.name,
img: message.img,
id: message.id
}
} }
var len = $('.notice_classify').length; var len = $('.notice_classify').length;
var messageSigleStr = var messageSigleStr =
...@@ -341,9 +350,9 @@ $(function () { ...@@ -341,9 +350,9 @@ $(function () {
if (!len) { if (!len) {
//新用户 //新用户
var userStr = '<div class="notice_classify active" userid="' + message.to + '">' + var userStr = '<div class="notice_classify active" userid="' + message.from + '">' +
self.userHtml(0, message, regContent) + '</div>'; self.userHtml(0, message, regContent) + '</div>';
var messageStr = '<div class="chat_item active" id="' + message.to + '">' + var messageStr = '<div class="chat_item active" id="' + message.from + '">' +
messageSigleStr + '</div>' messageSigleStr + '</div>'
$('.notice_left_content').append(userStr); $('.notice_left_content').append(userStr);
$('.chat_item_content').append(messageStr) $('.chat_item_content').append(messageStr)
...@@ -351,7 +360,7 @@ $(function () { ...@@ -351,7 +360,7 @@ $(function () {
$('.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');
if (userId == message.to) { if (userId == message.from) {
//已有用户 //已有用户
if (isNowChat) { if (isNowChat) {
//当前用户 //当前用户
...@@ -365,9 +374,9 @@ $(function () { ...@@ -365,9 +374,9 @@ $(function () {
} else { } else {
//非当前用户 //非当前用户
var num = Number($(this).find('.num').text()); var num = Number($(this).find('.num').text());
$(this).html(self.userHtml(num + 1, message.to, regContent)); $(this).html(self.userHtml(num + 1, message, regContent));
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2, // $('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, isTemplate)); // htmlStr, isTemplate));
} }
return false; return false;
...@@ -375,10 +384,10 @@ $(function () { ...@@ -375,10 +384,10 @@ $(function () {
if (index == len - 1) { if (index == len - 1) {
//新用户 //新用户
var userStr = '<div class="notice_classify" userid="' + var userStr = '<div class="notice_classify" userid="' +
message.to + '">' + message.from + '">' +
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.to + '">' + message.from + '">' +
messageSigleStr + '</div>' messageSigleStr + '</div>'
$('.notice_left_content').append(userStr); $('.notice_left_content').append(userStr);
$('.chat_item_content').append(messageStr) $('.chat_item_content').append(messageStr)
...@@ -402,7 +411,7 @@ $(function () { ...@@ -402,7 +411,7 @@ $(function () {
id: message.ext.id, id: message.ext.id,
img: message.ext.img, img: message.ext.img,
message: message.data, message: message.data,
from: message.to from: message.from
}, false) }, false)
}, //收到文本消息; }, //收到文本消息;
onEmojiMessage: function (message) { onEmojiMessage: function (message) {
...@@ -411,7 +420,7 @@ $(function () { ...@@ -411,7 +420,7 @@ $(function () {
id: message.ext.id, id: message.ext.id,
img: message.ext.img, img: message.ext.img,
message: message.data, message: message.data,
to: message.to, from: message.from,
}, false) }, false)
}, //收到表情消息; }, //收到表情消息;
...@@ -420,7 +429,7 @@ $(function () { ...@@ -420,7 +429,7 @@ $(function () {
name: message.ext.name, name: message.ext.name,
id: message.ext.id, id: message.ext.id,
img: message.ext.img, img: message.ext.img,
to: message.to, 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,
...@@ -442,8 +451,7 @@ $(function () { ...@@ -442,8 +451,7 @@ $(function () {
name: message.ext.name, name: message.ext.name,
id: message.ext.id, id: message.ext.id,
img: message.ext.img, img: message.ext.img,
to: message.to, from: message.from,
from: message.to,
url: message.url url: message.url
}, false) }, false)
...@@ -502,7 +510,6 @@ $(function () { ...@@ -502,7 +510,6 @@ $(function () {
name: self.name, name: self.name,
img: self.img img: self.img
}; };
console.log(ext)
msg.set({ msg.set({
msg: content, // 消息内容; msg: content, // 消息内容;
to: userId, // 接收消息对象; to: userId, // 接收消息对象;
...@@ -544,7 +551,7 @@ $(function () { ...@@ -544,7 +551,7 @@ $(function () {
action: "template", action: "template",
ext: params, ext: params,
success: function () { success: function () {
self.addChatMember(templateObj.id); self.addChatMember(templateObj.targetId);
$('#' + userId).find('.notice_item_content').append(self.messageHtml(1, $('#' + userId).find('.notice_item_content').append(self.messageHtml(1,
params, true)); params, true));
var contentHeight = $('#' + userId).find('.notice_item_content') var contentHeight = $('#' + userId).find('.notice_item_content')
...@@ -674,7 +681,6 @@ $(function () { ...@@ -674,7 +681,6 @@ $(function () {
queue: id, queue: id,
count: '50', count: '50',
success: function (data) { success: function (data) {
console.log(data)
self.rendHistoryMessage(id, data) self.rendHistoryMessage(id, data)
if (isTemplate) { if (isTemplate) {
self.sendCmd(self.templateObj); self.sendCmd(self.templateObj);
......
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