|
|
@@ -3,106 +3,123 @@ window.debug = true;
|
|
|
// 记录聊天双方信息
|
|
|
var dataInfo = {};
|
|
|
|
|
|
-// 储存聊天的会话记录信息
|
|
|
-var sessions = {};
|
|
|
-
|
|
|
// 存储应用数据
|
|
|
var app = {};
|
|
|
+app.gid = undefined;
|
|
|
+// 储存聊天的会话记录信息
|
|
|
+app.sessions = {};
|
|
|
+// 聊天记录是否已经展开
|
|
|
+app.isShowRecord = false;
|
|
|
|
|
|
$(document).ready(ready);
|
|
|
|
|
|
-// 表情
|
|
|
-var faces = {
|
|
|
- "奋斗" : "14.gif",
|
|
|
- "坏笑" : "20.gif"
|
|
|
-};
|
|
|
-function formatFace(text) {
|
|
|
- return text.replace(/(\[(.{2})\])/gi, function() {
|
|
|
- var face = faces[arguments[2]];
|
|
|
- return face ? ('<img src="../../style/img/face/' + face + '"/>') : arguments[0];
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
function connectServer() {
|
|
|
// 连接XMPP服务器
|
|
|
- Client.connect(dataInfo.userId, dataInfo.certification);
|
|
|
+ Client.connect(app.userInfo.userId, app.userInfo.certification);
|
|
|
}
|
|
|
|
|
|
// 接收到<message>
|
|
|
-function onMessage(msg) {
|
|
|
-
|
|
|
- console.log('subscribe received message', msg);
|
|
|
+/**
|
|
|
+ * 处理接收到Message
|
|
|
+ *
|
|
|
+ * @param message 用户接收到的消息
|
|
|
+ */
|
|
|
+function onMessage(message) {
|
|
|
+ console.log('subscribe received message', message);
|
|
|
|
|
|
- var message = translateToObject(msg);
|
|
|
- if (message.body) {
|
|
|
- var fromUserId = message.body.fromUserId;
|
|
|
- // 显示接受到的消息
|
|
|
- if (fromUserId === dataInfo.contactId) {
|
|
|
- // 显示消息
|
|
|
- drawMessage(message.body, false);
|
|
|
- }
|
|
|
+ // 如果是当前会话,则直接显示消息
|
|
|
+ if (app.currentSession && message.senderInfo === app.currentSession.linkman) {
|
|
|
+ // 显示消息
|
|
|
+ drawMessage(message, false);
|
|
|
}
|
|
|
+
|
|
|
// 缓存消息
|
|
|
- saveMessageToLocal(message.body, false);
|
|
|
+ console.log(message);
|
|
|
+ if (message.senderInfo && message.receiverInfo) {
|
|
|
+ saveMessageToLocal(message, false);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户发送消息
|
|
|
+ *
|
|
|
+ * @param message 已填充的消息
|
|
|
+ */
|
|
|
+function sendMessage(message) {
|
|
|
+ if (!message) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
|
|
|
- // 发送回执,告诉发送端收到了消息
|
|
|
- Client.received(dataInfo.userId, Strophe.getBareJidFromJid(message.from), message.id);
|
|
|
+ if (Client.isConnected()) {
|
|
|
+ if (!message.receiver || message.receiver == '') {
|
|
|
+ alert("请输入联系人!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
+ message = Client.sendMessage(message);
|
|
|
+
|
|
|
+ // 显示消息
|
|
|
+ drawMessage(message || {}, true);
|
|
|
+ saveMessageToLocal(message, true);
|
|
|
+ $("#input-msg").empty();
|
|
|
+ } else {
|
|
|
+ alert("请先登录!");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
function activate() {
|
|
|
- var params = httpUtils.queryParams();
|
|
|
- params.enterprise = decodeURIComponent(params.enterprise);
|
|
|
- params.condition = 'userid';
|
|
|
+ app = httpUtils.queryParams() || {};
|
|
|
+
|
|
|
if (window.debug) {
|
|
|
- console.log('[DEBUG]Query Params', params);
|
|
|
+ console.log('[DEBUG]App Info', app);
|
|
|
}
|
|
|
|
|
|
onfire.on('chat.message', onMessage);
|
|
|
|
|
|
- dataService.get('/api/chat/infos', params, {}, function (data) {
|
|
|
- dataInfo = data;
|
|
|
- dataInfo.enterprise = params.enterprise;
|
|
|
-
|
|
|
- if (!dataInfo.contactId || dataInfo.contactId === '') {
|
|
|
- hiddenChatArea();
|
|
|
- } else {
|
|
|
- // 绘制标题
|
|
|
- drawTitle();
|
|
|
+ ChatService.queryChatInfoWhenUserVisitWebSite(app.gid, function (data) {
|
|
|
+ if (!data.success) {
|
|
|
+ console.log('Message', data.message);
|
|
|
+ return ;
|
|
|
}
|
|
|
|
|
|
- // 获取会话信息
|
|
|
- sessionService.loadSessionsWhenUserRefresh(dataInfo.userId, function (data) {
|
|
|
-
|
|
|
- var sessions = handlerSessionData(data);
|
|
|
+ app.userInfo = data.chatInfo.userInfo;
|
|
|
+ app.enterprise = data.chatInfo.enterprise;
|
|
|
+ app.groups = data.groups || [];
|
|
|
|
|
|
- createNewSession(sessions);
|
|
|
+ // 绘制用户信息
|
|
|
+ drawUserInfo();
|
|
|
|
|
|
- // 绘制会话列表
|
|
|
- drawSessionList(sessions);
|
|
|
-
|
|
|
- connectServer();
|
|
|
- }, function (error) {
|
|
|
- console.log(error);
|
|
|
+ // 绘制会话列表
|
|
|
+ app.sessions = handlerSessionData(data.sessions || []);
|
|
|
+ drawSessionList(app.sessions);
|
|
|
|
|
|
- connectServer();
|
|
|
- });
|
|
|
+ // 绘制会话区域
|
|
|
+ if (app.currentSession) {
|
|
|
+ drawTitle();
|
|
|
+ showChatArea();
|
|
|
+ handlerUnReadMessage();
|
|
|
+ }
|
|
|
|
|
|
- // 获取未读消息缓存
|
|
|
- messageService.loadReadableMessageWhenUserRead(dataInfo.contactId, dataInfo.userId, function (messages) {
|
|
|
- if (window.debug) {
|
|
|
- console.log('message.unread', messages);
|
|
|
- }
|
|
|
+ connectServer();
|
|
|
+ }, function (error) {
|
|
|
+ console.log(error);
|
|
|
+ window.location.href = '/';
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
- messages.forEach(function (message) {
|
|
|
- // 显示消息
|
|
|
- drawMessage(message, false);
|
|
|
- });
|
|
|
- }, function (error) {
|
|
|
- console.log(error);
|
|
|
- })
|
|
|
+function handlerUnReadMessage() {
|
|
|
+ // 获取未读消息缓存
|
|
|
+ messageService.loadReadableMessageWhenUserRead(app.currentSession.owner, app.currentSession.linkman, function (messages) {
|
|
|
+ if (window.debug) {
|
|
|
+ console.log('message.unread', messages);
|
|
|
+ }
|
|
|
|
|
|
+ // 显示消息
|
|
|
+ messages.forEach(function (message) {
|
|
|
+ drawMessage(message, message.style == 'SEND');
|
|
|
+ });
|
|
|
}, function (error) {
|
|
|
console.log(error);
|
|
|
});
|
|
|
@@ -112,61 +129,35 @@ function handlerSessionData(data) {
|
|
|
var sessions = {};
|
|
|
if (data && data.length > 0) {
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
- if (!data[i].relateUser || data[i].relateUser === '') {
|
|
|
+ if (!data[i].linkman || data[i].linkman === '') {
|
|
|
continue;
|
|
|
}
|
|
|
- if (!sessions[data[i].relateUser]) {
|
|
|
- sessions[data[i].relateUser] = data[i];
|
|
|
+ if (!sessions[data[i].linkman]) {
|
|
|
+ sessions[data[i].linkman] = data[i];
|
|
|
+ sessions[data[i].linkman].userInfo = sessions[data[i].linkman].linkmanInfo.userInfo;
|
|
|
+ sessions[data[i].linkman].enterprise = sessions[data[i].linkman].linkmanInfo.enterprise;
|
|
|
} else {
|
|
|
- if (sessions[data[i].relateUser].timeSend < data[i].timeSend) {
|
|
|
- sessions[data[i].relateUser] = data[i];
|
|
|
+ if (sessions[data[i].linkman].timeSend < data[i].timeSend) {
|
|
|
+ sessions[data[i].linkman] = data[i];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return sessions;
|
|
|
-}
|
|
|
-
|
|
|
-function createNewSession(sessions) {
|
|
|
- var session = {};
|
|
|
- if (!dataInfo.contactId || dataInfo.contactId === '') return ;
|
|
|
- if (sessions[dataInfo.contactId]) return ;
|
|
|
-
|
|
|
- session.own = dataInfo.userId;
|
|
|
- session.relateUser = dataInfo.contactId;
|
|
|
- session.contactUserName = dataInfo.contactName;
|
|
|
- session.fromUserId = dataInfo.contactId;
|
|
|
- session.timeSend = new Date().getTime() / 1000;
|
|
|
- session.content = '';
|
|
|
- session.read = true;
|
|
|
- sessions[dataInfo.contactId] = session;
|
|
|
-
|
|
|
- sessionService.persistSessionWhenUserSendMessage(session, function (session) {
|
|
|
- if (window.debug) {
|
|
|
- console.log('[DEBUG]Create Session', session);
|
|
|
+ // 获取当前会话
|
|
|
+ var current = false;
|
|
|
+ for (var property in sessions) {
|
|
|
+ if (sessions.hasOwnProperty(property) && sessions[property] && sessions[property].current) {
|
|
|
+ current = true;
|
|
|
+ app.currentSession = sessions[property] || {};
|
|
|
+ break ;
|
|
|
}
|
|
|
- }, function (error) {
|
|
|
- console.log('error', error);
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-function translateToObject(stanza) {
|
|
|
- var message = {},
|
|
|
- elements = stanza.getElementsByTagName('body');
|
|
|
-
|
|
|
- message.from = stanza.getAttribute('from');
|
|
|
- message.to = stanza.getAttribute('to');
|
|
|
- message.id = stanza.getAttribute('id');
|
|
|
- message.type = stanza.getAttribute('type');
|
|
|
-
|
|
|
- if (message.type === 'chat' && elements.length > 0) {
|
|
|
- message.body = $.parseJSON(elements[0].textContent);
|
|
|
}
|
|
|
|
|
|
- console.log(message);
|
|
|
-
|
|
|
- return message;
|
|
|
+ if (!current) {
|
|
|
+ delete app.currentSession;
|
|
|
+ }
|
|
|
+ return sessions;
|
|
|
}
|
|
|
|
|
|
function formatTime(timestamp) {
|
|
|
@@ -176,11 +167,22 @@ function formatTime(timestamp) {
|
|
|
month = '' + (date.getMonth() + 1),
|
|
|
day = '' + date.getDate();
|
|
|
if (month.length < 2) month = '0' + month;
|
|
|
- if (date.length < 2) day = '0' + day;
|
|
|
+ if (day.length < 2) day = '0' + day;
|
|
|
|
|
|
return [year, month, day].join('-');
|
|
|
}
|
|
|
|
|
|
+function formatHourTime(timestamp) {
|
|
|
+ if (timestamp == null) return '';
|
|
|
+ var date = new Date(timestamp * 1000),
|
|
|
+ hour = '' + date.getHours(),
|
|
|
+ minute = '' + date.getMinutes();
|
|
|
+ if (hour.length < 2) hour = '0' + hour;
|
|
|
+ if (minute.length < 2) minute = '0' + minute;
|
|
|
+
|
|
|
+ return [hour, minute].join(':');
|
|
|
+}
|
|
|
+
|
|
|
function formatFullTime(timestamp) {
|
|
|
if (timestamp == null) return '';
|
|
|
var date = new Date(timestamp * 1000),
|
|
|
@@ -191,7 +193,7 @@ function formatFullTime(timestamp) {
|
|
|
minute = '' + date.getMinutes(),
|
|
|
second = '' + date.getSeconds();
|
|
|
if (month.length < 2) month = '0' + month;
|
|
|
- if (date.length < 2) day = '0' + day;
|
|
|
+ if (day.length < 2) day = '0' + day;
|
|
|
if (hour.length < 2) hour = '0' + hour;
|
|
|
if (minute.length < 2) minute = '0' + minute;
|
|
|
if (second.length < 2) second = '0' + second;
|
|
|
@@ -199,12 +201,52 @@ function formatFullTime(timestamp) {
|
|
|
return [year, month, day].join('-') + ' ' + [hour, minute, second].join(':');
|
|
|
}
|
|
|
|
|
|
-function hiddenChatArea() {
|
|
|
+function showChatArea() {
|
|
|
+ $('#chat-area').show();
|
|
|
+}
|
|
|
+
|
|
|
+function hideChatArea() {
|
|
|
$('#chat-area').hide();
|
|
|
}
|
|
|
|
|
|
+function drawUserInfo() {
|
|
|
+ console.log('APP', app);
|
|
|
+ var str = '<div class="img"><img src="/style/img/photo01.png" /></div>' +
|
|
|
+ '<div class="content">' +
|
|
|
+ '<span><span>' + app.userInfo.name + '</span><div class="star-img-group"><img src="/style/img/star.png"><img src="/style/img/star.png"><img src="/style/img/star.png"></div></span>' +
|
|
|
+ '<p>';
|
|
|
+ if (app.enterprise){
|
|
|
+ str +=(app.enterprise.name);
|
|
|
+ }else {str +=('个人账户');}
|
|
|
+ str +=('</p></div>');
|
|
|
+
|
|
|
+ $('#member-title').html(str);
|
|
|
+/*<div class="title-icon"><img src="/style/img/zoomIn.png" alt=""> <img src="/style/img/close.png" alt=""> </div>*/
|
|
|
+}
|
|
|
+
|
|
|
function drawTitle() {
|
|
|
- $('#chat-title').html('<h3>' + (dataInfo.contactName && dataInfo.contactName !== '' ? dataInfo.contactName : dataInfo.contactId) + '</h3>');
|
|
|
+ var name = '';
|
|
|
+ if (app.currentSession) {
|
|
|
+ if (app.currentSession.linkmanInfo.enterprise != null){
|
|
|
+ // if ('ENTERPRISE' === app.currentSession.communicatorType) {
|
|
|
+ // name = app.currentSession.linkmanInfo.userInfo.name + '-' + app.currentSession.linkmanInfo.enterprise.name;
|
|
|
+ // } else {
|
|
|
+ name = app.currentSession.linkmanInfo.enterprise.name;
|
|
|
+ // }
|
|
|
+ }else{
|
|
|
+ name = '个人账户';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#chat-title').html('<h3 title="'+name +'(' +app.currentSession.linkmanInfo.userInfo.name.substring(0,1)+ '**)' +'">' + name + '(' + app.currentSession.linkmanInfo.userInfo.name.substring(0,1) + '**)</h3>');
|
|
|
+/*<div class="title-icon"><img src="/style/img/zoomIn.png" alt=""> <img src="/style/img/close.png" alt=""> </div>*/
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 清空聊天记录
|
|
|
+ */
|
|
|
+function clearMessage() {
|
|
|
+ $("#chat-receiver-log ul").empty();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -214,17 +256,31 @@ function drawTitle() {
|
|
|
* @param isSend 是否为发送消息
|
|
|
*/
|
|
|
function drawMessage(message, isSend) {
|
|
|
+ var userName = '';
|
|
|
|
|
|
- $('#chat-receiver-log').append('<dl>' +
|
|
|
- '<dt><img src="/style/img/photo01.jpg"/></dt>' +
|
|
|
- '<dd>' +
|
|
|
- '<p class="name">' + (isSend ? dataInfo.userName : dataInfo.contactName) + '</p>' +
|
|
|
- '<span class="time">' + formatFullTime(message.timeSend) + '</span>' +
|
|
|
- '<p>' + message.content + '</p>' +
|
|
|
- '</dd>' +
|
|
|
- '</dl>');
|
|
|
-
|
|
|
- var height = $('#chat-receiver-log')[0].scrollHeight - $("#chat-receiver-log")[0].clientHeight;
|
|
|
+ /*if (!isSend) {
|
|
|
+ if (message.senderType === 'STORE') {
|
|
|
+ userName = app.currentSession.enterprise.name;
|
|
|
+ }
|
|
|
+ if (message.senderType === 'ENTERPRISE') {
|
|
|
+ userName = app.currentSession.userInfo.name + '-' + app.currentSession.enterprise.name;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ userName = app.userInfo.name;
|
|
|
+ }*/ //暂时没用到这个userName
|
|
|
+
|
|
|
+ console.log(message.content)
|
|
|
+ $('#chat-receiver-log ul').append('<li class="chat-log ' + (isSend ? 'chat-log-send' : 'chat-log-receive') + '">' +
|
|
|
+ '<div class="chat-log-avatar">' +
|
|
|
+ '<img src="/style/img/photo01.png" alt="头像"></img>' +
|
|
|
+ '</div>' +
|
|
|
+ '<div class="chat-log-text">' +
|
|
|
+ message.content +
|
|
|
+ '</div>' +
|
|
|
+ '<div class="clearfix"></div>' +
|
|
|
+ '</li>');
|
|
|
+
|
|
|
+ var height = $('#chat-receiver-log')[0].scrollHeight;
|
|
|
|
|
|
$("#chat-receiver-log").animate({
|
|
|
scrollTop : height
|
|
|
@@ -233,19 +289,54 @@ function drawMessage(message, isSend) {
|
|
|
|
|
|
function drawSessionList(sessions) {
|
|
|
$('#session-list .list-group').text('');
|
|
|
+ // $('#session-list .list-group2').text('');
|
|
|
for (var property in sessions) {
|
|
|
+ if (sessions[property].isBlack){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if (sessions.hasOwnProperty(property) && sessions[property]) {
|
|
|
|
|
|
- $('#session-list .list-group').append('<dl class="' + (sessions[property].relateUser === dataInfo.contactId ? ' active' : '' ) + '">' +
|
|
|
- '<a href="/chat/sample?from=' + sessions[property].own + '&to=' + sessions[property].relateUser + '">' +
|
|
|
- '<dt><img src="/style/img/photo01.jpg"/></dt>' +
|
|
|
- '<dd>' +
|
|
|
- '<span class="name">' + (sessions[property].contactUserName && sessions[property].contactUserName !== '' ? sessions[property].contactUserName : sessions[property].relateUser) + '</span>' +
|
|
|
- '<span class="time">' + formatTime(sessions[property].timeSend) + '</span>' +
|
|
|
- '</dd>' +
|
|
|
- '<dd class="record">' + sessions[property].content + '</dd>' +
|
|
|
- '</a>' +
|
|
|
- '</dl>');
|
|
|
+ var sessionStyle = '', record = '';
|
|
|
+ if (!sessions[property].read) {
|
|
|
+ //sessionStyle = 'bg-warning';
|
|
|
+ }
|
|
|
+ if (app.currentSession && app.currentSession.linkman && app.currentSession.linkman !== '') {
|
|
|
+ if (sessions[property].id === app.currentSession.id) {
|
|
|
+ sessionStyle = 'active';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sessions[property].type == 1) {
|
|
|
+ record = sessions[property].content.replace(/<img class="emoji_icon".*?>/, '[表情]');
|
|
|
+ } else if (sessions[property].type == 2) {
|
|
|
+ record = '[图片]';
|
|
|
+ } else if (sessions[property].type == 3) {
|
|
|
+ record = '[文件]';
|
|
|
+ }
|
|
|
+
|
|
|
+ var flag = "'" + sessions[property].linkman + "'";
|
|
|
+ var enStr;
|
|
|
+ if(sessions[property].enterprise == null){
|
|
|
+ enStr = '个人账户'+'('+sessions[property].userInfo.name.substring(0,1)+"**)";
|
|
|
+ }else{
|
|
|
+ enStr = sessions[property].enterprise.name+'('+sessions[property].userInfo.name.substring(0,1)+"**)";
|
|
|
+ }
|
|
|
+ var listStr = '<dl class="' + sessionStyle + '">' +
|
|
|
+ '<a href="javascript:void(0);" onclick="switchNewSession(' + flag + ')">' +
|
|
|
+ // '<dt><em>寄售</em><img src="/style/img/photo01.png"/></dt>' +
|
|
|
+ '<dt><img src="/style/img/photo01.png"/></dt>' +
|
|
|
+ '<dd>' +
|
|
|
+ '<span class="name" title="'+enStr+'">' + enStr + '</span>' +
|
|
|
+ '<span class="time">' + formatHourTime(sessions[property].timeSend) + '</span>' +
|
|
|
+ '</dd>' +
|
|
|
+ '<dd class="record">' + (sessions[property].content.substring(0, 4) == '<img' ? '[图片]' : sessions[property].content);
|
|
|
+ console.log(sessions[property].read);
|
|
|
+ listStr += '</dd>';
|
|
|
+ if (!sessions[property].read) { //未读信息加上标志
|
|
|
+ listStr += '<i></i>';
|
|
|
+ }
|
|
|
+ listStr += '</a></dl>';
|
|
|
+ $('#session-list .list-group').append(listStr);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -260,17 +351,20 @@ function saveMessageToLocal(stanza, isMySend) {
|
|
|
console.log('message.body', stanza);
|
|
|
|
|
|
if (isMySend === null || isMySend === undefined) {
|
|
|
- isMySend = stanza.sender === dataInfo.userId;
|
|
|
+ isMySend = stanza.senderInfo === app.currentSession.owner;
|
|
|
}
|
|
|
|
|
|
- stanza.own = dataInfo.userId;
|
|
|
+ stanza.own = app.gid;
|
|
|
stanza.mySend = isMySend;
|
|
|
stanza.style = isMySend ? 'SEND' : 'RECEIVE';
|
|
|
- if (isMySend || (!isMySend && stanza.sender === dataInfo.contactId)) {
|
|
|
+ if (isMySend || (!isMySend && app.currentSession && stanza.senderInfo === app.currentSession.linkman)) {
|
|
|
stanza.read = true;
|
|
|
} else {
|
|
|
stanza.read = false;
|
|
|
}
|
|
|
+ if (stanza.style === 'RECEIVE'){
|
|
|
+ stanza.id = stanza.uuid;
|
|
|
+ }
|
|
|
|
|
|
// 缓存消息
|
|
|
messageService.cacheMessageWhenClientReceive(stanza, function (sessions) {
|
|
|
@@ -278,10 +372,9 @@ function saveMessageToLocal(stanza, isMySend) {
|
|
|
console.log('[DEBUG]Update Sessions:', sessions);
|
|
|
}
|
|
|
|
|
|
- // 处理会话数据
|
|
|
- var handlerSessions = handlerSessionData(sessions);
|
|
|
// 绘制会话列表
|
|
|
- drawSessionList(handlerSessions);
|
|
|
+ app.sessions = handlerSessionData(sessions);
|
|
|
+ drawSessionList(app.sessions);
|
|
|
}, function (error) {
|
|
|
console.log('Cache Fail', error);
|
|
|
});
|
|
|
@@ -290,26 +383,106 @@ function saveMessageToLocal(stanza, isMySend) {
|
|
|
function ready() {
|
|
|
activate();
|
|
|
|
|
|
- $('#input-msg').emoji({
|
|
|
- button: "#show-emoji",
|
|
|
- showTab: false,
|
|
|
- animation: 'slide',
|
|
|
- icons: [{
|
|
|
- name: "QQ表情",
|
|
|
- path: "/style/img/qq/",
|
|
|
- maxNum: 91,
|
|
|
- excludeNums: [41, 45, 54],
|
|
|
- file: ".gif"
|
|
|
- }]
|
|
|
+ // // 添加Emoji
|
|
|
+ // $('#input-msg').emoji({
|
|
|
+ // button: "#show-emoji",
|
|
|
+ // showTab: false,
|
|
|
+ // animation: 'slide',
|
|
|
+ // icons: [{
|
|
|
+ // name: "QQ表情",
|
|
|
+ // path: "/style/img/qq/",
|
|
|
+ // maxNum: 91,
|
|
|
+ // excludeNums: [41, 45, 54],
|
|
|
+ // file: ".gif"
|
|
|
+ // }]
|
|
|
+ // });
|
|
|
+
|
|
|
+ // 点击回车发送消息
|
|
|
+ $('#input-msg').keydown(function (event) {
|
|
|
+ if (event.keyCode == 13) {
|
|
|
+ clickSendMessage();
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
+ // 点击回车发送消息后,清除换行字符
|
|
|
+ $('#input-msg').keyup(function (event) {
|
|
|
+ console.log(event.keyCode);
|
|
|
+ if (event.keyCode == 13) {
|
|
|
+ $("#input-msg").empty();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 处理复制内容转化成文本内容
|
|
|
+ $('[contenteditable]').each(function() {
|
|
|
+ // 干掉IE http之类地址自动加链接
|
|
|
+ try {
|
|
|
+ document.execCommand("AutoUrlDetect", false, false);
|
|
|
+ } catch (e) {}
|
|
|
+
|
|
|
+ $(this).on('paste', function(e) {
|
|
|
+
|
|
|
+ var text = null;
|
|
|
+
|
|
|
+ if(window.clipboardData && clipboardData.setData) {
|
|
|
+ // IE
|
|
|
+ text = window.clipboardData.getData('text');
|
|
|
+ } else {
|
|
|
+ text = (e.originalEvent || e).clipboardData.getData('text/plain') ||
|
|
|
+ (e.originalEvent || e).clipboardData.getData('image');
|
|
|
+ }
|
|
|
+ // 如果获取不到文本内容,可能是图片等,直接返回
|
|
|
+ if (!text) return;
|
|
|
+ // 获取到文本内容,将文本内容添加进入输入框
|
|
|
+ e.preventDefault();
|
|
|
+ if (document.body.createTextRange) {
|
|
|
+ if (document.selection) {
|
|
|
+ textRange = document.selection.createRange();
|
|
|
+ } else if (window.getSelection) {
|
|
|
+ sel = window.getSelection();
|
|
|
+ var range = sel.getRangeAt(0);
|
|
|
+
|
|
|
+ // 创建临时元素,使得TextRange可以移动到正确的位置
|
|
|
+ var tempEl = document.createElement("span");
|
|
|
+ tempEl.innerHTML = "&#FEFF;";
|
|
|
+ range.deleteContents();
|
|
|
+ range.insertNode(tempEl);
|
|
|
+ textRange = document.body.createTextRange();
|
|
|
+ textRange.moveToElementText(tempEl);
|
|
|
+ tempEl.parentNode.removeChild(tempEl);
|
|
|
+ }
|
|
|
+ textRange.text = text;
|
|
|
+ textRange.collapse(false);
|
|
|
+ textRange.select();
|
|
|
+ } else {
|
|
|
+ // Chrome之类浏览器
|
|
|
+ document.execCommand("insertText", false, text);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 去除Crtl+b/Ctrl+i/Ctrl+u等快捷键
|
|
|
+ $(this).on('keydown', function(e) {
|
|
|
+ // e.metaKey for mac
|
|
|
+ if (e.ctrlKey || e.metaKey) {
|
|
|
+ switch(e.keyCode){
|
|
|
+ case 66: //ctrl+B or ctrl+b
|
|
|
+ case 98:
|
|
|
+ case 73: //ctrl+I or ctrl+i
|
|
|
+ case 105:
|
|
|
+ case 85: //ctrl+U or ctrl+u
|
|
|
+ case 117: {
|
|
|
+ e.preventDefault();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
// 发送消息
|
|
|
$("#btn-send").click(clickSendMessage);
|
|
|
|
|
|
// 关闭聊天窗口
|
|
|
- $("#btn-close").click(function () {
|
|
|
- window.location.href = '/chat/sample?from=' + dataInfo.userId;
|
|
|
- });
|
|
|
+ $("#btn-close").click(closeChatArea);
|
|
|
|
|
|
// 上传图片
|
|
|
$('#upload-image-btn').click(function () {
|
|
|
@@ -318,49 +491,81 @@ function ready() {
|
|
|
});
|
|
|
|
|
|
// 上传图片获取图片信息
|
|
|
- $('#upload-image').change(uploadImage)
|
|
|
-}
|
|
|
+ $('#upload-image').change(uploadImage);
|
|
|
|
|
|
-function sendMessage(content) {
|
|
|
- if (!content || content === '') {
|
|
|
- return ;
|
|
|
- }
|
|
|
+ // 显示聊天历史
|
|
|
+ $('#show-chat-record').click(showChatRecord);
|
|
|
|
|
|
- if (Client.isConnected()) {
|
|
|
- if (!dataInfo.contactId || dataInfo.contactId == '') {
|
|
|
- alert("请输入联系人!");
|
|
|
- return;
|
|
|
- }
|
|
|
+ $('#close-chat-record').click(showChatRecord);
|
|
|
+}
|
|
|
|
|
|
- var msg = Client.sendMessage(dataInfo.userId, dataInfo.contactId, content);
|
|
|
+/**
|
|
|
+ * 点击发送按钮,发送消息
|
|
|
+ */
|
|
|
+function clickSendMessage() {
|
|
|
+ console.log(1);
|
|
|
|
|
|
- if (msg) {
|
|
|
- console.log(msg.tree().outerHTML);
|
|
|
- var message = translateToObject(msg.tree());
|
|
|
- console.log('1-message', message.body || {});
|
|
|
+ var message = new Message();
|
|
|
+ message.type = 1;
|
|
|
+ message.senderInfo = app.currentSession.owner;
|
|
|
+ message.receiverInfo = app.currentSession.linkman;
|
|
|
+ message.senderType = app.currentSession.communicatorType;
|
|
|
|
|
|
- // 显示消息
|
|
|
- drawMessage(message.body || {}, true);
|
|
|
+ message.sender = app.userInfo.userId;
|
|
|
+ message.receiver = app.currentSession.userInfo.userId;
|
|
|
+ message.content = $("#input-msg").html();
|
|
|
+ message.uuid = guid();
|
|
|
|
|
|
- saveMessageToLocal(message.body, true);
|
|
|
- }
|
|
|
+ if (!message.content || message.content === '') {
|
|
|
+ $("#input-msg").empty();
|
|
|
+ return ;
|
|
|
+ }
|
|
|
|
|
|
- $("#input-msg").text('');
|
|
|
- } else {
|
|
|
- alert("请先登录!");
|
|
|
+ if (window.debug) {
|
|
|
+ console.log('[DEBUG]Send Message', message);
|
|
|
}
|
|
|
+
|
|
|
+ sendMessage(message);
|
|
|
}
|
|
|
|
|
|
+//用于生成uuid
|
|
|
+function S4() {
|
|
|
+ return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
|
|
+}
|
|
|
+function guid() {
|
|
|
+ return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
|
|
|
+}
|
|
|
/**
|
|
|
- * 点击发送按钮,发送消息
|
|
|
+ * 发送图片
|
|
|
+ *
|
|
|
+ * @param url 图片URL
|
|
|
*/
|
|
|
-function clickSendMessage() {
|
|
|
- var content = $("#input-msg").html();
|
|
|
+function sendImage(url) {
|
|
|
+
|
|
|
+ var message = new Message();
|
|
|
+ message.type = 2;
|
|
|
+ message.senderInfo = app.currentSession.owner;
|
|
|
+ message.receiverInfo = app.currentSession.linkman;
|
|
|
+ message.senderType = app.currentSession.communicatorType;
|
|
|
+
|
|
|
+ message.sender = app.userInfo.userId;
|
|
|
+ message.receiver = app.currentSession.userInfo.userId;
|
|
|
+ message.content = '<img ondblclick="previewImg(''+ url + '')" class="content-image" src="' + (url || '') + '"/>';
|
|
|
+ message.uuid = guid();
|
|
|
|
|
|
if (window.debug) {
|
|
|
- console.log('[DEBUG]Send Message', content);
|
|
|
+ console.log('[DEBUG]Send Message', message.content);
|
|
|
}
|
|
|
- sendMessage(content);
|
|
|
+
|
|
|
+ sendMessage(message);
|
|
|
+}
|
|
|
+
|
|
|
+function previewImg(url) {
|
|
|
+ $('#preview-img img').attr('src', url);
|
|
|
+ $('#preview-img').show();
|
|
|
+}
|
|
|
+function closePreview() {
|
|
|
+ $('#preview-img').hide();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -368,7 +573,6 @@ function clickSendMessage() {
|
|
|
*/
|
|
|
function uploadImage() {
|
|
|
var file = $('#upload-image')[0].files[0];
|
|
|
- console.log(file);
|
|
|
|
|
|
if (file) {
|
|
|
var fileSize = 0;
|
|
|
@@ -378,20 +582,508 @@ function uploadImage() {
|
|
|
fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
|
|
|
}
|
|
|
|
|
|
- console.log('File Information', fileSize);
|
|
|
+ // console.log('File Information', fileSize);
|
|
|
|
|
|
var formData = new FormData();
|
|
|
formData.append('file', file);
|
|
|
|
|
|
+ var fileObj = $("#upload-image")
|
|
|
+ $('#loading').show();
|
|
|
FileService.uploadImage(formData, function (data) {
|
|
|
- console.log(data);
|
|
|
- var content = '<img src="' + data + '"/>';
|
|
|
- // $("#input-msg").html(content);
|
|
|
- sendMessage(content);
|
|
|
- $('#upload-image')[0].files[0] = [];
|
|
|
+ sendImage(data);
|
|
|
+ $('#loading').hide();
|
|
|
+ fileObj.val("")
|
|
|
}, function (error) {
|
|
|
+ $('#loading').hide();
|
|
|
console.log(error);
|
|
|
- $('#upload-image')[0].files[0] = [];
|
|
|
+ fileObj.val("");
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+function drawHistoryMessage(message, isSend) {
|
|
|
+ var name = '', enterpriseName = '', classStyle = '';
|
|
|
+
|
|
|
+ if (!isSend) {
|
|
|
+ name = app.currentSession.userInfo.name;
|
|
|
+ enterpriseName = app.currentSession.enterprise?app.currentSession.enterprise.name:'个人帐号';
|
|
|
+ } else {
|
|
|
+ name = app.userInfo.name;
|
|
|
+ enterpriseName = app.enterprise?app.enterprise.name:'个人帐号';
|
|
|
+ classStyle = 'customer';
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#chat-record>ul').prepend('<li class="' + classStyle + '">' +
|
|
|
+ '<p>' + name.substring(0,1)+'**' + ' ( ' + enterpriseName + ' ) ' + '<time>' + formatFullTime(message.timeSend) + '</time></p>' +
|
|
|
+ '<p class="content">' + message.content + '</p>' +
|
|
|
+ '</li>');
|
|
|
+}
|
|
|
+
|
|
|
+function loadHistoryMessage(max, min) {
|
|
|
+ messageService.loadHistoryMessage(app.gid, app.currentSession.linkman, max, min, function (messages) {
|
|
|
+ app.history = messages;
|
|
|
+ if (messages && messages.length > 0) {
|
|
|
+ messages.forEach(function (message) {
|
|
|
+ drawHistoryMessage(message, message.style === 'SEND');
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var record = $('#chat-record ul')[0];
|
|
|
+ var lastRecord = $('#chat-record ul li:last-child').height();
|
|
|
+ var height = record.scrollHeight + lastRecord;
|
|
|
+
|
|
|
+ console.log(height);
|
|
|
+ $("#chat-record ul").animate({
|
|
|
+ scrollTop : height
|
|
|
+ }, 0);
|
|
|
+
|
|
|
+ // 绘制聊天历史记录
|
|
|
+ }, function (error) {
|
|
|
+ console.log(error);
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 显示聊天历史信息
|
|
|
+ */
|
|
|
+function showChatRecord() {
|
|
|
+ if (!app.isShowRecord) {
|
|
|
+ app.isShowRecord = true;
|
|
|
+ $('.col-md-8 >.row').css('right','232px');
|
|
|
+ $('#chat-send-area').css('right','217px');
|
|
|
+ $('#chat-record').show();
|
|
|
+ $('#chat-area').css({'width':'391px'});
|
|
|
+ $('#show-chat-record').html('<img src="/style/img/icon04.png"/> 关闭聊天记录');
|
|
|
+ $('#show-chat-record').css('color', 'red');
|
|
|
+ $('#chat-record>ul').html('');
|
|
|
+
|
|
|
+ var max = Math.round(new Date().getTime() / 1000) - (60 * 60 * 24);
|
|
|
+ loadHistoryMessage(max, null);
|
|
|
+ } else {
|
|
|
+ app.isShowRecord = false;
|
|
|
+ $('.col-md-8 >.row').css('right','15px');
|
|
|
+ $('#chat-send-area').css('right','0');
|
|
|
+ $('#chat-record').hide();
|
|
|
+ $('#chat-area').css({'width':'609px'});
|
|
|
+ $('#show-chat-record').html('<img src="/style/img/icon04.png"/> 聊天记录');
|
|
|
+ $('#show-chat-record').css('color', '#337ab7');
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 开启新的会话
|
|
|
+ */
|
|
|
+function switchNewSession(communicator) {
|
|
|
+// console.log(communicator);
|
|
|
+ if (!communicator || communicator === '') return ;
|
|
|
+
|
|
|
+ var session = app.sessions[communicator];
|
|
|
+
|
|
|
+ sessionService.updateSessionStateWhenUserSwitchNewSession(session.id, function (sessions) {
|
|
|
+ // 绘制会话列表
|
|
|
+ app.sessions = handlerSessionData(sessions || []);
|
|
|
+ drawSessionList(app.sessions);
|
|
|
+
|
|
|
+ // 绘制会话区域
|
|
|
+ if (app.currentSession) {
|
|
|
+ drawTitle();
|
|
|
+ showChatArea();
|
|
|
+ clearMessage();
|
|
|
+ handlerUnReadMessage();
|
|
|
+ }
|
|
|
+ }, function (error) {
|
|
|
+ console.log(error);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function closeChatArea() {
|
|
|
+ delete app.currentSession;
|
|
|
+
|
|
|
+ hideChatArea();
|
|
|
+ drawSessionList(app.sessions);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 加载分组数据
|
|
|
+ * */
|
|
|
+function reloadData(flag) {
|
|
|
+ ChatService.queryChatInfoWhenUserVisitWebSite(app.gid, function (data) {
|
|
|
+ if (!data.success) {
|
|
|
+ console.log('Message', data.message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ app.userInfo = data.chatInfo.userInfo;
|
|
|
+ app.enterprise = data.chatInfo.enterprise;
|
|
|
+ app.groups = data.groups || [];
|
|
|
+ app.sessions = handlerSessionData(data.sessions || []);
|
|
|
+ // drawSessionList(app.sessions);
|
|
|
+ if (flag) {
|
|
|
+ toSingleList();
|
|
|
+ } else {
|
|
|
+ toDoubleList();
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 分组列表展示
|
|
|
+* */
|
|
|
+function drawSessionGroup() {
|
|
|
+ // $('#session-list .list-group').text('');
|
|
|
+ $('#session-list .list-group2').text('');
|
|
|
+ var tempStr = '<ul class="group-list">';
|
|
|
+ app.groups.forEach(function (item, index) {
|
|
|
+ if (item.chatSessionList == null){
|
|
|
+ tempStr += '<li><div onmousedown="onGroupMenu(event,' + index + ')" onclick="showDetailList(' + index +')"><img src="/style/img/arrow-right.png" alt=""/><span>'
|
|
|
+ + item.groupName + ' (0)</span></div></li>';
|
|
|
+ }else {
|
|
|
+ tempStr += '<li><div onmousedown="onGroupMenu(event,' + index + ')" onclick="showDetailList(' + index +')"><img src="/style/img/arrow-right.png" alt=""/><span>'
|
|
|
+ + item.groupName + ' ('+item.chatSessionList.length +')</span></div></li>';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#session-list .list-group2').append(tempStr);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 分组详细列表
|
|
|
+ * */
|
|
|
+function showDetailList(index) {
|
|
|
+ var temp_index = parseInt(index) + 1;
|
|
|
+ var tempEl = $('#session-list .list-group2 .group-list >li:nth-child(' + temp_index + ')');
|
|
|
+ if (tempEl.find('ul').length == 0) {
|
|
|
+ var tempStr = '<ul class="group-item-list">';
|
|
|
+ if (app.groups[index].chatSessionList) {
|
|
|
+ app.groups[index].chatSessionList.forEach(function (item, item_index) {
|
|
|
+ var id = "'" + item.linkman + "'";
|
|
|
+ if (item.linkmanInfo.enterprise && item.linkmanInfo.enterprise!=null){
|
|
|
+ tempStr += '<li onmousedown="onLinkmanMenu(event,'+index+','+item_index+')" onclick="switchNewSession(' +id + ')"><span title="'+item.linkmanInfo.enterprise.name +'('+item.linkmanInfo.userInfo.name.substring(0,1)+'**)">' + item.linkmanInfo.enterprise.name +'('+item.linkmanInfo.userInfo.name.substring(0,1)+'**)</span></li>';
|
|
|
+ }else{
|
|
|
+ tempStr += '<li onmousedown="onLinkmanMenu(event,'+index+','+item_index+')" onclick="switchNewSession(' +id + ')"><span title="个人账户('+item.linkmanInfo.userInfo.name.substring(0,1)+'**)">个人账户('+item.linkmanInfo.userInfo.name.substring(0,1)+'**)</span></li>';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tempStr += '</ul>';
|
|
|
+ tempEl.append(tempStr);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ tempEl.find('ul').remove()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 转换显示列表为最近联系人
|
|
|
+ * */
|
|
|
+function toSingleList() {
|
|
|
+ drawSessionList(app.sessions);
|
|
|
+ $('#session-list .list-group').show();
|
|
|
+ $('#session-list .list-group2').hide();
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 转换显示列表为分组
|
|
|
+ * */
|
|
|
+function toDoubleList() {
|
|
|
+ drawSessionGroup();
|
|
|
+ $('#session-list .list-group').hide();
|
|
|
+ $('#session-list .list-group2').show();
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 转换显示列表
|
|
|
+* */
|
|
|
+function changeSelectList(type, e) {
|
|
|
+ var flag = type == 'single' ? true : false;
|
|
|
+ var left = $(e.target).parent()[0].firstElementChild;
|
|
|
+ var right = $(e.target).parent()[0].lastElementChild;
|
|
|
+ left.setAttribute('class', flag ? 'single active' : 'single');
|
|
|
+ left.firstElementChild.setAttribute('src', flag ? '/style/img/single-active.png' : '/style/img/single.png');
|
|
|
+ right.setAttribute('class', !flag ? 'double active' : 'double');
|
|
|
+ right.firstElementChild.setAttribute('src', !flag ? '/style/img/double-active.png' : '/style/img/double.png');
|
|
|
+ reloadData(flag);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 右键分组菜单
|
|
|
+ * */
|
|
|
+function onGroupMenu(event, index) {
|
|
|
+ hideGroupListMenu();
|
|
|
+ $('.linkman-menu').hide();
|
|
|
+ if (event.button == 2) {
|
|
|
+ document.oncontextmenu = function () {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var groupName = app.groups[index].groupName;
|
|
|
+
|
|
|
+ var x = event.pageX;
|
|
|
+ var y = event.pageY;
|
|
|
+ $('.group-menu').attr('style', 'top: ' + y + 'px; left: ' + x + 'px;');
|
|
|
+ $('.group-menu li').attr('name', index);
|
|
|
+ if ('我的好友' == groupName){
|
|
|
+ $('.group-menu .delete-group').hide();
|
|
|
+ }else {
|
|
|
+ $('.group-menu .delete-group').show();
|
|
|
+ }
|
|
|
+ $('.group-menu').show();
|
|
|
+ $(document).click(function () {
|
|
|
+ $('.group-menu').hide();
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 右键联系人操作菜单
|
|
|
+ * */
|
|
|
+function onLinkmanMenu(event, index, item_index) {
|
|
|
+ hideGroupMenu();
|
|
|
+ if (event.button == 2) {
|
|
|
+ document.oncontextmenu = function () {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var x = event.pageX;
|
|
|
+ var y = event.pageY;
|
|
|
+ var deleteObj = $('.linkman-menu >li:nth-child(2)');
|
|
|
+ var toBlackObj = $('.linkman-menu >li:nth-child(3)');
|
|
|
+ $('.linkman-menu').attr('style', 'top: ' + y + 'px; left: ' + x + 'px;');
|
|
|
+ var groupName = app.groups[index].groupName;
|
|
|
+ if ('我的好友' == groupName){
|
|
|
+ $('.linkman-menu .delete-linkman').hide();
|
|
|
+ }else {
|
|
|
+ $('.linkman-menu .delete-linkman').show();
|
|
|
+ }
|
|
|
+ $('.linkman-menu').show();
|
|
|
+ $('.linkman-menu >li:first-child').attr('onmouseenter','showGroupList(event,' + index +',' + item_index + ')');
|
|
|
+ deleteObj.attr('onclick', 'selectLinkmanMenuItem(event, "2",' + index + ',' + item_index +')');
|
|
|
+ deleteObj.attr('onmouseenter', 'hideGroupListMenu()');
|
|
|
+ toBlackObj.attr('onclick', 'selectLinkmanMenuItem(event, "3",' + index + ',' + item_index +')');
|
|
|
+ toBlackObj.attr('onmouseenter', 'hideGroupListMenu()');
|
|
|
+ $(document).click(function () {
|
|
|
+ $('.linkman-menu').hide();
|
|
|
+ $('.group-list-menu').hide();
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 分组列表菜单展示
|
|
|
+ * */
|
|
|
+function showGroupList(event, index, item_index) {
|
|
|
+ var obj = $('.group-list-menu');
|
|
|
+ obj.text('');
|
|
|
+ var str = '';
|
|
|
+ var type = 1;
|
|
|
+ if (app.groups) {
|
|
|
+ app.groups.forEach(function (item) {
|
|
|
+ str += '<li onclick="selectLinkmanMenuItem(event,'+ type + ',' + index + ','+item_index+')">' + item.groupName + '</li>'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ var x = $(event.target).parent().css('left');
|
|
|
+ var y = $(event.target).parent().css('top');
|
|
|
+
|
|
|
+ obj.append(str);
|
|
|
+ obj.css({'top': y, 'left': parseInt(x.substring(0, x.length-2)) + 145 + 'px'});
|
|
|
+ obj.show();
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 分组菜单选择
|
|
|
+ * */
|
|
|
+function selectGroupMenuItem(e, type) {
|
|
|
+ var ownid = app.gid;
|
|
|
+ var index = $(e.target).attr('name');
|
|
|
+ var groupName = app.groups[index].groupName;
|
|
|
+ if (type == 'add') {
|
|
|
+ var str = '<li><div><img src="/style/img/arrow-right.png" alt=""><input type="text" onkeyup="onAddGroup(event)" onblur="onAddGroup(event)" placeholder="请输入分组名称" /></div></li>'
|
|
|
+ $('#session-list .list-group2 .group-list').append(str);
|
|
|
+ $('#session-list .list-group2 .group-list >li:last-child >div > input').focus();
|
|
|
+ } else if (type == 'rename') {
|
|
|
+ var list_index = parseInt(index) +1;
|
|
|
+ var tempEl = '#session-list .list-group2 .group-list >li:nth-child(' + list_index + ')';
|
|
|
+ var str = '<input type="text" onkeyup="onRenameGroup(event,' + index +')" onblur="onRenameGroup(event,' + index +')" placeholder="' + groupName + '" />'
|
|
|
+ $(tempEl + '>div >span').hide();
|
|
|
+ $(tempEl + '>div').append(str);
|
|
|
+ $(tempEl + '>div >input').focus();
|
|
|
+ } else if (type === 'remove') {
|
|
|
+ if (app.groups[index].groupName === '我的好友') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $('.remind-box').text('');
|
|
|
+ var str = '<div class="box-header"><img onclick="hideRemindBox()" src="/style/img/remind-box-del.png" alt="" /></div>';
|
|
|
+ str += '<div class="box-title"><span>!</span><span>是否要删除该分组?</span><div>选定的分组将会被删除,组内联系人将会移至系统默认分组“我的好友。</div></div>';
|
|
|
+ str += '<div class="box-btn"> <span onclick="hideRemindBox()">取消</span> <span onclick="submitDeleteGroupAction('+ index + ')">确定</span></div>';
|
|
|
+ $('.remind-box').append(str);
|
|
|
+ $('.remind-box').show();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 联系人菜单选择
|
|
|
+ * type:
|
|
|
+ * 1:移动联系人
|
|
|
+ * 2:删除联系人
|
|
|
+ * 3:加入黑名单
|
|
|
+ * */
|
|
|
+
|
|
|
+function selectLinkmanMenuItem(event, type, index, item_index) {
|
|
|
+ var chatSessionId = app.groups[index].chatSessionList[item_index].id;
|
|
|
+ var name = app.groups[index].chatSessionList[item_index].linkmanInfo.userInfo.name;
|
|
|
+ var ownid = app.gid;
|
|
|
+ var fromGroupName = app.groups[index].groupName;
|
|
|
+ if (type == 1) {
|
|
|
+ var toGroupName = $(event.target).text()
|
|
|
+ groupService.moveToGroup(chatSessionId, ownid, fromGroupName, toGroupName, function (data) {
|
|
|
+ reloadData();
|
|
|
+ drawSessionGroup();
|
|
|
+ },function (error) {
|
|
|
+
|
|
|
+ })
|
|
|
+ } else if (type == 2) {
|
|
|
+ $('.remind-box').text('');
|
|
|
+ var str = '<div class="box-header"><img onclick="hideRemindBox()" src="/style/img/remind-box-del.png" alt="" /></div>';
|
|
|
+ str += '<div class="box-title"><span>!</span><span>删除后对方将从联系人列表中消失。</span></div>';
|
|
|
+ str += '<div class="box-info"> <img src="/style/img/photo01.png" alt="" /><span>' + name.substring(0,1)+'**' +'</span> </div>';
|
|
|
+ str += '<div class="box-btn"> <span onclick="hideRemindBox()">取消</span> <span onclick="submitDeleteAction('+ index + ',' + item_index + ')">确定</span></div>';
|
|
|
+ $('.remind-box').append(str);
|
|
|
+ $('.remind-box').show();
|
|
|
+ } else if (type == 3) {
|
|
|
+ $('.remind-box').text('');
|
|
|
+ var str = '<div class="box-header"><img onclick="hideRemindBox()" src="/style/img/remind-box-del.png" alt="" /></div>';
|
|
|
+ str += '<div class="box-title"><span>!</span><span>确认将该联系人加入至黑名单吗?</span><div>移至黑名单后将无法接收此人会话消息。</div></div>';
|
|
|
+ str += '<div class="box-info"> <img src="/style/img/photo01.png" alt="" /><span>' + name.substring(0,1)+'**' +'</span> </div>';
|
|
|
+ str += '<div class="box-btn"> <span onclick="hideRemindBox()">取消</span> <span onclick="submitBlackAction('+ index + ',' + item_index + ')">确定</span></div>';
|
|
|
+ $('.remind-box').append(str);
|
|
|
+ $('.remind-box').show();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 隐藏分组菜单
|
|
|
+ * */
|
|
|
+function hideRemindBox() {
|
|
|
+ $('.remind-box').hide();
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 确认删除分组
|
|
|
+ * */
|
|
|
+function submitDeleteGroupAction(index) {
|
|
|
+ var ownid = app.gid;
|
|
|
+ var groupName = app.groups[index].groupName;
|
|
|
+ groupService.removeGroup(ownid, groupName, function (data) {
|
|
|
+ reloadData();
|
|
|
+ drawSessionGroup();
|
|
|
+ hideRemindBox();
|
|
|
+ },function (error) {
|
|
|
+ alert('删除分组失败!');
|
|
|
+ })
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 确认删除联系人
|
|
|
+ * */
|
|
|
+function submitDeleteAction(index, item_index) {
|
|
|
+ var chatSessionId = app.groups[index].chatSessionList[item_index].id;
|
|
|
+ var ownid = app.gid;
|
|
|
+ var fromGroupName = app.groups[index].groupName;
|
|
|
+ groupService.removeLinkman(chatSessionId, ownid, fromGroupName, function (data) {
|
|
|
+ reloadData();
|
|
|
+ drawSessionGroup();
|
|
|
+ hideRemindBox();
|
|
|
+ },function (error) {
|
|
|
+ alert('删除联系人失败!');
|
|
|
+ })
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 确认加入黑名单
|
|
|
+ * */
|
|
|
+function submitBlackAction(index, item_index) {
|
|
|
+ var chatSessionId = app.groups[index].chatSessionList[item_index].id;
|
|
|
+ var ownid = app.gid;
|
|
|
+ var fromGroupName = app.groups[index].groupName;
|
|
|
+ groupService.setlinkmanToBlacklist(chatSessionId, ownid, fromGroupName, function (data) {
|
|
|
+ reloadData();
|
|
|
+ drawSessionGroup();
|
|
|
+ hideRemindBox();
|
|
|
+ },function (error) {
|
|
|
+ alert('加入黑名单失败!');
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 隐藏分组菜单
|
|
|
+ * */
|
|
|
+function hideGroupMenu() {
|
|
|
+ $('.group-menu').hide();
|
|
|
+}
|
|
|
+/**
|
|
|
+ * 隐藏分组列表菜单
|
|
|
+ * */
|
|
|
+function hideGroupListMenu() {
|
|
|
+ $('.group-list-menu').hide();
|
|
|
+}
|
|
|
+
|
|
|
+function onAddGroup(event) {
|
|
|
+ if (event.keyCode && event.keyCode !== 13) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var val = $(event.target).val();
|
|
|
+ if (!val || val == '') {
|
|
|
+ $('#session-list .list-group2 .group-list >li:last-child').remove();
|
|
|
+ } else {
|
|
|
+ groupService.addGroup(app.gid, val, function (data) {
|
|
|
+ reloadData();
|
|
|
+ drawSessionGroup();
|
|
|
+ }, function (error) {
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function onRenameGroup(event, index) {
|
|
|
+ if (event.keyCode && event.keyCode !== 13) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var _this = $(event.target)
|
|
|
+ var val = _this.val();
|
|
|
+ if (!val || val == '') {
|
|
|
+ _this.prev().show();
|
|
|
+ _this.remove();
|
|
|
+ } else {
|
|
|
+ var groupName = app.groups[index].groupName;
|
|
|
+ groupService.renameGroup(app.gid, groupName, val, function (data) {
|
|
|
+ reloadData();
|
|
|
+ drawSessionGroup();
|
|
|
+ }, function (error) {
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 搜索联系人
|
|
|
+ * */
|
|
|
+function onSearchLinkman(type) {
|
|
|
+ if (type && type == 'keyup' && event.keyCode!=13) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ searchLinkMan();
|
|
|
+}
|
|
|
+
|
|
|
+function searchLinkMan() {
|
|
|
+ var keyword = $('#session-list .search-user >input').val();
|
|
|
+ var ownerId = app.gid;
|
|
|
+ groupService.searchLinkman(keyword, ownerId, function (data) {
|
|
|
+ app.sessions = handlerSessionData(data.success || []);
|
|
|
+ drawSessionList(app.sessions);
|
|
|
+ },function (error) {
|
|
|
+
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+$(window).resize(function () { //当浏览器大小变化时
|
|
|
+ // alert($(window).height()); //浏览器时下窗口可视区域高度
|
|
|
+ //alert($(document).height()); //浏览器时下窗口文档的高度
|
|
|
+ //alert($(document.body).height()); //浏览器时下窗口文档body的高度
|
|
|
+ //alert($(document.body).outerHeight(true)); //浏览器时下窗口文档body的总高度 包括border padding margin*/
|
|
|
+});
|