/** * REIM即时通信主js-最新版本 * caratename:雨中磐石(rainrock) * caratetime:2018-11-01 21:40:00 * homepage:www.rockoa.com */ var agentarr={},userarr={},grouparr={},cnum='',windowfocus=true,jietubool=false; //是不是xp和win7的版本 function jisxobo(){ var llq = navigator.userAgent.toLowerCase(); if(llq.indexOf('windows nt 5')>0 || llq.indexOf('windows nt 6.1')>0){ return true; } return false; } var reim={ chatobj:{}, maindata:{}, initci:0, timeloads:0, ruloadtime:5*60, //5分钟 init:function(){ js.ajaxwurbo = true; js.xpbodysplit = 5; date = js.now('Y-m-d'); nwjs.init(); bodyunload=function(){ nwjs.removetray(); } this.resize(); nwjs.serverdata=function(d){ return reim.serverdata(d); } $(window).resize(this.resize); $(window).focus(function(){windowfocus=true;im.windowfocus()}); $(window).blur(function(){windowfocus=false}); //数秒 setInterval('reim.timeload()', 1000); var fse=js.getoption('loginface'); if(fse)get('myface').src=fse; nwjs.createtray(document.title+'-'+adminname, 1); strformat.ismobile=0; //禁止后退 try{ history.pushState(null, null, document.URL); window.addEventListener('popstate', function (){ history.pushState(null, null, document.URL); }); }catch(e){} this.initload(); $('#centlist').perfectScrollbar(); uploadobj = $.rockupload({ inputfile:'allfileinput', initpdbool:false, updir:'reimchat', urlparams:{noasyn:'yes'}, //不需要同步到文件平台上 onchange:function(d){ im.sendfileshow(d); }, onprogress:function(f,per,evt){ im.upprogresss(per); }, onsuccess:function(f,str,o1){ im.sendfileok(f,str); }, onerror:function(str){ js.msg('msg', str); im.senderror(); } }); strformat.upobj = uploadobj; $('body').keydown(function(e){ return reim.bodykeydown(e); }); //注册推送提醒的 notifyobj=new notifyClass({ title:'系统提醒', sound:'web/res/sound/todo.ogg', sounderr:'', soundbo:this.getsound(), //是否要声音 showbool:false }); this.righthistroboj = $.rockmenu({ data:[], itemsclick:function(d){ reim.rightclick(d); } }); $('#reimcog').click(function(){ reim.clickcog(this); return false; }); document.ondragover=function(e){e.preventDefault();}; document.ondrop=function(e){e.preventDefault();}; //注册全局ajax的错误 js.ajaxerror=function(msg,code){ if(code==401){ js.msg(); js.msgerror('登录失效,重新登录'); if(!nwjsgui){ js.location('/users/login?backurl=reim'); }else{ js.location('/reim/login.html'); } } } if(!nwjsgui){ $('#closediv').remove(); } $('#reim_keysou').keyup(function(){reim.searchss();}); $('#reim_keysou').click(function(){reim.searchss();}); if(jisxobo()){ js.xpbodysplit = 0; get('mindivshow').style.margin='0px'; } }, resize:function(){ viewheight = winHb()-10-50; //可操作高度 var lx1 = 0; if(jisxobo())lx1=10; viewheight+=lx1; $('#mindivshow').css('height',''+(viewheight+50)+'px'); $('#centlist').css('height',''+viewheight+'px'); $('#viewzhulist').css('height',''+viewheight+'px'); var obj = $('div[resizeh]'),o,hei; for(var i=0;i= this.ruloadtime){ this.timeloads = 0; this.initload(); } //if(this.timeloads==5)this.getonline();//获取在线人员id }, bodykeydown:function(e){ var code = e.keyCode; if(code==27){ if($.imgviewclose())return false; if(get('xpbg_bodydds')){ js.tanclose($('#xpbg_bodydds').attr('xpbody')); }else{ this.closenowtabss(); } return false; } }, winclose:function(){ nwjs.win.hide(); }, winzuida:function(){ if(!this.zdhbo){ nwjs.win.maximize(); this.zdhbo=true; }else{ nwjs.win.unmaximize(); this.zdhbo=false; } }, changetabs:function(ind){ $('div[id^="changetabs"]').css('color','#cccccc'); $('div[id^="centshow"]').hide(); $('#changetabs'+ind+'').css('color','#1389D3'); $('#centshow'+ind+'').show(); if(ind==1)this.showdept(); if(ind==2){ $('#maincenter').hide(); this.showagent(true); }else{ this.hideagent(); $('#maincenter').show(); } }, getapiurl:function(m,a){ return 'api.php?m='+m+'&a='+a+'&cfrom=reim'; }, //ajax访问处理 ajax:function(url,cans, fun, lx,efun){ if(!lx)lx='get'; if(!fun)fun=function(){} if(!efun)efun=function(){} js.ajax(url,cans,function(ret){ if(ret.code==200){ fun(ret); }else if(ret.code==199){ js.confirm(ret.msg, function(){ reim.exitlogin(true); }); }else{ js.msg('msg',ret.msg); efun(ret); } },''+lx+',json', efun); }, //初始加载数据 initload:function(bo){ this.initbool = true; this.ajax(this.getapiurl('indexreim','indexinit'),{'initci':this.initci,'gtype':'reim'}, function(ret){ reim.initci++; reim.showdata(ret.data); if(bo)reim.reloaduser(); }); }, firstpid:0, showdata:function(ret){ if(!ret.userjson)return; this.lastloaddt = ret.loaddt; this.maindata.darr = js.decode(ret.deptjson); this.maindata.uarr = js.decode(ret.userjson); this.maindata.garr = js.decode(ret.groupjson); this.maindata.harr = js.decode(ret.historyjson); this.firstpid = this.maindata.darr[0].pid; if(!this.showconfigarr){ this.showconfigarr = ret.config; this.websocketlink(ret.config); } var aarr = js.decode(ret.agentjson); var cbarr = {},i; for(i=0;i-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',xuoi:i}); oi++; } if(oi>10)break;//最多显示10人 } arr = this.maindata.garr; for(i=0;i-1){ s1=''+a.name+'(会话)'; d.push({name:s1,id:a.id,icons:a.face,type:'group'}); } } for(sid in agenharr){ a=agenharr[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+25,$('#reim_headercenter').width()-2); }, websocketlink: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','无法连接服务器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','连接已经断开了
[重连]',0); reim.relianshotime(10); } }); }, connectservers:function(){ if(this.connectbool){ this.serverstatus(1); return; } var bo = this.websocketlink(this.showconfigarr); if(bo)js.msg('wait','连接中...'); }, 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); } }, showdept:function(id){ if($('#showdept').html()==''){ this.reloaduser(); }else{ } }, 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(){ js.msg('success', reim.indexsyscogs()); }); }, reloaduser:function(){ $('#showdept').html(''); this.showuserlists(this.firstpid,0, 'showdept'); this.showgroup(); }, //服务端发消息调用opener.reim.serversend(a); serversend:function(a){ if(!this.connectbool)return false; websocketobj.send(a); return true; }, //获取在线人员 getonline:function(){ this.serversend({'atype':'getonline'}); }, //别的地方登录 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; if(lx=='offoline'){ this.otherlogins(); return; } if(lx=='user' || lx=='group'){ if(sendid!=adminid)this.receivechat(d); } if(lx=='agent'){ this.receiveagenh(d); nwjs.jumpicon(); } if(lx=='chehui'){ $('#qipaocont_mess_'+d.messid+'').html(js.getmsg(jm.base64decode(d.cont),'green')); this.historyreload(); } }, showuserlists:function(pid,xu, svie){ var o = $('#'+svie+''); var tx= o.text(); if(tx){if(pid!=0){o.toggle();}return;} var a =this.maindata.uarr,i,len=a.length,d,dn,s='',wfj,zt,sids; for(i=0;i-1){ zt=''; if(d.status==0)zt=' 未加入'; s='
'; s+=''; s+=''; s+=''; s+='
'+d.name+''+zt+'
'; s+='
'; o.append(s); } } a = this.maindata.darr; len=a.length; for(i=0;i'; s+=' '+d.name+''; if(d.ntotal>0)s+=' ('+d.ntotal+')'; s+=''; s+=''; o.append(s); if(xu==0)this.showuserlists(d.id, xu+1, 'showdept_'+d.id+''); } } }, showgroup:function(){ var a =this.maindata.garr,i,len=a.length,d,s=''; s='
会话('+len+')
'; for(i=0;i'; s+=''; s+=''; s+=' '; s+='
'+d.name+''; if(d.deptid=='1')s+=' 全员'; if(d.deptid>'1')s+=' 部门'; s+='
'; s+=''; } $('#showgroup').html(s) }, historyreload:function(){ this.ajax(this.getapiurl('indexreim','gethistory'),{id:0},function( ret){ var data = ret.data; reim.showhistory(data); }); }, showhistory:function(a){ var i,len=a.length; $('#historylist').html(''); $('#historylist_tems').show(); for(i=0;i0)$('#historylist_tems').hide(); }, showhistorydata:{}, showhistorys:function(d,pad, lex){ var s,ty,o=$('#historylist'),d1,st,attr; var num = ''+d.type+'_'+d.receid+''; this.showhistorydata[num]=d; $('#history_'+num+'').remove(); st = d.stotal;if(st=='0')st=''; var ops = d.optdt.substr(11,5); if(d.optdt.indexOf(date)!=0)ops=d.optdt.substr(5,5); ty = d.type; var cls = lex ? ' active' : ''; var na = d.name; if(d.title)na = d.title; if(d.type=='group'){ var d2 = grouparr[d.receid]; if(d2)d.deptid = d2.deptid; } var s1 = ''; if(d.deptid=='1')s1=' 全员'; if(d.deptid>'1')s1=' 部门'; s = '
'; s+=''; s+=''; s+=''; s+=''; s+='
'+na+''+s1+'
'+jm.base64decode(d.cont)+'
'+st+'
'+ops+'
'; s+='
'; if(!pad){o.append(s);}else{o.prepend(s)} $('#historylist_tems').hide(); this.showbadge('chat'); }, historyright:function(o1,e,num){ var rt = $(o1).attr('rtype'); if(isempt(rt))return false; this.rightdivobj = o1; var da=[{name:'打开',lx:0}],d=this.showhistorydata[num]; if(d && d.stotal>0)da.push({name:'标识已读',lx:1}); if(rt.indexOf('hist')>-1){ da.push({name:'删除此记录',lx:2}); } this.righthistroboj.setData(da); 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){ this.rightdivobj.onclick(); } if(lx==2){ o1.remove(); var tst=$('#historylist').text();if(tst=='')$('#historylist_tems').show(); js.ajax(this.getapiurl('reim','delhistory'),{type:tsayp,gid:tsaid},false,'get'); this.showbadge('chat'); } if(lx==1){ var num = ''+tsayp+'_'+tsaid+''; $('#chat_stotal_'+num+'').html(''); var d=this.showhistorydata[num]; if(d)d.stotal='0'; this.showbadge('chat'); this.biaoyd('agent',tsaid); } }, openmyinfo:function(){ this.showuserinfo(0,userarr[adminid]); }, showuserinfo:function(oi, d1){ var d = this.maindata.uarr[oi]; if(d1)d=d1; var num = 'userinfo_'+d.id+''; var s = '
'; s+='
'; if(d.id==adminid)s+=''; s+='
姓名:'+d.name+'
部门:'+d.deptallname+'
职位:'+d.ranking+'
性别:'+d.sex+'
电话:'+d.tel+'
手机:'+d.mobile+'
邮箱:'+d.email+'
'; s+='
   
'; s+='
'; this.addtabs(num,s); if(d.id==adminid){ if(!this.upfaceobj)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.getapiurl('reim','changeface'),{id:fid},function(ret){ var face = ret.data; get('myface').src=face; get('myfacess').src=face; adminface=face; js.setoption('loginface', face); js.setoption('adminface', face); $('#fupbgonet').html('修改成功'); }); }, openchat:function(type,reid,na,fac){ var num = ''+type+'_'+reid+''; $('#chat_stotal_'+num+'').html(''); this.showbadge('chat'); if(type=='agent'){ var d = this.showhistorydata[num]; var url=''; if(d && d.stotal>0 && !isempt(d.xgurl)){ d.stotal='0'; var xga = d.xgurl.split('|'); if(xga[1]>0)url='task.php?a=p&num='+xga[0]+'&mid='+xga[1]+''; } if(url==''){ this.openagenh(reid); }else{ this.biaoyd('agent',reid); js.open(url,760,500); } return; } var s = '
'; s+='
'; s+='
'; var hei = 206; s+='
'; s+='
'; s+=' '; s+=' '; if(nwjsgui){ s+=' '; s+=' '; } s+='
'; s+='
'; s+='
 
'; s+='
'; var bo = this.addtabs(num,s); get('input_content_'+num+'').focus(); if(!bo){ this.chatobj[num]=new chatcreate({ 'type' : type, 'gid' : reid, 'num' : num, 'name' : na, 'face' : fac }); } this.chatobj[num].onshow(); }, biaoyd:function(type,gid){ js.ajax(this.getapiurl('reim','yiduall'),{type:type,gid:gid},false,'get'); }, receiveagenh:function(d){ var gid = d.gid; var num = d.type+'_'+gid,stotal=0,msg; var so = $('#chat_stotal_'+num+'').html(); if(!so)so=0; stotal = parseInt(so)+1; this.showhistorys({ 'cont' : d.cont, 'name' : d.gname, 'title' : d.title, 'face' : d.gface, 'optdt' : d.optdt, 'type' : d.type, 'receid' : gid, 'stotal' : stotal }, true); msg = jm.base64decode(d.cont); msg = msg.replace(/\\n/gi,' '); var sopenfun=function(b){ js.alertclose(); notifyobj.close();//关闭右下角的提示 if(b.url){ js.open(b.url,760,500); return true; }else{ reim.openagenh(b.gid, b.url); } return true; //不激活主窗口 } js.alertclose(); js.confirm(msg,function(jg){if(jg=='yes'){sopenfun(d)}},'',' '+d.title); if(this.getzhuom())notifyobj.showpopup(msg,{icon:d.gface,url:d.url,gid:gid,title:d.title,rand:num,click:function(b){ return sopenfun(b); }}); }, receivechat:function(d){ var gid = d.gid,lx = d.type,stotal=0,num,msg,name=d.gname,face=d.face,s1=''; if(lx=='user'){ gid = d.adminid; name= d.sendname; } if(lx=='group'){ face = d.gface; s1 = jm.base64encode(''+d.sendname+':'); if(isempt(face))face = 'images/group.png'; } num = d.type+'_'+gid; var showtx = true; if(this.isopentabs(num)){ this.chatobj[num].receivedata(d); if(this.nowtabs!=num){ this.chatobj[num].newbool=true; } } if(windowfocus && this.nowtabs==num)showtx=false; //未读数 if(this.nowtabs!=num){ var so = $('#chat_stotal_'+num+'').html(); if(!so)so=0; stotal = parseInt(so)+1; } this.showhistorys({ 'cont' : s1+d.cont, 'name' : name, 'face' : face, 'optdt' : d.optdt, 'type' : d.type, 'receid' : gid, 'stotal' : stotal }, true, this.nowtabs==num); var nr = jm.base64decode(d.cont); if(showtx || nr.indexOf('@'+adminname+'')>-1){ var title = '会话消息'; msg = '人员['+d.sendname+'],发来一条信息'; if(lx == 'group'){ msg += ',来自['+name+']'; } if(this.getzhuom())notifyobj.showpopup(msg,{icon:face,type:lx,gid:gid,name:name,title:title,rand:num,click:function(b){ reim.openchat(b.type, b.gid,b.name,b.icon); }}); nwjs.jumpicon(); } }, addtabs:function(num, s){ var ids = 'tabs_'+num+'',bo; if(!get(ids)){ var s = '
'+s+'
'; $('#viewzhulist').append(s); bo = false; }else{ bo = true; } this.showtabs(num); return bo; }, closetabs:function(num){ var ids = 'tabs_'+num+''; $('#'+ids+'').remove(); var ood = $('#viewzhulist div[tabs]:last'); var snu = ood.attr('tabs'); this.showtabs(snu); }, closenowtabs:function(){ if(this.nowtabs)this.closetabs(this.nowtabs); }, closenowtabss:function(){ var nun = this.nowtabs; if(!nun)return; if(nun.indexOf('user_')==0 || nun.indexOf('group_')==0 || nun.indexOf('userinfo_')==0)this.closenowtabs(); }, isopentabs:function(num){ return get('tabs_'+num+''); }, showtabs:function(num){ $('div[tabs]').hide(); var ids = 'tabs_'+num+''; $('#'+ids+'').show(); $('div[temp]').removeClass('active'); $('#history_'+num+'').addClass('active'); this.nowtabs = num; }, showagent:function(sbo){ var agedt = this.maindata.aarr,s='',ty,a,len,d,d1,sno,so=0,sodd=1; s+='
'; agenharr={}; for(ty in agedt){ a = agedt[ty]; len = a.length; s+='
  '+ty+'
'; s+='
'; for(i=0;i
'+d.name+'
'; s+=''+sno+''; s+='
'; } s+='
'; sodd=1; } s+='
'; if(!sbo){ if(so==0)so=''; $('#agenh_stotal').html(so); return; } var bo = this.addtabs('agenh',s); if(!bo)$('#agenhview').perfectScrollbar(); this.showbadge('agenh'); }, hideagent:function(){ if(get('tabs_agenh')) this.closetabs('agenh'); }, openagenh:function(id, url){ var d = agenharr[id]; if(!d){ js.msg('msg','应用不存在,请刷新'); return; } d.stotal=0; var num = 'agenh_'+d.id+''; $('#agenh_stotal_'+d.id+'').html(''); this.showagent(false); $('#chat_stotal_'+num+'').html(''); this.showbadge('chat'); this.biaoyd('agent',d.id); var w = 1100,h=600,url = d.urlpc; if(isempt(url)){ url = d.urlm; if(isempt(url)){ url = '?d=we&m=ying&num='+d.num+''; //先默认用移动端 } w = 350; } var jg = (url.indexOf('?')>-1)?'&':'?'; url+=''+jg+'openfrom=reim'; //考勤打卡 if(d.num=='kqdaka'){ this.opendaka();return; } if(url.substr(0,4)=='http' && url.indexOf(HOST)<0 && nwjsgui){ nwjs.openurl(url); }else{ 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'}); }, showbadge:function(lx){ var obj = $('span[id^="'+lx+'_stotal_"]'),so=0,s1,o,i; for(i=0;i', bbar:'none', closed:cse }); openinputiframe.location.href='?m=index&d=we&a=editpass&hideheader=true&ofrom=reim'; }, changecom:function(){ js.tanbody('winiframe','切换单位',350,300,{ html:'
', bbar:'none' }); openinputiframe.location.href='?m=index&d=we&a=company&hideheader=true&ofrom=reim'; }, changecomok:function(){ js.tanclose('winiframe'); js.msgok('切换成功'); location.reload(); }, exitlogin:function(bo){ if(!bo){ js.confirm('确定要退出系统吗?',function(jg){ if(jg=='yes')reim.exitlogin(true); }); return; } if(nwjsgui){ js.loading('退出中...'); js.ajax(this.getapiurl('login','loginexit'),{},function(ret){ js.setoption('autologin', '0'); js.location('?d=reim&a=login&a=xin'); }); }else{ window.close(); } }, 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); }, getzhuom:function(){ var lx = js.getoption('zhuomcog'),chs=false; if(lx=='')lx='1'; if(lx==1)chs=true; return chs; }, setzhuom:function(o1){ var lx=(o1.checked)?'1':'2'; js.setoption('zhuomcog', lx); }, cogshow:function(){ var chs= (this.getsound())?'checked':''; var ch1= (this.getzhuom())?'checked':''; var num = 'userinfo_cogshow'; var s = '
'; s+='
设置
'; s+='
'; s+='
'; if(nwjsgui){ var ips = nwjs.getipmac(); s+='
我局域网IP:'+ips.ip+'
'; s+='
我的MAC地址:'+ips.mac+'
'; } s+='
网络IP:'+this.myip+'
'; s+='
'; s+='
'; this.addtabs(num,s); }, //内部服务处理 serverdata:function(a){ var lx = a.atype; 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(); } }; function chatcreate(cans){ for(var i in cans)this[i]=cans[i]; strformat.emotspath='web/'; var me = this; this._init = function(){ this.minid = 999999999; this.showobj = $('#viewcontent_'+this.num+''); this.inputobj = $('#input_content_'+this.num+''); this.sendbtn = $('#chatsendbtn_'+this.num+''); this.listdata = {}; this.loadci = 0; this.objstr = 'reim.chatobj[\''+this.num+'\']'; this.sendbtn.click(function(){ me.sendcont(); }); $('#chatclosebtn_'+this.num+'').click(function(){ me.closechat(); }); this.inputobj.keydown(function(e){ return me.onkeydown(e); }); $('#toolsliao_'+this.num+'').find('span').click(function(e){ me.clicktools(this); return false; }); this.showtitle(); this.loaddata(); get('tabs_'+this.num+'').addEventListener('drop', function(e) { var files = e.dataTransfer; me.filedrop(files); }, false); }; this.showtitle=function(){ var o = $('#viewtitle_'+this.num+''),s=''; var od = this.receinfo; if(!od)od={deptid:'-1'}; s+=''; s+=''; s+=''; if(this.type=='group'){ if(!od.deptid || od.deptid=='0'){ s+=''; s+=''; } s+=''; } s+='
'; s+='
'+this.name+''; if(this.type=='group' && this.usershu)s+='('+this.usershu+')'; if(this.type=='group'){ if(od.deptid=='1')s+=' 全员'; if(od.deptid>'1')s+=' 部门'; } if(od.ranking)s+=' ('+od.ranking+')'; s+='
'; if(od.unitname)s+='
'+od.unitname+'
'; s+='
'; o.html(s); $('#yaoqingchat_'+this.num+'').click(function(){ me.yaoqing(); }); $('#tuichuchat_'+this.num+'').click(function(){ me.exitgroup(); }); $('#tuiuserlist_'+this.num+'').click(function(){ me.showhuilist(); }); }; this.loaddata=function(o1, iref){ if(this.boolload)return; var iref = (!iref)?false:true; var minid= 0; if(iref)minid=this.minid; if(o1)$(o1).html(' 加载中...'); this.boolload = true; this.isshangla = false; reim.ajax(reim.getapiurl('reim','getrecord'),{type:this.type,gid:this.gid,minid:minid,loadci:this.loadci},function(ret){ if(o1)$(o1).html(''); var da = ret.data; if(me.loadci==0){ me.showobj.html(''); me.sendinfo = da.sendinfo; me.receinfo = da.receinfor; me.usershu = me.receinfo.utotal; me.showtitle(); me.showobj.perfectScrollbar(); } me.loadci++; me.boolload = false; me.loaddatashow(da, iref); }); }; this.loaddatashow=function(ret,isbf, isls){ var a = ret.rows; this.lastdt = ret.nowdt; var i,len = a.length,cont,lex,nas,fase,nr,d,na=[],rnd,sid; $('#loadmored_'+this.num+'').remove(); if(isbf){ if(len>0)this.showobj.prepend('
---------↑以上是新加载---------
'); na = a; }else{ for(i= len-1; i>=0; i--)na.push(a[i]); } for(i= 0; i0 && !isls){ var s = '
'; if(ret.wdtotal==0){ s+='---------↑以上是历史记录---------'; if(len>=5){ this.showobj.prepend(''); this.isshangla = true; } }else{ s+='---↑以上是历史,还有未读信息'+ret.wdtotal+'条,点击加载---'; } s+='
'; if(!isbf)this.addcont(s); if(isbf)this._addclickf(); } }; //邀请 this.yaoqing=function(){ if(this.type!='group')return; js.changeuser(false,'usercheck','邀请人到会话中', { onselect:function(sna,sid){ if(!sid)return; me.yaoqings(sid); } }); }; this.yaoqings=function(sid){ js.msg('wait','邀请中...'); reim.ajax(reim.getapiurl('reim','yaoqinguid'),{val:sid,gid:this.gid},function(da){ js.msg(); if(da.success){ js.msgok('邀请成功'); me.userlistarr=false; me.getreceinfor(); }else{ js.msg('msg',da); } }); }; this.getreceinfor=function(){ reim.ajax(reim.getapiurl('reim','getreceinfor'),{type:this.type,gid:this.gid},function(ret){ me.receinfo = ret.data.receinfor; me.usershu = me.receinfo.utotal; me.showtitle(); }); }; this.exitgroup=function(){ if(this.type!='group')return; js.confirm('确定要此退出会话吗?',function(lx){ if(lx=='yes'){ me.exitgroups(); } }); }; this.showhuilist=function(){ var s = '
 加载人员...
'; js.tanbody('syscogshow','会话上人员('+this.usershu+')',420,100,{html:s}); if(!this.userlistarr){ reim.ajax(reim.getapiurl('reim','getgroupuser'),{type:this.type,gid:this.gid},function(ret){ me.showusershow(ret.data.uarr); },'get'); }else{ this.showusershow(this.userlistarr); } }; this.showusershow=function(a){ this.userlistarr = a; var i,len=a.length,s='',oi=0; s+=''; for(i=0;i
'+a[i].name+'
'; if(oi%5==0)s+='
'; } s+='
'; $('#showuserlist').html(s); }; this.exitgroups=function(){ js.msg('wait','退出中...'); reim.ajax(reim.getapiurl('reim','exitgroup'),{gid:this.gid}, function(da){ js.msgok('成功退出此会话,无法在此会话发消息了'); }); }; this.contshozt=function(d){ return strformat.contshozt(d,'web/'); }; this.addcont=function(cont, isbf){ var o = this.showobj; if(cont){if(isbf){o.prepend(cont);}else{o.append(cont);}} clearTimeout(this.scrolltime); this.scrolltime = setTimeout(function(){ me.scrollboot(); me._addclickf(); }, 50); }; //滚动条到最下面 this.scrollboot=function(){ this.showobj.animate({scrollTop:get('viewcontent_'+this.num+'').scrollHeight},100); }; this._addclickf=function(){ var o = this.showobj.find('img[fid]'); o.unbind('click'); o.click(function(){ me.clickimg(this); }); }; this.clickimg=function(o1){ var o=$(o1); var fid=o.attr('fid'); var src = o1.src.replace('_s.','.'); $.imgview({url:src,ismobile:false}); }; this.loadmoreda=function(o1){ this.loaddata(o1, true); }; this.sendcont=function(ssnr){ if(this.sendbool)return; js.msg('none'); var o = this.inputobj; var nr = strformat.sendinstr(o.val()); nr = nr.replace(//gi,'>').replace(/\n/gi,'
'); if(ssnr)nr=ssnr; if(isempt(nr))return false; var conss = jm.base64encode(nr); if(conss.length>3998){ js.msg('msg','发送内容太多了'); return; } var nuid= js.now('time'),optdt = js.serverdt(); if(optdt==this.nowoptdt){ js.msg('msg','消息发太快了'); return; } this.nowoptdt = optdt; var cont= strformat.showqp('right','我',optdt, nr, nuid, this.sendinfo.face, nuid); this.addcont(cont); o.val('').focus(); this.sendconts(conss, nuid, optdt, 0); return false; }; //收到推送消息来了 this.receivedata=function(d){ var minid=this.minid; reim.ajax(reim.getapiurl('reim','getrecord'),{type:this.type,gid:this.gid,minid:0,lastdt:this.lastdt,loadci:this.loadci},function(ret){ me.loaddatashow(ret.data, false, true); }); }; this.onshow=function(){ if(this.newbool){ this.scrollboot(); } this.newbool = false; }; this.onkeydown=function(e){ var code = e.keyCode; if(code==13 && !e.ctrlKey){ this.sendcont(); return false; } if(e.altKey && code==83){ this.sendcont(); return false; } if(e.altKey && code==67){ this.closechat(); return false; } if(e.ctrlKey && code==13){ this.addinput('\n'); return false; } return true; }; this.sendconts=function(conss, nuid, optdt, fid){ this.sendbool = true; var d = {cont:conss,gid:this.gid,type:this.type,nuid:nuid,optdt:optdt,fileid:fid}; reim.ajax(reim.getapiurl('reim','sendinfor'),d,function(ret){ me.sendsuccess(ret.data,nuid); },'post',function(){ me.senderror(nuid); }); var s1=''; if(this.type=='group')s1=jm.base64encode(''+adminname+':'); //显示到会话里 reim.showhistorys({ 'cont' : s1+d.cont, 'name' : this.receinfo.name, 'face' : this.receinfo.face, 'optdt' : d.optdt, 'type' : this.type, 'receid' : this.gid, 'stotal' : 0 }, true, true); }; this.senderror=function(nuid){ get(nuid).src='images/error.png'; get(nuid).title='发送失败'; this.sendbool=false; }; this.sendsuccess=function(d,nuid){ this.sendbool = false; if(!d.id){ this.senderror(nuid); return; } $('#'+d.nuid+'').remove(); var bo = false; d.messid=d.id; d.face = this.sendinfo.face; if(this.type=='group')d.gface=this.receinfo.face; this.listdata[nuid]=d; //添加右键事件 $('#qipaocont_'+nuid+'').contextmenu(function(e){ me.contright(this,e); return false; }); reim.serversend(d); }; this.addinput=function(s){ var val = this.inputobj.val()+s; this.inputobj.val(val).focus(); }; this.closechat=function(){ if(this.sendbool)return; reim.chatobj[this.num]=false; reim.closetabs(this.num); }; this.clicktools=function(o1){ var o = $(o1); var lx = o.attr('tools'); if(lx=='emts')this.getemts(o); if(lx=='file')this.sendfile(o); if(lx=='paste')this.pasteimg(); if(lx=='crop')this.cropScreen(); }; this.getemts=function(o){ if(!get('aemtsdiv')){ var s = ''; $('body').append(s); js.addbody('emts','hide','aemtsdiv'); } var o1 = $('#aemtsdiv'); o1.toggle(); var off = o.offset(); o1.css({'top':''+(off.top-205)+'px','left':''+(off.left)+'px'}); }; this.getemtsbq=function(wj, oi1,oi2, fzd, dx){ var i,oi=0,j1 = js.float(100/fzd); var s = ''; for(i=oi1; i<=oi2; i++){ oi++; s+=''; if(oi % fzd==0)s+=''; } s+='
'; return s; }; this.sendfile=function(bo){ uploadobj.nownum = this.num; uploadobj.click(); }; this.sendfileshow=function(f){ f.face = this.sendinfo.face; var fa = strformat.showupfile(f); var cont= fa.cont; this.upfilearr = fa; this.addcont(cont); }; this.sendfileok=function(f,str){ var a=js.decode(str); if(!a.id){ js.msg('msg', str); this.senderrornss(); return; } var tm= this.upfilearr,conss=''; f = a; strformat.upsuccess(a); if(js.isimg(f.fileext)){ conss = '[图片 '+f.filesizecn+']'; this._addclickf(); }else{ conss = '['+f.filename+' '+f.filesizecn+']' } this.sendconts(jm.base64encode(conss), tm.nuid, tm.optdt, a.id); }; this.senderrornss=function(){ this.senderror(this.upfilearr.nuid); }; this.readclip=function(evt){ var clipboardData = evt.clipboardData; if(!clipboardData)return; for(var i=0; i0 && chehui>0){ var t1 = js.now('time', this.rightdata.optdt),t2 = js.now('time'); var t3 = (t2-t1)*0.001; if(t3