Commit 3122b539 by 施宇

11212

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