/**
* REIM即时通信主js
* caratename:雨中磐石(rainrock)
* caratetime:2017-07-20 21:40:00
* homepage:www.rockoa.com
*/
//打开聊天会话
function openchat(id, lx,face){
if(!lx)lx=0;var types=['user','group'];
var sle = (types[lx]) ? types[lx] : lx;
var url = '?d=reim&m=chat&uid='+id+'&type='+sle+'',csne={};
if(face)csne.icon=face;
js.open(url, 480,500, ''+sle+'_'+id+'',{},csne);
}
var windowfocus=true;
var reim = {
connectbool:false,
otherlogin:false,
timeloads:0,
ruloadtime:10*60,
userarr:{},
deptarr:{},
grouparr:{},
maindata:{},
agentarr:{},
lastloaddt:'',
apiurl:function(m,a){
return 'api.php?m='+m+'&a='+a+'';
},
show:function(){
nwjs.init();
nwjs.createtray(''+systitle+'-'+adminname+'', 1);
bodyunload=function(){
nwjs.removetray();
}
nwjs.serverdata=function(d){
return reim.serverdata(d);
}
this.date = js.now();
notifyobj=new notifyClass({
title:'系统提醒',
sound:'web/res/sound/todo.ogg',
sounderr:'',
soundbo:true,
showbool:false
});
this.mainshow();//显示主界面
this.righthistroboj = $.rockmenu({
data:[],
itemsclick:function(d){
reim.rightclick(d);
}
});
$(window).resize(this.resize);
$(window).focus(function(){windowfocus=true});
$(window).blur(function(){windowfocus=false});
//数秒
setInterval('reim.timeload()', 1000);
document.ondragover=function(e){e.preventDefault();};
document.ondrop=function(e){e.preventDefault();};
},
openrecord:function(){
var url = '?homeurl=cmVpbSxyZWNvcmQsYXR5cGU9bXk:&homename=5oiR55qE5Lya6K!d6K6w5b2V&menuid=MjI3';
js.open(url,1000,550,'chatrecord');
},
timeload:function(){
this.timeloads++;
//刷新
if(this.timeloads >= this.ruloadtime){
this.timeloads = 0;
this.reload();
}
if(this.timeloads==5)this.getonline();
//如果服务端断开,用ajax连接
if(this.timeloads % 10==0){
this.loadredata();
}
},
//内部服务处理
serverdata:function(a){
var lx = a.atype;
if(lx=='cropfinish' && !this.cropScreenbo && a.filepath){
nwjs.winshow();
}
if(lx=='focus')nwjs.winshow();
if(lx=='crop')this.cropScreen(true);
if(lx=='notify')this.shownotify(a);
if(lx=='openchat')this.openchat(a.id,a.type);
if(lx=='getlogin')return {uid:adminid,uname:adminname,face:adminface};
if(lx=='getipmac')return nwjs.getipmac();
if(lx=='office')nwjs.editoffice(a.paramsstr);
if(lx=='upfile')return nwjs.filetobase64(a.path);
if(lx=='gpath')return nwjs.getpath();
},
shownotify:function(d1){
var d = js.apply({icon:'images/logo.png','title':'系统提醒',url:''}, d1);
if(d.msg)notifyobj.showpopup(d.msg,{icon:d.icon,title:d.title,url:d.url,click:function(b){
if(b.url)nwjs.openurl(b.url);
return true;
}});
},
resize:function(){
var h = winHb()-140-40;
$('#reim_mainview').css('height',''+h+'px');
},
cropScreen:function(){
var oatg = nwjs.getpath();
nw.Shell.openItem(''+oatg+'/images/reimcaptScreen.exe');
},
//显示聊天主界面
mainshow:function(bo){
if(get('reim_main')){
this.connectservers();
return;
}
var h = winHb()-140-40;
var s = '
';
s+='
';
s+='
| '+adminname+'('+adminranking+') '+deptallname+' |
';
s+='
';
s+='
';
s+='
0';
s+='
0';
s+=' ';
s+='
';
s+=' ';
s+='
';
s+='
';
s+='
';
$('#reim_viewshow').html(s);
this.resize();
$('#reim_keysou').keyup(function(){reim.searchss();});
$('#reim_keysou').click(function(){reim.searchss();});
this.initdata(); //初始化数据
},
ajax:function(url,da,fun,type,efun){
if(!da)da={};if(!type)type='get';
if(typeof(fun)!='function')fun=function(){};
if(typeof(efun)!='function')efun=function(){};
var atyp = type.split(',');type=atyp[0];
function errshow(esr){
js.msg('msg',esr);
efun(esr);
}
var ajaxcan={
type:type,
data:da,url:url+'&cfrom=reim',
success:function(ret){
if(ret.code==199){
reim.loginexits();
return;
}
if(ret.code==200){
fun(ret.data);
}else{
errshow(ret.msg);
}
},error:function(e){
errshow('处理出错:'+e.responseText+'');
}
};
ajaxcan.dataType='json';
$.ajax(ajaxcan);
},
//连接到服务端
connectserver:function(){
this.loaddata('config');
},
connectservers:function(){
if(this.connectbool){
this.serverstatus(1);
return;
}
var bo = this.showconfig(this.showconfigarr);
if(bo)js.msg('wait','连接中...');
},
showconfig:function(a){
if(this.connectbool){
this.serverstatus(1);
return false;
}
if(!a){
this.serverstatus(3);
return false;
}
var wsurl = jm.base64decode(a.wsurl),receid = a.recid;
this.showconfigarr = a;
if(isempt(wsurl) || wsurl.indexOf('ws')!=0){
this.serverstatus(3);
return false;
}
clearTimeout(this.relianshotime_time);
websocketobj = new websocketClass({
adminid:adminid,
reimfrom:receid,
wshost:wsurl,
sendname:adminname,
onerror:function(o,ws){
reim.connectbool=false;
reim.serverstatus(0);
js.msg('msg','REIM无法连接服务器1
[重连]',0);
reim.relianshotime(30);
},
onmessage:function(str){
reim.connectbool=true;
clearTimeout(reim.relianshotime_time);
var a=js.decode(str);
reim.receivemesb(a);
},
onopen:function(){
reim.connectbool=true;
reim.serverstatus(1);
clearTimeout(reim.relianshotime_time);
js.msg('none');
reim.initnotify();
},
onclose:function(o,e){
reim.connectbool=false;
if(reim.otherlogin)return;
reim.serverstatus(0);
js.msg('msg','REIM连接已经断开了
[重连]',0);
reim.relianshotime(30);
}
});
return true;
},
loginexit:function(){
js.confirm('确定要退出'+systitle+'吗?',function(lx){
if(lx=='yes')reim.loginexits();
});
},
loginexits:function(){
if(!nwjsgui){
window.close();
}else{
this.ajax(this.apiurl('login','loginexit'),{},function(ret){
js.setoption('autologin', '0');
js.location('?d=reim&a=login');
});
}
},
serverstatus:function(lx){
var s = '已连接';s='';
if(lx==0)s='未连接'
if(lx==2)s='在别处连接'
if(lx==3)s='没服务端';
$('#reim_statusserver').html(s);
},
relianshotime:function(oi){
clearTimeout(this.relianshotime_time);
$('#lianmiaoshoetime').html('('+oi+'秒后重连)');
if(oi<=0){
this.connectservers();
}else{
this.relianshotime_time=setTimeout('reim.relianshotime('+(oi-1)+')',1000);
}
},
//服务端发消息调用opener.reim.serversend(a);
serversend:function(a){
if(!this.connectbool)return false;
websocketobj.send(a);
return true;
},
//获取在线人员
getonline:function(){
this.serversend({'atype':'getonline'});
},
//加载数据
loadhistory:function(){
this.loaddata('history');
},
reload:function(){
this.initdata();
},
initdatas:function(){
this.initbackd(this.bdats);
},
//没有服务端定时去ajax读取。
loadredata:function(){
if(this.connectbool)return;
this.ajax(this.apiurl('indexreim','ldata'),{type:'history','loaddt':jm.base64encode(this.lastloaddt)}, function(ret){
var hist = js.decode(ret.json);
reim.lastloaddt = ret.loaddt;
reim.reloadhistory(hist);
});
},
reloadhistory:function(a){
var i,len=a.length,d;
for(i=0;i全员';
if(d1.deptid>'1')nastr+=' 部门';
}
s = '';
s+='
';
s+=' | ';
s+=''+nastr+' '+cont+' | ';
s+=''+d.stotal+' '+ops+' | ';
s+='
';
s+='
';
if(!pad){o.append(s);}else{o.prepend(s)}
$('#historylist_tems').hide();
this.showbadge('chat');
},
//在线离线设置
setonline:function(online){
$('div[uid]').addClass('offline');
var onlies = online.split(','),i,uid;
for(i=0;i-1){
d.push({name:'打开窗口',lx:1});
}
if(rt.indexOf('hist')>-1){
d.push({name:'删除此记录',lx:2});
}
this.righthistroboj.setData(d);
this.righthistroboj.showAt(e.clientX-3,e.clientY-3);
return false;
},
rightclick:function(d){
var o1 = $(this.rightdivobj),lx=d.lx;
var tsaid = o1.attr('tsaid'),
tsayp = o1.attr('tsaype');
if(lx==0){
if(tsayp=='user')this.openuser(tsaid);
if(tsayp=='group')this.opengroup(tsaid);
}
if(lx==2){
o1.remove();
var tst=$('#historylist').text();if(tst=='')$('#historylist_tems').show();
this.ajax(this.apiurl('reim','delhistory'),{type:tsayp,gid:tsaid},false);
}
},
//打开聊天界面
openchat:function(id,type){
this.showbadge('chat',''+type+'_'+id+'', 0);
if(type=='agent'){
this.openagent(id);
}else{
openchat(id,type);
}
this.setyd(type,id);
},
opengroup:function(id){
this.openchat(id, 'group');
},
openuser:function(id){
this.openchat(id, 'user');
},
//会话标识已读
setyd:function(type,id){
this.ajax(this.apiurl('reim','yiduall'),{type:type,gid:id},false);
},
//切换聊天主界面隐藏显示
mainclose:function(){
$('#reim_main').toggle();
this.showzhu();
},
//隐藏主界面
hidezhu:function(){
$('#topheaderid').hide();
$('.topcenter').hide();
$('#zhutable').hide();
},
//显示主界面
showzhu:function(){
$('#topheaderid').show();
$('.topcenter').show();
$('#zhutable').show();
},
//选择卡切换
tabchagne:function(oi,o1){
$('.headertab div').removeClass();
o1.className = 'active';
$('#reim_headercenter').find("div[tabdiv]").hide();
$('#reim_headercenter').find("div[tabdiv='"+oi+"']").show();
if(oi=='1')this.showdept(this.firstpid,0);
},
//加载群会话列表
loadgroup:function(){
this.loaddata('group');
},
loadagent:function(){
this.loaddata('agent');
},
showgroup:function(a){
var i=0,len=a.length,s,d,o=$('#reim_showgroupdiv'),msg='';
o.html('');
for(i=0;i
'+d.name+'';
if(d.deptid=='1')s+=' 全员';
if(d.deptid>'1')s+=' 部门';
s +='';
this.grouparr[d.id] = d;
o.append(s);
}
},
//显示组织结构
showdept:function(pid, xu){
var i=0,len,s='',a,wfj,cls;
var sv= '#showdept_'+pid+'';if(xu==0)sv='#showdept_0';
var o = $(sv);
var tx= o.text();
if(tx){if(xu!=0){o.toggle();}return;}
len=this.maindata.uarr.length;
for(i=0;i-1){
cls='offline';if(a.online==1)cls='';
s='';
s+='

'+a.name+'
('+a.ranking+')';
s+=' ';
o.append(s);
}
}
len = this.maindata.darr.length
for(i=0;i';
s+=' '+a.name+'';
s+='';
s+='';
o.append(s);
if(xu==0)this.showdept(a.id, xu+1);
}
}
},
//显示用户
showuser:function(a){
var i=0,len=a.length,d;
for(i=0;i
';
if(id==adminid)s+='
修改头像';
s+='';
s+='姓名:'+d.name+'
部门:'+d.deptallname+'
职位:'+d.ranking+'
性别:'+d.sex+'
电话:'+d.tel+'
手机:'+d.mobile+'
邮箱:'+d.email+'
';
s+='';
js.tanbody('userziliao',''+d.name+'', 240,350,{
html:s,
btn:[{text:'发消息'}]
});
$('#userziliao_btn0').click(function(){
reim.openuser(id);
});
if(id==adminid){
this.upfaceobj=$.rockupload({inputfile:'upfacess',uptype:'image',
urlparams:{noasyn:'yes'},
onsuccess:function(f,str){
var a=js.decode(str);
if(!a.id)return;
reim.saveface(a.id);
},
onchange:function(){
$('#fupbgonet').html('上传中...');
}
});
};
},
saveface:function(fid){
this.ajax(this.apiurl('reim','changeface'),{id:fid},function(face){
get('myface').src=face;
get('myfacess').src=face;
adminface=face;
js.setoption('adminface', face);
$('#fupbgonet').html('修改成功');
});
},
//显示应用
showagent:function(a){
var i=0,len=a.length,d,types,ty,o=$('#reim_showagetdiv'),s='',oi,atr;
o.html('');
var typearr = {};
for(i=0;i';
oi = 0;
for(i=0;i';
s+='';
s+='
'+d.stotal+'';
s+='
';
s+='
'+d.name+'
';
s+='
';
s+='';
if(oi%col==0){
if(i';
oi=0;
}
}
if(oi>0)for(i=oi;i ';
}
s+='
';
o.append(s);
}
this.showbadge('agent');
},
showbadge:function(slx,num,lx){
var to = 0,chanu=''+slx+'stotal_'+num+'';
$("span[id^='"+slx+"stotal_']").each(function(){
var o1,vd,ids;
ids= this.id;
o1 = $(this);
vd = parseFloat(o1.text());
if(ids==chanu){
if(lx==0){vd=0;o1.text('0');}
if(lx==1){vd++;o1.text(''+vd+'');}
}
if(vd==0){o1.hide();}else{o1.show();}
to+=vd;
});
var o1 = $('#'+slx+'_alltotal');
o1.text(''+to+'');
if(to==0){o1.hide();}else{o1.show();}
var oi = parseFloat($('#agent_alltotal').text()) + parseFloat($('#chat_alltotal').text());
nwjs.changeicon(oi); //托盘图标
},
//打开应用
openagent:function(id){
var d = this.agentarr[id];
this.showbadge('agent',d.num,0);
var w = 1000,h=570,url = d.urlpc;
if(isempt(url)){
url = d.urlm;
if(isempt(url)){
url = '?d=we&m=ying&num='+d.num+''; //先默认用移动端
}
w = 320;
}
var jg = (url.indexOf('?')>-1)?'&':'?';
url+=''+jg+'openfrom=reim';
//考勤打卡
if(d.num=='kqdaka'){
this.opendaka();return;
}
js.open(url, w,h,'agent'+d.num+'');
},
//考勤打卡
opendaka:function(bo){
var url = '?d=reim&m=ying&a=daka',w = 550;h=300;
js.open(url, w,h,'agentkqdaka',{},{icon:'images/adddk.png'});
},
//显示到会话列表上
addhistory:function(lx,id,sot,cont,opt,sne,name,face){
if(!sne)sne='';
if(sne)sne=jm.base64encode(sne+':');
if(lx!='group')sne='';
var d={type:lx,receid:id,stotal:sot,cont:sne+cont,optdt:opt};
if(name)d.name = name;
if(face)d.face = face;
this.showhistorys(d, true);
},
editpass:function(bt,cse){
if(!bt)bt='修改密码';
if(!cse)cse='';
js.tanbody('winiframe',bt,260,300,{
html:'',
bbar:'none',
closed:cse
});
openinputiframe.location.href='?m=index&d=we&a=editpass&hideheader=true&ofrom=reim';
},
//别的地方登录
otherlogins:function(){
this.otherlogin = true;
var msg='已在别的地方连接了';
js.msg('success', msg, -1);
this.serverstatus(2);
},
//服务端接收到推送消息
receivemesb:function(d, lob){
var lx=d.type,sendid=d.adminid,num,face,ops=false,msg='',ot,ots,garr,tits,gid;
if(!sendid)sendid = d.sendid;
if(lx=='offoline'){
this.otherlogins();
return;
}
if(lx=='getonline'){
this.setonline(d.online);
return;
}
var a = this.userarr[sendid];
if(a){
d.sendname=a.name;
d.face = a.face;
}else if(!lob){
this.ajax(this.apiurl('indexreim','loadinfo'),{type:'user',receid:sendid}, function(ret){
if(!ret){
console.error('无法读取到'+sendid+'的信息');
}else{
reim.showuser(ret);
reim.receivemesb(d, true);
}
});
return;
}
gid = d.gid;
if(lx == 'user' || lx == 'group'){
num = ''+lx+'_'+sendid+'';
if(lx == 'group')num = ''+lx+'_'+gid+'';
ops = js.openrun(num, 'recemess', d);
if(lx == 'group'){
garr= this.grouparr[gid];
if(!garr){
this.loadgroup();
garr={face:'images/group.png'};
}
face= garr.face;
}
this.setonlines(sendid,1);//说明是在线的
var title = document.title+'消息';
if(ops){
ops.focus();
}else{
if(lx == 'user'){
msg = '人员['+d.sendname+'],发来一条信息';
notifyobj.showpopup(msg,{icon:d.face,sendid:sendid,title:title,rand:num,click:function(b){
reim.openuser(b.sendid);
return true;
}});
}
if(lx == 'group'){
if(!d.gname)d.gname = d.name;
msg = '人员['+d.sendname+'],发来一条信息,来自['+d.gname+']';
if(d.form=='ajax')d.sendname='';
notifyobj.showpopup(msg,{icon:garr.face,gid:gid,title:title,rand:num,click:function(b){
reim.opengroup(b.gid);
return true;
}});
}
}
ot = $('#chatstotal_'+num+'');ots=ot.text();if(ots=='')ots='0';
if(!ops)ots = parseFloat(ots)+1;
if(lx=='user')this.addhistory(lx,sendid,ots,d.cont,d.optdt);
if(lx=='group')this.addhistory(lx,gid,ots,d.cont,d.optdt,d.sendname);
}
//应用的通知提醒
if(lx == 'agent'){
garr = this.agentarr[gid];
num = 'agent_'+gid+'';
if(!garr){
this.loadagent();
garr={face:'images/logo.png',pid:0};
}
msg = ""+jm.base64decode(d.cont)+"";
tits = d.title;
if(!tits)tits = d.gname;
notifyobj.showpopup(msg,{icon:garr.face,title:tits,gid:gid,rand:'agent_'+gid+'',url:d.url,click:function(b){
if(b.url){
js.open(b.url,760,500);
return true;
}else{
//im.openagent(b.gid);
return false;
}
}});
ot = $('#chatstotal_'+num+'');ots=ot.text();if(ots=='')ots='0';
if(!ops)ots = parseFloat(ots)+1;
this.addhistory(lx,gid,ots,d.cont,d.optdt,'', tits, garr.face);
}
if(lx == 'loadgroup'){
this.loadgroup();
}
},
//通知设置
initnotify:function(){
var lx=notifyobj.getaccess();
if(lx!='ok'){
js.msg('msg','为了可及时收到信息通知
请开启提醒,[开启]',-1);
}
},
indexsyscogs:function(){
var str = notifyobj.getnotifystr('reim.indexsyscogss()');
return '桌面通知提醒'+str+'';
},
indexsyscogss:function(){
notifyobj.opennotify(function(){
$('#indexsyscog_msg').html(reim.indexsyscogs());
});
},
getsound:function(){
var lx = js.getoption('soundcog'),chs=false;
if(lx=='')lx='1';
if(lx==1)chs=true;
return chs;
},
setsound:function(o1){
var lx=(o1.checked)?'1':'2';
js.setoption('soundcog', lx);
notifyobj.setsound(o1.checked);
},
indexsyscog:function(){
var chs= (this.getsound())?'checked':'';
var s='';
s+='
'+this.indexsyscogs()+'
';
s+='
';
if(nwjsgui){
var ksj=js.getoption('kuaijj','Q');
var strw='ABCEDFGHIJKLMNOPQRSTUVWYZ',s1,cls1='';
s+='
主窗口快捷键:Ctrl+Alt+
';
var ips = nwjs.getipmac();
s+='
我局域网IP:'+ips.ip+'
';
s+='
我的MAC地址:'+ips.mac+'
';
}else{
}
s+='
网络IP:'+this.myip+'
';
s+='
';
js.tanbody('syscogshow','REIM设置',240,100,{html:s});
},
//搜索联系人/会话/应用
searchss:function(){
clearTimeout(this.searchsstime);
this.searchsstime=setTimeout('reim.searchssss()',500);
if(!this.searchright)this.searchright=$.rockmenu({
data:[],iconswh:20,
itemsclick:function(d){
reim.searchclick(d.type,d.id);
}
});
},
searchclick:function(ty,id){
if(ty=='user')this.openuser(id);
if(ty=='group')this.opengroup(id);
if(ty=='agent')this.openagent(id);
},
searchssss:function(){
var o = $('#reim_keysou'),val=strreplace(o.val());
var d=[];
if(val==''){
this.searchright.hide();
return;
}
val=val.toLowerCase();
var off=o.offset(),sid,a,s1;
for(sid in this.userarr){
a=this.userarr[sid];
if(a.name.indexOf(val)>-1 || a.pingyin.indexOf(val)==0 || a.deptname.indexOf(val)>-1 || a.ranking.indexOf(val)>-1){
s1=''+a.name+'('+a.ranking+')';
d.push({name:s1,id:a.id,icons:a.face,type:'user'});
}
}
for(sid in this.grouparr){
a=this.grouparr[sid];
if(a.name.indexOf(val)>-1){
s1=''+a.name+'(会话)';
d.push({name:s1,id:a.id,icons:a.face,type:'group'});
}
}
for(sid in this.agentarr){
a=this.agentarr[sid];
if(a.name.indexOf(val)>-1){
s1=''+a.name+'(应用)';
d.push({name:s1,id:a.id,icons:a.face,type:'agent'});
}
}
if(d.length==0){
this.searchright.hide();
return;
}
this.searchright.setData(d);
this.searchright.showAt(off.left+1,off.top+40,$('#reim_headercenter').width()-2);
},
//创建会话
creategroup:function(){
js.prompt('创建会话','请输入会话名称:',function(lx,v){
if(lx=='yes'){
if(!v){js.msg('msg','没有输入会话名称');return false;}
js.msg('wait','创建中...');
reim.ajax(reim.apiurl('reim','createlun'),{val:jm.base64encode(v)}, function(da){
js.msg('success','创建成功,请打开会话窗口邀请人员加入');
reim.loadgroup();
});
}
});
return false;
},
//退出会话
exitgroup:function(gid){
this.loadgroup();
//$('#history_group_'+gid+'').remove();
}
};