Commit 31b0d1c9 by 施宇

1

parent 157431b0
Showing with 50 additions and 43 deletions
...@@ -3,6 +3,8 @@ $(function () { ...@@ -3,6 +3,8 @@ $(function () {
conn: {}, conn: {},
orgName: "1113190618181018", orgName: "1113190618181018",
appName: "icsales", appName: "icsales",
// defaultName:"18664936975",
defaultName: "18589050841",
init: function () { init: function () {
this.ieFun() this.ieFun()
this.connection(); this.connection();
...@@ -16,32 +18,42 @@ $(function () { ...@@ -16,32 +18,42 @@ $(function () {
if (res.err_code == 0) { if (res.err_code == 0) {
self.login(res.data.im_username, res.data.im_password) self.login(res.data.im_username, res.data.im_password)
} else { } else {
console.log('获取用户名失败') console.log('获取用户名失败');
layer.msg('聊天系统出错');
} }
}, undefined, true) }, undefined, true)
}, },
getHistoryData: function () { getHistoryData: function (id) {
console.log(this.conn.prototype) this.conn.fetchHistoryMessages({
queue: id,
count: "1000",
success: function (data) {
console.log(data)
}, },
registerUser: function (user, password) { //给用户注册环信账号 fail: function (e) {
var self = this; console.log(e)
var options = { layer.msg('获取历史纪录失败');
username: user, }
password: password, })
appKey: WebIM.config.appkey,
success: function () {
self.login(user, password)
}, },
error: function () { renderHistory: function (isCustomer, data) {
console.log('注册失败') var len = data.length;
for (var i = 0; i < len; i++) {
var fromId = data[i].from,//发送者的id
toId = data[i].to;//接收者的id
if (data[i].from == '18271408717') {//自己发送的
this.historyHtml(1)
} else {//自己接收的
this.historyHtml(2 )
}
}
}, },
apiUrl: WebIM.config.apiURL historyHtml:function(leftOrRight,data){//1右边 2左边
};
self.conn.registerUser(options);
}, },
defaultUser: function () { defaultUser: function () {
//默认客服 //默认客服
this.addUser('18664936975', true) this.addUser(this.defaultName, true)
}, },
singleChat: function () { singleChat: function () {
...@@ -61,10 +73,10 @@ $(function () { ...@@ -61,10 +73,10 @@ $(function () {
var lefthtml = '<div class="notice_classify" userid="' + id + '">' + this.userHtml(0, id, '') + '</div>';; var lefthtml = '<div class="notice_classify" userid="' + id + '">' + this.userHtml(0, id, '') + '</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">' +
'<span class="icon iconfont iconjuxing23"></span>' + // '<span class="icon iconfont iconjuxing23"></span>' +
'<i>' + id + '</i>' + // '<i>' + id + '</i>' +
'</div>' + // '</div>' +
'<h3 class="bold boxsiz">' + id + '</h3>' + '<h3 class="bold boxsiz">' + id + '</h3>' +
'</div>' + '</div>' +
'<div class="notice_list boxsiz">' + '<div class="notice_list boxsiz">' +
...@@ -283,10 +295,10 @@ $(function () { ...@@ -283,10 +295,10 @@ $(function () {
var len = $('.notice_classify').length; var len = $('.notice_classify').length;
var messageSigleStr = var messageSigleStr =
'<div class="title clr">' + '<div class="title clr">' +
'<div class="fr btn btn_border">' + // '<div class="fr btn btn_border">' +
'<span class="icon iconfont iconjuxing23"></span>' + // '<span class="icon iconfont iconjuxing23"></span>' +
'<i>' + message.from + '</i>' + // '<i>' + message.from + '</i>' +
'</div>' + // '</div>' +
'<h3 class="bold boxsiz">' + message.from + '</h3>' + '<h3 class="bold boxsiz">' + message.from + '</h3>' +
'</div>' + '</div>' +
'<div class="notice_list boxsiz">' + '<div class="notice_list boxsiz">' +
...@@ -352,17 +364,8 @@ $(function () { ...@@ -352,17 +364,8 @@ $(function () {
console.log('登入成功') console.log('登入成功')
self.defaultUser(); self.defaultUser();
self.singleChat(); self.singleChat();
self.getHistoryData(); self.getHistoryData(self.defaultName);
self.conn.fetchHistoryMessages({
queue:"18664936975",
count:"100",
success:function(data){
console.log(data)
},
fail:function(e){
console.log(e)
}
})
}, },
onTextMessage: function (message) { onTextMessage: function (message) {
self.receiveData(1, message, false) self.receiveData(1, message, false)
...@@ -372,7 +375,6 @@ $(function () { ...@@ -372,7 +375,6 @@ $(function () {
}, //收到表情消息; }, //收到表情消息;
onCmdMessage: function (message) { onCmdMessage: function (message) {
// console.log('CMD');
self.receiveData(1, message, true); self.receiveData(1, message, true);
}, //收到命令消息; }, //收到命令消息;
onPictureMessage: function (message) { onPictureMessage: function (message) {
...@@ -389,7 +391,7 @@ $(function () { ...@@ -389,7 +391,7 @@ $(function () {
// 图片下载失败 // 图片下载失败
// console.log('Image download failed!'); // console.log('Image download failed!');
}; };
WebIM.utils.download.call(self.conn, options); // 意义待查; WebIM.default.utils.download.call(self.conn, options); // 意义待查;
}, //收到图片消息; }, //收到图片消息;
...@@ -402,6 +404,7 @@ $(function () { ...@@ -402,6 +404,7 @@ $(function () {
onError: function (message) { onError: function (message) {
// console.log('Error', WebIM.utils.stringify(message)); // console.log('Error', WebIM.utils.stringify(message));
console.log('onError: ', message); console.log('onError: ', message);
layer.msg('聊天系统出错');
}, //失败回调; }, //失败回调;
}); });
}, },
...@@ -409,15 +412,16 @@ $(function () { ...@@ -409,15 +412,16 @@ $(function () {
// open,登录; // open,登录;
var options = { var options = {
apiUrl: WebIM.config.apiURL, apiUrl: WebIM.config.apiURL,
user: user, user: '18271408717',
pwd: password, pwd: '123456',
appKey: WebIM.config.appkey appKey: WebIM.config.appkey
}; };
try { try {
this.conn.open(options); this.conn.open(options);
} catch (e) { } catch (e) {
console.log('登入失败') console.log('登入失败');
layer.msg('登入失败');
} }
}, },
......
...@@ -134,8 +134,11 @@ ...@@ -134,8 +134,11 @@
/*** /***
* 获取省市区 * 获取省市区
*/ */
regionPcd: user_url + "/region/pcd" regionPcd: user_url + "/region/pcd",
/**环信通讯记录添加 */
addrecord: user_url + '/im/add/record',
/**环信通讯记录列表(最多显示30条最新的聊天记录) */
listrecord: user_url + '/im/list/record',
}; };
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
return apis; return apis;
......
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