reim.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  1. /**
  2. * REIM即时通信主js
  3. * caratename:雨中磐石(rainrock)
  4. * caratetime:2017-07-20 21:40:00
  5. * homepage:www.rockoa.com
  6. */
  7. //打开聊天会话
  8. function openchat(id, lx,face){
  9. if(!lx)lx=0;var types=['user','group'];
  10. var sle = (types[lx]) ? types[lx] : lx;
  11. var url = '?d=reim&m=chat&uid='+id+'&type='+sle+'',csne={};
  12. if(face)csne.icon=face;
  13. js.open(url, 480,500, ''+sle+'_'+id+'',{},csne);
  14. }
  15. var windowfocus=true;
  16. var reim = {
  17. connectbool:false,
  18. otherlogin:false,
  19. timeloads:0,
  20. ruloadtime:10*60,
  21. userarr:{},
  22. deptarr:{},
  23. grouparr:{},
  24. maindata:{},
  25. agentarr:{},
  26. lastloaddt:'',
  27. apiurl:function(m,a){
  28. return 'api.php?m='+m+'&a='+a+'';
  29. },
  30. show:function(){
  31. nwjs.init();
  32. nwjs.createtray(''+systitle+'-'+adminname+'', 1);
  33. bodyunload=function(){
  34. nwjs.removetray();
  35. }
  36. nwjs.serverdata=function(d){
  37. return reim.serverdata(d);
  38. }
  39. this.date = js.now();
  40. notifyobj=new notifyClass({
  41. title:'系统提醒',
  42. sound:'web/res/sound/todo.ogg',
  43. sounderr:'',
  44. soundbo:true,
  45. showbool:false
  46. });
  47. this.mainshow();//显示主界面
  48. this.righthistroboj = $.rockmenu({
  49. data:[],
  50. itemsclick:function(d){
  51. reim.rightclick(d);
  52. }
  53. });
  54. $(window).resize(this.resize);
  55. $(window).focus(function(){windowfocus=true});
  56. $(window).blur(function(){windowfocus=false});
  57. //数秒
  58. setInterval('reim.timeload()', 1000);
  59. document.ondragover=function(e){e.preventDefault();};
  60. document.ondrop=function(e){e.preventDefault();};
  61. },
  62. openrecord:function(){
  63. var url = '?homeurl=cmVpbSxyZWNvcmQsYXR5cGU9bXk:&homename=5oiR55qE5Lya6K!d6K6w5b2V&menuid=MjI3';
  64. js.open(url,1000,550,'chatrecord');
  65. },
  66. timeload:function(){
  67. this.timeloads++;
  68. //刷新
  69. if(this.timeloads >= this.ruloadtime){
  70. this.timeloads = 0;
  71. this.reload();
  72. }
  73. if(this.timeloads==5)this.getonline();
  74. //如果服务端断开,用ajax连接
  75. if(this.timeloads % 10==0){
  76. this.loadredata();
  77. }
  78. },
  79. //内部服务处理
  80. serverdata:function(a){
  81. var lx = a.atype;
  82. if(lx=='cropfinish' && !this.cropScreenbo && a.filepath){
  83. nwjs.winshow();
  84. }
  85. if(lx=='focus')nwjs.winshow();
  86. if(lx=='crop')this.cropScreen(true);
  87. if(lx=='notify')this.shownotify(a);
  88. if(lx=='openchat')this.openchat(a.id,a.type);
  89. if(lx=='getlogin')return {uid:adminid,uname:adminname,face:adminface};
  90. if(lx=='getipmac')return nwjs.getipmac();
  91. if(lx=='office')nwjs.editoffice(a.paramsstr);
  92. if(lx=='upfile')return nwjs.filetobase64(a.path);
  93. if(lx=='gpath')return nwjs.getpath();
  94. },
  95. shownotify:function(d1){
  96. var d = js.apply({icon:'images/logo.png','title':'系统提醒',url:''}, d1);
  97. if(d.msg)notifyobj.showpopup(d.msg,{icon:d.icon,title:d.title,url:d.url,click:function(b){
  98. if(b.url)nwjs.openurl(b.url);
  99. return true;
  100. }});
  101. },
  102. resize:function(){
  103. var h = winHb()-140-40;
  104. $('#reim_mainview').css('height',''+h+'px');
  105. },
  106. cropScreen:function(){
  107. var oatg = nwjs.getpath();
  108. nw.Shell.openItem(''+oatg+'/images/reimcaptScreen.exe');
  109. },
  110. //显示聊天主界面
  111. mainshow:function(bo){
  112. if(get('reim_main')){
  113. this.connectservers();
  114. return;
  115. }
  116. var h = winHb()-140-40;
  117. var s = '<div id="reim_main" style="position:relative" class="reim_main">';
  118. s+='<div class="gradienth" style="height:70px;overflow:hidden">';
  119. s+=' <table style="top:0px;left:0px" cellspacing="0" cellpadding="0" width="100%"><tr><td height="70" style="padding:0px 10px"><div style="height:40px;overflow:hidden"><img onclick="reim.openuserzl('+adminid+')" style="border-radius:50%;cursor:pointer" src="'+adminface+'" id="myface" width="40" height="40"></div></td><td width="100%"><div>'+adminname+'<span style="font-size:12px;color:#999999">('+adminranking+')</span></div><div style="font-size:12px;color:#999999" class="blank20">'+deptallname+'</div></tr></table>';
  120. s+='</div>';
  121. s+=' <div style="border-bottom:1px #dedede solid"><input placeholder="搜索联系人/会话/应用" id="reim_keysou" style="width:100%;padding:0px 5px;height:40px;line-height:30px;border:none;background:none url(web/images/im/sousuo.png) 200px 5px no-repeat;"></div>';
  122. s+=' <span class="badge red" style="position:absolute;top:100px;left:10%;display:none" id="chat_alltotal">0</span>';
  123. s+=' <span class="badge red" style="position:absolute;top:100px;left:35%;display:none" id="agent_alltotal">0</span>';
  124. s+=' <div class="headertab"><div style="width:25%" class="active" title="消息会话" onclick="reim.tabchagne(0, this)"><i class="icon-comment-alt"></i></div><div style="width:25%" title="应用" onclick="reim.tabchagne(3,this)"><i class="icon-th-large"></i></div><div style="width:25%" title="组织结构" onclick="reim.tabchagne(1,this)"><i class="icon-sitemap"></i></div><div style="width:25%" title="会话/群" onclick="reim.tabchagne(2,this)"><i class="icon-group"></i></div></div>';
  125. s+=' <div id="reim_mainview" style="height:'+h+'px;overflow:auto">';
  126. s+=' <div id="reim_headercenter" style="position:relative">';
  127. s+=' <div tabdiv="0"><div id="historylist_tems" style="padding-top:50px;text-align:center;color:#cccccc"><span style="font-size:40px"><i class="icon-comment-alt"></i></span><br>暂无消息</div><div class="listviewt" id="historylist"></div> </div>';
  128. s+=' <div tabdiv="1" class="usersslist" style="display:none"><span id="showdept_0"></span></div>';
  129. s+=' <div tabdiv="2" id="reim_showgroupdiv" class="usersslist" style="display:none;"></div>';
  130. s+=' <div tabdiv="3" id="reim_showagetdiv" style="display:none;"></div>';
  131. s+=' </div>';
  132. s+=' </div>';
  133. s+='<div style="height:30px;overflow:hidden;border-top:1px #dddddd solid; background-color:#eeeeee"><div class="toolsliao"><span onclick="reim.indexsyscog()" title="设置"><i class="icon-cog"></i></span><span onclick="reim.creategroup()" title="创建会话"><i class="icon-plus"></i></span><span onclick="location.reload()" title="刷新"><i class="icon-refresh"></i></span><span onclick="reim.openrecord()" title="会话记录"><i class="icon-file-alt"></i></span><span onclick="reim.loginexit()" style="float:right" title="退出"><i class="icon-signout"></i></span>&nbsp;<font id="reim_statusserver" style="font-size:12px"></font></div></div>';
  134. s+='</div>';
  135. $('#reim_viewshow').html(s);
  136. this.resize();
  137. $('#reim_keysou').keyup(function(){reim.searchss();});
  138. $('#reim_keysou').click(function(){reim.searchss();});
  139. this.initdata(); //初始化数据
  140. },
  141. ajax:function(url,da,fun,type,efun){
  142. if(!da)da={};if(!type)type='get';
  143. if(typeof(fun)!='function')fun=function(){};
  144. if(typeof(efun)!='function')efun=function(){};
  145. var atyp = type.split(',');type=atyp[0];
  146. function errshow(esr){
  147. js.msg('msg',esr);
  148. efun(esr);
  149. }
  150. var ajaxcan={
  151. type:type,
  152. data:da,url:url+'&cfrom=reim',
  153. success:function(ret){
  154. if(ret.code==199){
  155. reim.loginexits();
  156. return;
  157. }
  158. if(ret.code==200){
  159. fun(ret.data);
  160. }else{
  161. errshow(ret.msg);
  162. }
  163. },error:function(e){
  164. errshow('处理出错:'+e.responseText+'');
  165. }
  166. };
  167. ajaxcan.dataType='json';
  168. $.ajax(ajaxcan);
  169. },
  170. //连接到服务端
  171. connectserver:function(){
  172. this.loaddata('config');
  173. },
  174. connectservers:function(){
  175. if(this.connectbool){
  176. this.serverstatus(1);
  177. return;
  178. }
  179. var bo = this.showconfig(this.showconfigarr);
  180. if(bo)js.msg('wait','连接中...');
  181. },
  182. showconfig:function(a){
  183. if(this.connectbool){
  184. this.serverstatus(1);
  185. return false;
  186. }
  187. if(!a){
  188. this.serverstatus(3);
  189. return false;
  190. }
  191. var wsurl = jm.base64decode(a.wsurl),receid = a.recid;
  192. this.showconfigarr = a;
  193. if(isempt(wsurl) || wsurl.indexOf('ws')!=0){
  194. this.serverstatus(3);
  195. return false;
  196. }
  197. clearTimeout(this.relianshotime_time);
  198. websocketobj = new websocketClass({
  199. adminid:adminid,
  200. reimfrom:receid,
  201. wshost:wsurl,
  202. sendname:adminname,
  203. onerror:function(o,ws){
  204. reim.connectbool=false;
  205. reim.serverstatus(0);
  206. js.msg('msg','REIM无法连接服务器1<br><span id="lianmiaoshoetime"></span><a href="javascript:;" onclick="reim.connectservers()">[重连]</a>',0);
  207. reim.relianshotime(30);
  208. },
  209. onmessage:function(str){
  210. reim.connectbool=true;
  211. clearTimeout(reim.relianshotime_time);
  212. var a=js.decode(str);
  213. reim.receivemesb(a);
  214. },
  215. onopen:function(){
  216. reim.connectbool=true;
  217. reim.serverstatus(1);
  218. clearTimeout(reim.relianshotime_time);
  219. js.msg('none');
  220. reim.initnotify();
  221. },
  222. onclose:function(o,e){
  223. reim.connectbool=false;
  224. if(reim.otherlogin)return;
  225. reim.serverstatus(0);
  226. js.msg('msg','REIM连接已经断开了<br><span id="lianmiaoshoetime"></span><a href="javascript:;" onclick="reim.connectservers()">[重连]</a>',0);
  227. reim.relianshotime(30);
  228. }
  229. });
  230. return true;
  231. },
  232. loginexit:function(){
  233. js.confirm('确定要退出'+systitle+'吗?',function(lx){
  234. if(lx=='yes')reim.loginexits();
  235. });
  236. },
  237. loginexits:function(){
  238. if(!nwjsgui){
  239. window.close();
  240. }else{
  241. this.ajax(this.apiurl('login','loginexit'),{},function(ret){
  242. js.setoption('autologin', '0');
  243. js.location('?d=reim&a=login');
  244. });
  245. }
  246. },
  247. serverstatus:function(lx){
  248. var s = '<font color="green">已连接</font>';s='';
  249. if(lx==0)s='<font color="red">未连接</font>'
  250. if(lx==2)s='<font color="#ff6600">在别处连接</font>'
  251. if(lx==3)s='<font color="blue">没服务端</font>';
  252. $('#reim_statusserver').html(s);
  253. },
  254. relianshotime:function(oi){
  255. clearTimeout(this.relianshotime_time);
  256. $('#lianmiaoshoetime').html('('+oi+'秒后重连)');
  257. if(oi<=0){
  258. this.connectservers();
  259. }else{
  260. this.relianshotime_time=setTimeout('reim.relianshotime('+(oi-1)+')',1000);
  261. }
  262. },
  263. //服务端发消息调用opener.reim.serversend(a);
  264. serversend:function(a){
  265. if(!this.connectbool)return false;
  266. websocketobj.send(a);
  267. return true;
  268. },
  269. //获取在线人员
  270. getonline:function(){
  271. this.serversend({'atype':'getonline'});
  272. },
  273. //加载数据
  274. loadhistory:function(){
  275. this.loaddata('history');
  276. },
  277. reload:function(){
  278. this.initdata();
  279. },
  280. initdatas:function(){
  281. this.initbackd(this.bdats);
  282. },
  283. //没有服务端定时去ajax读取。
  284. loadredata:function(){
  285. if(this.connectbool)return;
  286. this.ajax(this.apiurl('indexreim','ldata'),{type:'history','loaddt':jm.base64encode(this.lastloaddt)}, function(ret){
  287. var hist = js.decode(ret.json);
  288. reim.lastloaddt = ret.loaddt;
  289. reim.reloadhistory(hist);
  290. });
  291. },
  292. reloadhistory:function(a){
  293. var i,len=a.length,d;
  294. for(i=0;i<len;i++){
  295. d = a[i];d.form = 'ajax';
  296. if(d.sendid!=adminid)this.receivemesb(d);
  297. }
  298. },
  299. initdata:function(){
  300. this.ajax(this.apiurl('indexreim','indexinit'),{}, function(ret){
  301. reim.bdats = ret;
  302. js.servernow = ret.loaddt;
  303. js.getsplit();
  304. reim.initbackd(ret);
  305. });
  306. },
  307. firstpid:0,
  308. initbackd:function(ret){
  309. if(!ret.userjson)return;
  310. this.lastloaddt = ret.loaddt;
  311. this.maindata.darr = js.decode(ret.deptjson);
  312. this.maindata.uarr = js.decode(ret.userjson);
  313. this.maindata.garr = js.decode(ret.groupjson);
  314. this.maindata.aarr = js.decode(ret.agentjson);
  315. this.maindata.harr = js.decode(ret.historyjson);
  316. this.firstpid = this.maindata.darr[0].pid;
  317. this.myip = ret.ip;
  318. this.showuser(this.maindata.uarr);
  319. this.adminmyrs = this.userarr[adminid];
  320. adminname = this.adminmyrs.name;
  321. adminface = this.adminmyrs.face;
  322. this.showgroup(this.maindata.garr);
  323. this.showagent(this.maindata.aarr);
  324. this.showhistory(this.maindata.harr);
  325. this.shownowci = 0;
  326. this.showconfig(ret.config);
  327. if(ret.editpass==0)this.editpass('请先修改密码后在使用','none');
  328. },
  329. loaddata:function(type){
  330. this.ajax(this.apiurl('indexreim','ldata'),{type:type}, function(ret){
  331. var hist = js.decode(ret.json);
  332. reim['show'+ret.type+''](hist);
  333. });
  334. },
  335. //显示历史聊天列表
  336. showhistory:function(a){
  337. var i,len=a.length;
  338. $('#historylist_tems').show();
  339. $('#historylist').html('');
  340. for(i=0;i<len;i++){
  341. this.showhistorys(a[i]);
  342. }
  343. },
  344. showhistorys:function(d,pad, lex){
  345. if(!d)return;
  346. var s,ty,o=$('#historylist'),d1,st,attr,stst,cont,cls,nastr;
  347. ty = d.type;
  348. if(ty=='user')d1=this.userarr[d.receid];
  349. if(ty=='group')d1=this.grouparr[d.receid];
  350. if(d1){
  351. d.name = d1.name;
  352. d.face = d1.face;
  353. }else if(!lex && ty=='user'){
  354. this.ajax(this.apiurl('indexreim','loadinfo'),{type:ty,receid:d.receid}, function(ret){
  355. if(!ret){
  356. console.error('无法读取到'+ty+','+d.receid+'的信息');
  357. }else{
  358. reim.showuser(ret);
  359. reim.showhistorys(d, pad, true);
  360. }
  361. });
  362. return;
  363. }
  364. var num = ''+ty+'_'+d.receid+'';
  365. $('#history_'+num+'').remove();
  366. var stotal = 0;
  367. cont = jm.base64decode(d.cont);
  368. var ops = d.optdt.substr(11,5);
  369. if(d.optdt.indexOf(this.date)!=0)ops=d.optdt.substr(5,5);
  370. attr = 'oncontextmenu="return reim.historyright(this,event);" tsaid="'+d.receid+'" tsaype="'+d.type+'" ';
  371. st = d.stotal;if(st=='0')st='';
  372. stotal+=parseFloat(d.stotal);
  373. stst = '';
  374. cls = '';
  375. nastr= d.name;
  376. if(d.type=='user'){
  377. stst='uid="'+d.receid+'"';
  378. if(d1.online=='0')cls=' offline';
  379. }
  380. if(d.type=='group' && d1){
  381. if(d1.deptid=='1')nastr+=' <span class="reimlabel">全员</span>';
  382. if(d1.deptid>'1')nastr+=' <span class="reimlabel1">部门</span>';
  383. }
  384. s = '<div '+attr+' '+stst+' class="lists'+cls+'" rtype="hist" id="history_'+num+'" onclick="reim.openchat('+d.receid+',\''+ty+'\')">';
  385. s+='<table cellpadding="0" border="0" width="100%"><tr>';
  386. s+='<td style="padding-right:8px"><div style="height:34px;overflow:hidden"><img src="'+d.face+'"></div></td>';
  387. s+='<td align="left" width="100%"><div class="name">'+nastr+'</div><div class="huicont">'+cont+'</div></td>';
  388. s+='<td align="center" nowrap><span id="chatstotal_'+num+'" class="badge red">'+d.stotal+'</span><br><span style="color:#cccccc;font-size:10px">'+ops+'</span></td>';
  389. s+='</tr></table>';
  390. s+='</div>';
  391. if(!pad){o.append(s);}else{o.prepend(s)}
  392. $('#historylist_tems').hide();
  393. this.showbadge('chat');
  394. },
  395. //在线离线设置
  396. setonline:function(online){
  397. $('div[uid]').addClass('offline');
  398. var onlies = online.split(','),i,uid;
  399. for(i=0;i<onlies.length;i++){
  400. uid=onlies[i];
  401. this.setonlines(uid, 1);
  402. }
  403. },
  404. setonlines:function(uid, on){
  405. var d = this.userarr[uid];
  406. if(on==1){
  407. $('div[uid='+uid+']').removeClass('offline');
  408. }else{
  409. $('div[uid='+uid+']').addClass('offline');
  410. }
  411. this.userarr[uid].online = on;
  412. this.maindata.uarr[d.i].online = on;
  413. },
  414. historyright:function(o1,e){
  415. var rt = $(o1).attr('rtype');
  416. if(isempt(rt))return false;
  417. this.rightdivobj = o1;
  418. var d=[{name:'打开',lx:0}];
  419. if(rt.indexOf('agent')>-1){
  420. d.push({name:'打开窗口',lx:1});
  421. }
  422. if(rt.indexOf('hist')>-1){
  423. d.push({name:'删除此记录',lx:2});
  424. }
  425. this.righthistroboj.setData(d);
  426. this.righthistroboj.showAt(e.clientX-3,e.clientY-3);
  427. return false;
  428. },
  429. rightclick:function(d){
  430. var o1 = $(this.rightdivobj),lx=d.lx;
  431. var tsaid = o1.attr('tsaid'),
  432. tsayp = o1.attr('tsaype');
  433. if(lx==0){
  434. if(tsayp=='user')this.openuser(tsaid);
  435. if(tsayp=='group')this.opengroup(tsaid);
  436. }
  437. if(lx==2){
  438. o1.remove();
  439. var tst=$('#historylist').text();if(tst=='')$('#historylist_tems').show();
  440. this.ajax(this.apiurl('reim','delhistory'),{type:tsayp,gid:tsaid},false);
  441. }
  442. },
  443. //打开聊天界面
  444. openchat:function(id,type){
  445. this.showbadge('chat',''+type+'_'+id+'', 0);
  446. if(type=='agent'){
  447. this.openagent(id);
  448. }else{
  449. openchat(id,type);
  450. }
  451. this.setyd(type,id);
  452. },
  453. opengroup:function(id){
  454. this.openchat(id, 'group');
  455. },
  456. openuser:function(id){
  457. this.openchat(id, 'user');
  458. },
  459. //会话标识已读
  460. setyd:function(type,id){
  461. this.ajax(this.apiurl('reim','yiduall'),{type:type,gid:id},false);
  462. },
  463. //切换聊天主界面隐藏显示
  464. mainclose:function(){
  465. $('#reim_main').toggle();
  466. this.showzhu();
  467. },
  468. //隐藏主界面
  469. hidezhu:function(){
  470. $('#topheaderid').hide();
  471. $('.topcenter').hide();
  472. $('#zhutable').hide();
  473. },
  474. //显示主界面
  475. showzhu:function(){
  476. $('#topheaderid').show();
  477. $('.topcenter').show();
  478. $('#zhutable').show();
  479. },
  480. //选择卡切换
  481. tabchagne:function(oi,o1){
  482. $('.headertab div').removeClass();
  483. o1.className = 'active';
  484. $('#reim_headercenter').find("div[tabdiv]").hide();
  485. $('#reim_headercenter').find("div[tabdiv='"+oi+"']").show();
  486. if(oi=='1')this.showdept(this.firstpid,0);
  487. },
  488. //加载群会话列表
  489. loadgroup:function(){
  490. this.loaddata('group');
  491. },
  492. loadagent:function(){
  493. this.loaddata('agent');
  494. },
  495. showgroup:function(a){
  496. var i=0,len=a.length,s,d,o=$('#reim_showgroupdiv'),msg='';
  497. o.html('');
  498. for(i=0;i<len;i++){
  499. d = a[i];
  500. s = '<div style="padding-left:10px" id="group_'+d.id+'" onclick="reim.opengroup('+d.id+')"><img src="'+d.face+'" align="absmiddle">'+d.name+'';
  501. if(d.deptid=='1')s+=' <span class="reimlabel">全员</span>';
  502. if(d.deptid>'1')s+=' <span class="reimlabel1">部门</span>';
  503. s +='</div>';
  504. this.grouparr[d.id] = d;
  505. o.append(s);
  506. }
  507. },
  508. //显示组织结构
  509. showdept:function(pid, xu){
  510. var i=0,len,s='',a,wfj,cls;
  511. var sv= '#showdept_'+pid+'';if(xu==0)sv='#showdept_0';
  512. var o = $(sv);
  513. var tx= o.text();
  514. if(tx){if(xu!=0){o.toggle();}return;}
  515. len=this.maindata.uarr.length;
  516. for(i=0;i<len;i++){
  517. a=this.maindata.uarr[i];
  518. if(pid==a.deptid || a.deptidss.indexOf(','+pid+',')>-1){
  519. cls='offline';if(a.online==1)cls='';
  520. s='<div uid="'+a.id+'" class="'+cls+'" style="padding-left:'+(xu*20+10)+'px" onclick="reim.openuserzl('+a.id+')">';
  521. s+=' <img src="'+a.face+'" align="absmiddle"> '+a.name+' <font color="#888888">('+a.ranking+')<font>';
  522. s+='</div>';
  523. o.append(s);
  524. }
  525. }
  526. len = this.maindata.darr.length
  527. for(i=0;i<len;i++){
  528. a=this.maindata.darr[i];
  529. if(pid==a.pid){
  530. wfj = 'icon-folder-close-alt';
  531. if(a.ntotal=='0')wfj='icon-file-alt';
  532. s='<div style="padding-left:'+(xu*20+10)+'px" onclick="reim.showdept('+a.id+','+(xu+1)+')">';
  533. s+=' <i class="'+wfj+'"></i> '+a.name+'';
  534. s+='</div>';
  535. s+='<span id="showdept_'+a.id+'"></span>';
  536. o.append(s);
  537. if(xu==0)this.showdept(a.id, xu+1);
  538. }
  539. }
  540. },
  541. //显示用户
  542. showuser:function(a){
  543. var i=0,len=a.length,d;
  544. for(i=0;i<len;i++){
  545. d = a[i];
  546. d.i = i;
  547. d.online=0;
  548. this.maindata.uarr[i] = d;
  549. this.userarr[d.id] = d;
  550. }
  551. },
  552. //显示用户信息
  553. openuserzl:function(id){
  554. var d=this.userarr[id];
  555. if(!d)return;
  556. if(isempt(d.tel))d.tel='';if(isempt(d.email))d.email='';
  557. if(isempt(d.sex))d.sex='?';
  558. var s = '<div>';
  559. s+='<div align="center" style="padding:10px;"><img id="myfacess" onclick="$(this).imgview()" src="'+d.face+'" height="80" width="80" style="border-radius:40px;border:1px #eeeeee solid">';
  560. if(id==adminid)s+='<br><a href="javascript:;" id="fupbgonet" onclick="reim.upfaceobj.click()" style="font-size:12px">修改头像</a>';
  561. s+='</div>';
  562. s+='<div style="line-height:25px;padding:10px;padding-left:20px;"><font color=#888888>姓名:</font>'+d.name+'<br><font color=#888888>部门:</font>'+d.deptallname+'<br><font color=#888888>职位:</font>'+d.ranking+'<br><font color=#888888>性别:</font>'+d.sex+'<br><font color=#888888>电话:</font>'+d.tel+'<br><font color=#888888>手机:</font>'+d.mobile+'<br><font color=#888888>邮箱:</font>'+d.email+'</div>';
  563. s+='</div>';
  564. js.tanbody('userziliao',''+d.name+'', 240,350,{
  565. html:s,
  566. btn:[{text:'发消息'}]
  567. });
  568. $('#userziliao_btn0').click(function(){
  569. reim.openuser(id);
  570. });
  571. if(id==adminid){
  572. this.upfaceobj=$.rockupload({inputfile:'upfacess',uptype:'image',
  573. urlparams:{noasyn:'yes'},
  574. onsuccess:function(f,str){
  575. var a=js.decode(str);
  576. if(!a.id)return;
  577. reim.saveface(a.id);
  578. },
  579. onchange:function(){
  580. $('#fupbgonet').html('上传中...');
  581. }
  582. });
  583. };
  584. },
  585. saveface:function(fid){
  586. this.ajax(this.apiurl('reim','changeface'),{id:fid},function(face){
  587. get('myface').src=face;
  588. get('myfacess').src=face;
  589. adminface=face;
  590. js.setoption('adminface', face);
  591. $('#fupbgonet').html('修改成功');
  592. });
  593. },
  594. //显示应用
  595. showagent:function(a){
  596. var i=0,len=a.length,d,types,ty,o=$('#reim_showagetdiv'),s='',oi,atr;
  597. o.html('');
  598. var typearr = {};
  599. for(i=0;i<len;i++){
  600. d = a[i];
  601. d.i = i;
  602. this.agentarr[d.id] = d;
  603. if(!typearr[d.types])typearr[d.types]=[];
  604. typearr[d.types].push(d);
  605. }
  606. var col = 3,wd = 100/col;
  607. for(ty in typearr){
  608. len = typearr[ty].length;
  609. s='<div class="reim_agent_types">'+ty+'</div><table class="reim_agent_grid" width="100%"><tr>';
  610. oi = 0;
  611. for(i=0;i<len;i++){
  612. oi++;atr='';
  613. if(oi==1)atr='style="border-left:none"';
  614. if(oi==col)atr='style="border-right:none"';
  615. d = typearr[ty][i];
  616. s+='<td '+atr+' onclick="reim.openagent('+d.id+')" width="'+wd+'%">';
  617. s+='<div class="reim_agent_div">';
  618. s+=' <span id="agentstotal_'+d.num+'" class="badge red">'+d.stotal+'</span>';
  619. s+=' <div class="reim_agent_img"><img src="'+d.face+'"></div>';
  620. s+=' <div class="reim_agent_text">'+d.name+'</div>';
  621. s+='</div>';
  622. s+='</td>';
  623. if(oi%col==0){
  624. if(i<len-1)s+='</tr><tr>';
  625. oi=0;
  626. }
  627. }
  628. if(oi>0)for(i=oi;i<col;i++){
  629. atr='';
  630. if(i==col-1)atr='style="border-right:none"';
  631. s+='<td '+atr+' width="'+wd+'%">&nbsp;</td>';
  632. }
  633. s+='</tr></table>';
  634. o.append(s);
  635. }
  636. this.showbadge('agent');
  637. },
  638. showbadge:function(slx,num,lx){
  639. var to = 0,chanu=''+slx+'stotal_'+num+'';
  640. $("span[id^='"+slx+"stotal_']").each(function(){
  641. var o1,vd,ids;
  642. ids= this.id;
  643. o1 = $(this);
  644. vd = parseFloat(o1.text());
  645. if(ids==chanu){
  646. if(lx==0){vd=0;o1.text('0');}
  647. if(lx==1){vd++;o1.text(''+vd+'');}
  648. }
  649. if(vd==0){o1.hide();}else{o1.show();}
  650. to+=vd;
  651. });
  652. var o1 = $('#'+slx+'_alltotal');
  653. o1.text(''+to+'');
  654. if(to==0){o1.hide();}else{o1.show();}
  655. var oi = parseFloat($('#agent_alltotal').text()) + parseFloat($('#chat_alltotal').text());
  656. nwjs.changeicon(oi); //托盘图标
  657. },
  658. //打开应用
  659. openagent:function(id){
  660. var d = this.agentarr[id];
  661. this.showbadge('agent',d.num,0);
  662. var w = 1000,h=570,url = d.urlpc;
  663. if(isempt(url)){
  664. url = d.urlm;
  665. if(isempt(url)){
  666. url = '?d=we&m=ying&num='+d.num+''; //先默认用移动端
  667. }
  668. w = 320;
  669. }
  670. var jg = (url.indexOf('?')>-1)?'&':'?';
  671. url+=''+jg+'openfrom=reim';
  672. //考勤打卡
  673. if(d.num=='kqdaka'){
  674. this.opendaka();return;
  675. }
  676. js.open(url, w,h,'agent'+d.num+'');
  677. },
  678. //考勤打卡
  679. opendaka:function(bo){
  680. var url = '?d=reim&m=ying&a=daka',w = 550;h=300;
  681. js.open(url, w,h,'agentkqdaka',{},{icon:'images/adddk.png'});
  682. },
  683. //显示到会话列表上
  684. addhistory:function(lx,id,sot,cont,opt,sne,name,face){
  685. if(!sne)sne='';
  686. if(sne)sne=jm.base64encode(sne+':');
  687. if(lx!='group')sne='';
  688. var d={type:lx,receid:id,stotal:sot,cont:sne+cont,optdt:opt};
  689. if(name)d.name = name;
  690. if(face)d.face = face;
  691. this.showhistorys(d, true);
  692. },
  693. editpass:function(bt,cse){
  694. if(!bt)bt='修改密码';
  695. if(!cse)cse='';
  696. js.tanbody('winiframe',bt,260,300,{
  697. html:'<div style="height:250px;overflow:hidden"><iframe src="" name="openinputiframe" width="100%" height="100%" frameborder="0"></iframe></div>',
  698. bbar:'none',
  699. closed:cse
  700. });
  701. openinputiframe.location.href='?m=index&d=we&a=editpass&hideheader=true&ofrom=reim';
  702. },
  703. //别的地方登录
  704. otherlogins:function(){
  705. this.otherlogin = true;
  706. var msg='已在别的地方连接了';
  707. js.msg('success', msg, -1);
  708. this.serverstatus(2);
  709. },
  710. //服务端接收到推送消息
  711. receivemesb:function(d, lob){
  712. var lx=d.type,sendid=d.adminid,num,face,ops=false,msg='',ot,ots,garr,tits,gid;
  713. if(!sendid)sendid = d.sendid;
  714. if(lx=='offoline'){
  715. this.otherlogins();
  716. return;
  717. }
  718. if(lx=='getonline'){
  719. this.setonline(d.online);
  720. return;
  721. }
  722. var a = this.userarr[sendid];
  723. if(a){
  724. d.sendname=a.name;
  725. d.face = a.face;
  726. }else if(!lob){
  727. this.ajax(this.apiurl('indexreim','loadinfo'),{type:'user',receid:sendid}, function(ret){
  728. if(!ret){
  729. console.error('无法读取到'+sendid+'的信息');
  730. }else{
  731. reim.showuser(ret);
  732. reim.receivemesb(d, true);
  733. }
  734. });
  735. return;
  736. }
  737. gid = d.gid;
  738. if(lx == 'user' || lx == 'group'){
  739. num = ''+lx+'_'+sendid+'';
  740. if(lx == 'group')num = ''+lx+'_'+gid+'';
  741. ops = js.openrun(num, 'recemess', d);
  742. if(lx == 'group'){
  743. garr= this.grouparr[gid];
  744. if(!garr){
  745. this.loadgroup();
  746. garr={face:'images/group.png'};
  747. }
  748. face= garr.face;
  749. }
  750. this.setonlines(sendid,1);//说明是在线的
  751. var title = document.title+'消息';
  752. if(ops){
  753. ops.focus();
  754. }else{
  755. if(lx == 'user'){
  756. msg = '人员['+d.sendname+'],发来一条信息';
  757. notifyobj.showpopup(msg,{icon:d.face,sendid:sendid,title:title,rand:num,click:function(b){
  758. reim.openuser(b.sendid);
  759. return true;
  760. }});
  761. }
  762. if(lx == 'group'){
  763. if(!d.gname)d.gname = d.name;
  764. msg = '人员['+d.sendname+'],发来一条信息,来自['+d.gname+']';
  765. if(d.form=='ajax')d.sendname='';
  766. notifyobj.showpopup(msg,{icon:garr.face,gid:gid,title:title,rand:num,click:function(b){
  767. reim.opengroup(b.gid);
  768. return true;
  769. }});
  770. }
  771. }
  772. ot = $('#chatstotal_'+num+'');ots=ot.text();if(ots=='')ots='0';
  773. if(!ops)ots = parseFloat(ots)+1;
  774. if(lx=='user')this.addhistory(lx,sendid,ots,d.cont,d.optdt);
  775. if(lx=='group')this.addhistory(lx,gid,ots,d.cont,d.optdt,d.sendname);
  776. }
  777. //应用的通知提醒
  778. if(lx == 'agent'){
  779. garr = this.agentarr[gid];
  780. num = 'agent_'+gid+'';
  781. if(!garr){
  782. this.loadagent();
  783. garr={face:'images/logo.png',pid:0};
  784. }
  785. msg = ""+jm.base64decode(d.cont)+"";
  786. tits = d.title;
  787. if(!tits)tits = d.gname;
  788. notifyobj.showpopup(msg,{icon:garr.face,title:tits,gid:gid,rand:'agent_'+gid+'',url:d.url,click:function(b){
  789. if(b.url){
  790. js.open(b.url,760,500);
  791. return true;
  792. }else{
  793. //im.openagent(b.gid);
  794. return false;
  795. }
  796. }});
  797. ot = $('#chatstotal_'+num+'');ots=ot.text();if(ots=='')ots='0';
  798. if(!ops)ots = parseFloat(ots)+1;
  799. this.addhistory(lx,gid,ots,d.cont,d.optdt,'', tits, garr.face);
  800. }
  801. if(lx == 'loadgroup'){
  802. this.loadgroup();
  803. }
  804. },
  805. //通知设置
  806. initnotify:function(){
  807. var lx=notifyobj.getaccess();
  808. if(lx!='ok'){
  809. js.msg('msg','为了可及时收到信息通知 <br>请开启提醒,<span class="zhu cursor" onclick="reim.indexsyscog()">[开启]</span>',-1);
  810. }
  811. },
  812. indexsyscogs:function(){
  813. var str = notifyobj.getnotifystr('reim.indexsyscogss()');
  814. return '桌面通知提醒'+str+'';
  815. },
  816. indexsyscogss:function(){
  817. notifyobj.opennotify(function(){
  818. $('#indexsyscog_msg').html(reim.indexsyscogs());
  819. });
  820. },
  821. getsound:function(){
  822. var lx = js.getoption('soundcog'),chs=false;
  823. if(lx=='')lx='1';
  824. if(lx==1)chs=true;
  825. return chs;
  826. },
  827. setsound:function(o1){
  828. var lx=(o1.checked)?'1':'2';
  829. js.setoption('soundcog', lx);
  830. notifyobj.setsound(o1.checked);
  831. },
  832. indexsyscog:function(){
  833. var chs= (this.getsound())?'checked':'';
  834. var s='<div style="height:160px;overflow:auto;padding:5px 10px">';
  835. s+='<div style="padding:5px 0px;" id="indexsyscog_msg">'+this.indexsyscogs()+'</div>';
  836. s+='<div style="padding:5px 0px;border-top:1px #eeeeee solid"><label><input '+chs+' onclick="reim.setsound(this)" type="checkbox">新信息声音提示</label></div>';
  837. if(nwjsgui){
  838. var ksj=js.getoption('kuaijj','Q');
  839. var strw='ABCEDFGHIJKLMNOPQRSTUVWYZ',s1,cls1='';
  840. s+='<div style="padding:5px 0px;border-top:1px #eeeeee solid">主窗口快捷键:Ctrl+Alt+<select onchange="nwjs.changekuai(this)">';
  841. for(var i=0;i<strw.length;i++){
  842. s1= strw.substr(i,1);
  843. cls1='';if(ksj==s1){cls1='selected';}
  844. s+='<option '+cls1+' value="'+s1+'">'+s1+'</option>';
  845. }
  846. s+='</select></div>';
  847. var ips = nwjs.getipmac();
  848. s+='<div style="padding:5px 0px;border-top:1px #eeeeee solid">我局域网IP:'+ips.ip+'</div>';
  849. s+='<div style="padding:5px 0px;border-top:1px #eeeeee solid">我的MAC地址:'+ips.mac+'</div>';
  850. }else{
  851. }
  852. s+='<div style="padding:5px 0px;border-top:1px #eeeeee solid">网络IP:'+this.myip+'</div>';
  853. s+='</div>';
  854. js.tanbody('syscogshow','REIM设置',240,100,{html:s});
  855. },
  856. //搜索联系人/会话/应用
  857. searchss:function(){
  858. clearTimeout(this.searchsstime);
  859. this.searchsstime=setTimeout('reim.searchssss()',500);
  860. if(!this.searchright)this.searchright=$.rockmenu({
  861. data:[],iconswh:20,
  862. itemsclick:function(d){
  863. reim.searchclick(d.type,d.id);
  864. }
  865. });
  866. },
  867. searchclick:function(ty,id){
  868. if(ty=='user')this.openuser(id);
  869. if(ty=='group')this.opengroup(id);
  870. if(ty=='agent')this.openagent(id);
  871. },
  872. searchssss:function(){
  873. var o = $('#reim_keysou'),val=strreplace(o.val());
  874. var d=[];
  875. if(val==''){
  876. this.searchright.hide();
  877. return;
  878. }
  879. val=val.toLowerCase();
  880. var off=o.offset(),sid,a,s1;
  881. for(sid in this.userarr){
  882. a=this.userarr[sid];
  883. if(a.name.indexOf(val)>-1 || a.pingyin.indexOf(val)==0 || a.deptname.indexOf(val)>-1 || a.ranking.indexOf(val)>-1){
  884. s1=''+a.name+'<font color=#888888>('+a.ranking+')</font>';
  885. d.push({name:s1,id:a.id,icons:a.face,type:'user'});
  886. }
  887. }
  888. for(sid in this.grouparr){
  889. a=this.grouparr[sid];
  890. if(a.name.indexOf(val)>-1){
  891. s1=''+a.name+'<font color=#888888>(会话)</font>';
  892. d.push({name:s1,id:a.id,icons:a.face,type:'group'});
  893. }
  894. }
  895. for(sid in this.agentarr){
  896. a=this.agentarr[sid];
  897. if(a.name.indexOf(val)>-1){
  898. s1=''+a.name+'<font color=#888888>(应用)</font>';
  899. d.push({name:s1,id:a.id,icons:a.face,type:'agent'});
  900. }
  901. }
  902. if(d.length==0){
  903. this.searchright.hide();
  904. return;
  905. }
  906. this.searchright.setData(d);
  907. this.searchright.showAt(off.left+1,off.top+40,$('#reim_headercenter').width()-2);
  908. },
  909. //创建会话
  910. creategroup:function(){
  911. js.prompt('创建会话','请输入会话名称:',function(lx,v){
  912. if(lx=='yes'){
  913. if(!v){js.msg('msg','没有输入会话名称');return false;}
  914. js.msg('wait','创建中...');
  915. reim.ajax(reim.apiurl('reim','createlun'),{val:jm.base64encode(v)}, function(da){
  916. js.msg('success','创建成功,请打开会话窗口邀请人员加入');
  917. reim.loadgroup();
  918. });
  919. }
  920. });
  921. return false;
  922. },
  923. //退出会话
  924. exitgroup:function(gid){
  925. this.loadgroup();
  926. //$('#history_group_'+gid+'').remove();
  927. }
  928. };