Commit 3122b539 by 施宇

11212

parent 0ebcb590
Showing with 63 additions and 37 deletions
...@@ -13,28 +13,27 @@ $(function () { ...@@ -13,28 +13,27 @@ $(function () {
"grant_type": "client_credentials", "grant_type": "client_credentials",
"client_id": "YXA6UWJlUJGNEemA0XUSlr6mDA", "client_id": "YXA6UWJlUJGNEemA0XUSlr6mDA",
"client_secret": "YXA6n8pckF065e7FPtukjJHAoa-4G74" "client_secret": "YXA6n8pckF065e7FPtukjJHAoa-4G74"
},) }, )
$.ajax({ $.ajax({
type: 'post', type: 'post',
url: 'http://a1.easemob.com/1113190618181018/icsales/token', url: 'http://a1.easemob.com/1113190618181018/icsales/token',
data:data, data: data,
contentType:"application/json", contentType: "application/json",
success: function (data) { success: function (data) {
var token = data.access_token; var token = data.access_token;
$.ajax({ $.ajax({
type: 'get', type: 'get',
url: 'http://a1.easemob.com/1113190618181018/icsales/chatmessages/2019062513', url: 'http://a1.easemob.com/1113190618181018/icsales/chatmessages/2019062513',
headers:{ headers: {
Authorization:'Bearer '+token Authorization: 'Bearer ' + token
}, },
success: function (data) { success: function (data) {
console.log(data)
},
}, error: function () {
error: function () { layer.msg('网络出现问题,请重试!');
layer.msg('网络出现问题,请重试!'); }
} });
});
}, },
error: function () { error: function () {
...@@ -186,15 +185,22 @@ $(function () { ...@@ -186,15 +185,22 @@ $(function () {
clock += ss; clock += ss;
return (clock); return (clock);
}, },
userHtml: function (num, user, message) { userHtml: function (num, user, message, isTest) {
//左边用户的dom拼接 //左边用户的dom拼接
var messageContent = '';
if (isTest) {
messageContent = '100,000PCS ¥67.9800';
} else {
messageContent = message;
}
if (num == 0) { if (num == 0) {
return '<img src="' + dist + '/images/test.jpg" alt="" class="user_logo">' + return '<img src="' + dist + '/images/test.jpg" alt="" class="user_logo">' +
'<div class="user_right">' + '<div class="user_right">' +
'<div class="clr">' + '<div class="clr">' +
'<h3 class="boxsiz ellipsis">' + user + '</h3>' + '<h3 class="boxsiz ellipsis">' + user + '</h3>' +
'</div>' + '</div>' +
'<div class="message">' + message + '</div>' + '<div class="message ellipsis">' + messageContent + '</div>' +
'</div>' '</div>'
} else { } else {
return '<img src="' + dist + '/images/test.jpg" alt="" class="user_logo">' + return '<img src="' + dist + '/images/test.jpg" alt="" class="user_logo">' +
...@@ -203,20 +209,20 @@ $(function () { ...@@ -203,20 +209,20 @@ $(function () {
'<span class="num fr">' + num + '</span>' + '<span class="num fr">' + num + '</span>' +
'<h3 class="boxsiz ellipsis">' + user + '</h3>' + '<h3 class="boxsiz ellipsis">' + user + '</h3>' +
'</div>' + '</div>' +
'<div class="message">' + message + '</div>' + '<div class="message ellipsis">' + messageContent + '</div>' +
'</div>' '</div>'
} }
}, },
messageHtml: function (leftOrRight, html, obj) { messageHtml: function (leftOrRight, html, obj) {
//右边消息的dom拼接 //右边消息的dom拼接
var htmlp = ''
if (obj.test) {
htmlp = html;
} else {
htmlp = '<p>' + html + '</p>'
}
if (leftOrRight == 1) { //右边 if (leftOrRight == 1) { //右边
if (html) { if (html) {
var htmlp = ''
if (obj.test) {
htmlp = html;
} else {
htmlp = '<p>' + html + '</p>'
}
return '<div class="notice_item right clr">' + return '<div class="notice_item right clr">' +
'<img src="' + dist + '/images/test.jpg" alt="" class="fr user_logo">' + '<img src="' + dist + '/images/test.jpg" alt="" class="fr user_logo">' +
'<div class="notice_content">' + '<div class="notice_content">' +
...@@ -234,9 +240,9 @@ $(function () { ...@@ -234,9 +240,9 @@ $(function () {
return '<div class = "notice_item left clr" > ' + return '<div class = "notice_item left clr" > ' +
'<img src="' + dist + '/images/test.jpg" alt="" class="fl user_logo">' + '<img src="' + dist + '/images/test.jpg" alt="" class="fl user_logo">' +
'<div class="notice_content">' + '<div class="notice_content">' +
'<p>' + // '<p>' +
html + htmlp +
'</p>' + // '</p>' +
'<div>' + this.curentTime() + '</div>' + '<div>' + this.curentTime() + '</div>' +
'</div>' '</div>'
} else { } else {
...@@ -250,6 +256,18 @@ $(function () { ...@@ -250,6 +256,18 @@ $(function () {
var regContent = ""; var regContent = "";
var htmlStr = ""; var htmlStr = "";
var self = this; var self = this;
var isTest = '';
try {
isTest = message.ext.test
} catch (e) {
}
var obj = {};
if (isTest) {
obj = {
test: 1
}
}
if (type == 1) { if (type == 1) {
regContent = message.data; regContent = message.data;
htmlStr = message.data; htmlStr = message.data;
...@@ -279,7 +297,7 @@ $(function () { ...@@ -279,7 +297,7 @@ $(function () {
'</div>' + '</div>' +
'<div class="notice_list boxsiz">' + '<div class="notice_list boxsiz">' +
'<div class="notice_item_content">' + '<div class="notice_item_content">' +
self.messageHtml(2, htmlStr, {}) + self.messageHtml(2, htmlStr, obj) +
'</div>' + '</div>' +
'</div>' + '</div>' +
'</div>'; '</div>';
...@@ -287,7 +305,7 @@ $(function () { ...@@ -287,7 +305,7 @@ $(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 + '">' +
self.userHtml(0, message.from, regContent) + '</div>'; self.userHtml(0, message.from, regContent, isTest) + '</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_left_content').append(userStr);
...@@ -300,9 +318,9 @@ $(function () { ...@@ -300,9 +318,9 @@ $(function () {
//已有用户 //已有用户
if (isNowChat) { if (isNowChat) {
//当前用户 //当前用户
$(this).html(self.userHtml(0, message.from, regContent)); $(this).html(self.userHtml(0, message.from, regContent, isTest));
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2, $('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, {})); htmlStr, obj));
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);
...@@ -310,9 +328,9 @@ $(function () { ...@@ -310,9 +328,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.from, regContent)); $(this).html(self.userHtml(num + 1, message.from, regContent, isTest));
$('#' + userId).find('.notice_item_content').append(self.messageHtml(2, $('#' + userId).find('.notice_item_content').append(self.messageHtml(2,
htmlStr, {})); htmlStr, obj));
} }
return false; return false;
...@@ -321,7 +339,7 @@ $(function () { ...@@ -321,7 +339,7 @@ $(function () {
//新用户 //新用户
var userStr = '<div class="notice_classify" userid="' + var userStr = '<div class="notice_classify" userid="' +
message.from + '">' + message.from + '">' +
self.userHtml(1, message.from, regContent) + '</div>'; self.userHtml(1, message.from, regContent, isTest) + '</div>';
var messageStr = '<div class="chat_item" id="' + var messageStr = '<div class="chat_item" id="' +
message.from + '">' + message.from + '">' +
messageSigleStr + '</div>' messageSigleStr + '</div>'
...@@ -401,10 +419,18 @@ $(function () { ...@@ -401,10 +419,18 @@ $(function () {
var id = this.conn.getUniqueId(); var id = this.conn.getUniqueId();
var msg = new WebIM.message('txt', id); var msg = new WebIM.message('txt', id);
var emojiMessage = WebIM.utils.parseEmoji(content); //表情解析工具 var emojiMessage = WebIM.utils.parseEmoji(content); //表情解析工具
var ext = {};
if (obj.test) {
ext = {
'test': '1'
}
};
console.log(ext)
msg.set({ msg.set({
msg: content, // 消息内容; msg: content, // 消息内容;
to: userId, // 接收消息对象; to: userId, // 接收消息对象;
roomType: false, roomType: false,
ext: ext, //用户自扩展的消息内容
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,
emojiMessage, obj)); emojiMessage, obj));
......
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