chat.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. var im={
  2. minid:999999999,
  3. init:function(){
  4. strformat.emotspath='web/';
  5. this.type = receinfor.type;
  6. this.gid = receinfor.gid;
  7. this.showobj = $('#showview');
  8. this.inputobj = $('#contentss');
  9. $('#btn').click(function(){
  10. im.sendcont();
  11. });
  12. this.loaddata();
  13. this.readinforshow();
  14. im.touchobj = $('#showview').rockdoupull({
  15. downbgcolor:'',
  16. downbool:true,
  17. ondownsuccess:function(){
  18. im.dropdown_success();
  19. }
  20. });
  21. this.resizehei();
  22. $(window).resize(this.resizehei);
  23. },
  24. submitinput:function(){
  25. try{im.sendcont();}catch(e){}
  26. return false;
  27. },
  28. getheight:function(ss){
  29. var hei = 50;if(!ss)ss=0;
  30. if(get('header_title'))hei+=50;
  31. return $(window).height()-hei+ss;
  32. },
  33. resizehei:function(){
  34. var h = im.getheight();
  35. im.showobj.css('height',''+h+'px');
  36. im.touchobj.resize();
  37. },
  38. loaddata:function(o1, iref){
  39. if(this.boolload)return;
  40. var iref = (!iref)?false:true;
  41. var minid= 0;
  42. if(iref)minid=this.minid;
  43. if(o1)$(o1).html('<img src="images/loadings.gif" height="14" width="15" align="absmiddle"> 加载中...');
  44. this.boolload = true;
  45. this.isshangla = false;
  46. js.ajax('reim','getrecord',{type:this.type,gid:this.gid,minid:minid,lastdt:''},function(ret){
  47. if(o1)$(o1).html('');
  48. im.boolload = false;
  49. im.loaddatashow(ret, iref);
  50. },'none', false,false,'get');
  51. },
  52. readinforshow:function(){
  53. setTimeout('im.readinforshows()',1000*10);
  54. },
  55. readinforshows:function(){
  56. var minid=this.minid;
  57. js.ajax('reim','getrecord',{type:this.type,gid:this.gid,minid:0,lastdt:this.lastdt},function(ret){
  58. im.loaddatashow(ret, false, true);
  59. im.readinforshow();
  60. },'none', false,false,'get');
  61. },
  62. loaddatashow:function(ret,isbf, isls){
  63. var a = ret.rows;
  64. this.lastdt = ret.nowdt;
  65. var i,len = a.length,cont,lex,nas,fase,nr,d,na=[],rnd,sid;
  66. $('#loadmored').remove();
  67. if(isbf){
  68. if(len>0)this.showobj.prepend('<div class="showblanks">---------↑以上是新加载---------</div>');
  69. na = a;
  70. }else{
  71. for(i= len-1; i>=0; i--)na.push(a[i]);
  72. }
  73. for(i= 0; i<len; i++){
  74. d = na[i];
  75. sid = parseFloat(d.id);
  76. lex = 'right';
  77. nas = '我';
  78. fase= adminface;
  79. if(d.sendid!=adminid){
  80. lex='left';
  81. nas= d.sendname;
  82. fase= d.face;
  83. }
  84. nr = this.contshozt(d.filers);
  85. if(nr=='')nr= jm.base64decode(d.cont);
  86. rnd = 'mess_'+sid+'';
  87. cont= strformat.showqp(lex,nas,d.optdt,nr ,'', fase, rnd);
  88. if(!isbf){
  89. this.addcont(cont, isbf);
  90. }else{
  91. this.showobj.prepend(cont);
  92. }
  93. if(sid<this.minid)this.minid=sid;
  94. }
  95. if(len>0 && !isls){
  96. var s = '<div id="histordiv" class="showblanks" >';
  97. if(ret.wdtotal==0){
  98. s+='---------↑以上是历史记录---------';
  99. if(len>=5){
  100. //this.showobj.prepend('<div id="loadmored" class="showblanks" ><a href="javascript:;" onclick="im.loadmoreda(this)">点击加载更多...</a></div>');
  101. this.isshangla = true;
  102. }
  103. }else{
  104. s+='---↑以上是历史,还有未读信息'+ret.wdtotal+'条,<a href="javascript:;" onclick="im.loaddata(this)">点击加载</a>---';
  105. }
  106. s+='</div>';
  107. if(!isbf)this.addcont(s);
  108. if(isbf)this._addclickf();
  109. }
  110. if(im.touchobj)im.touchobj.ondownok();
  111. },
  112. dropdown_success:function(){
  113. if(this.isshangla){
  114. this.loadmoreda(false);
  115. }else{
  116. setTimeout(function(){im.touchobj.ondownok()},1000);
  117. }
  118. },
  119. loadmoreda:function(o1){
  120. this.loaddata(o1, true);
  121. },
  122. addcont:function(cont, isbf){
  123. var o = this.showobj;
  124. if(cont){if(isbf){o.prepend(cont);}else{o.append(cont);}}
  125. clearTimeout(this.scrolltime);
  126. this.scrolltime = setTimeout(function(){
  127. im.showobj.animate({scrollTop:get('showview').scrollHeight},100);
  128. im._addclickf();
  129. }, 50);
  130. },
  131. _addclickf:function(){
  132. var o = this.showobj.find('img[fid]');
  133. o.unbind('click');
  134. o.click(function(){
  135. im.clickimg(this);
  136. });
  137. },
  138. clickimg:function(o1){
  139. var o=$(o1);
  140. var fid=o.attr('fid');
  141. var src = o1.src.replace('_s.','.');
  142. $.imgview({url:src,ismobile:true});
  143. },
  144. contshozt:function(d){
  145. return strformat.contshozt(d,'web/');
  146. },
  147. sendcont : function(ssnr){
  148. if(js.ajaxbool)return;
  149. js.msg('none');
  150. var o = this.inputobj;
  151. var nr = strformat.sendinstr(o.val());
  152. nr = nr.replace(/</gi,'&lt;').replace(/>/gi,'&gt;').replace(/\n/gi,'<br>');
  153. if(ssnr)nr=ssnr;
  154. if(isempt(nr))return false;
  155. var conss = jm.base64encode(nr);
  156. if(conss.length>500){
  157. js.msg('msg','发送内容太多了');
  158. return;
  159. }
  160. var nuid= js.now('time'),optdt = js.serverdt();
  161. var cont= strformat.showqp('right','我',optdt, nr, nuid, adminface);
  162. this.addcont(cont);
  163. o.val('').focus();
  164. this.sendconts(conss, nuid, optdt, 0);
  165. return false;
  166. },
  167. sendconts:function(conss, nuid, optdt, fid){
  168. var d = {cont:conss,gid:this.gid,type:this.type,nuid:nuid,optdt:optdt,fileid:fid};
  169. js.ajax('reim','sendinfor',d,function(ret){
  170. im.sendsuccess(ret,nuid);
  171. },'none',false,function(){
  172. im.senderror(nuid);
  173. });
  174. },
  175. senderror:function(nuid){
  176. js.ajaxbool = false;
  177. get(nuid).src='images/error.png';
  178. get(nuid).title='发送失败';
  179. },
  180. sendsuccess:function(d,nuid){
  181. this.bool = false;
  182. if(!d.id){
  183. this.senderror(nuid);
  184. return;
  185. }
  186. $('#'+d.nuid+'').remove();
  187. var bo = false;
  188. d.messid=d.id;
  189. d.face = adminface;
  190. },
  191. addinput:function(s){
  192. var val = this.inputobj.val()+s;
  193. this.inputobj.val(val).focus();
  194. },
  195. showemit:function(){
  196. var da = [];
  197. var a = strformat.emotsarr,i;
  198. for(i=1;i<50;i++)da.push({name:'&nbsp; <img src="web/images/im/emots/qq/'+(i-1)+'.gif" align="absmiddle">&nbsp;'+a[i], num:a[i]});
  199. js.showmenu({
  200. data:da,width:150,align:'left',
  201. onclick:function(d){
  202. im.addinput(d.num);
  203. }
  204. });
  205. },
  206. sendfile:function(){
  207. if(typeof(uploadobj)=='undefined')uploadobj = $.rockupload({
  208. inputfile:'allfileinput',
  209. updir:'reimchat',
  210. urlparams:{noasyn:'yes'}, //不需要同步到文件平台上
  211. initpdbool:true,
  212. onchange:function(d){
  213. im.sendfileshow(d);
  214. },
  215. onprogress:function(f,per,evt){
  216. strformat.upprogresss(per);
  217. },
  218. onsuccess:function(f,str,o1){
  219. im.sendfileok(f,str);
  220. },
  221. onerror:function(str){
  222. js.msg('msg', str);
  223. im.senderror(im.upfilearr.nuid);
  224. }
  225. });
  226. strformat.upobj = uploadobj;
  227. uploadobj.click();
  228. },
  229. sendfileshow:function(f){
  230. f.face = adminface;
  231. var fa = strformat.showupfile(f);
  232. var cont= fa.cont;
  233. this.upfilearr = fa;
  234. this.addcont(cont);
  235. },
  236. sendfileok:function(f,str){
  237. var tm= this.upfilearr,conss='';
  238. var a = js.decode(str);
  239. a.isimg = f.isimg;
  240. strformat.upsuccess(a);
  241. if(f.isimg){
  242. conss = '[图片 '+a.filesizecn+']';
  243. }else{
  244. conss = '['+f.filename+' '+f.filesizecn+']'
  245. }
  246. this.sendconts(jm.base64encode(conss), tm.nuid, tm.optdt, a.id);
  247. },
  248. fileyulan:function(pn,fid){
  249. var url = '?m=public&a=fileviewer&id='+fid+'';
  250. js.location(url);
  251. }
  252. }
  253. strformat.clickfile=function(fid,lx){
  254. js.fileopt(fid,lx);
  255. }