jswx.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. QOM='xinhuwx_'
  2. js.wx={};
  3. js.wx.alert=function(msg,fun,tit, cof1){
  4. js.alert(msg,tit, fun);
  5. }
  6. js.wx.confirm=function(msg,fun,tit){
  7. js.confirm(msg,fun,tit);
  8. }
  9. js.wx.prompt=function(tit,msg,fun,nr){
  10. js.prompt(tit,msg,fun,nr);
  11. }
  12. js.apiurl = function(m,a,cans){
  13. var url=''+apiurl+'api.php?m='+m+'&a='+a+'';
  14. var cfrom='mweb';
  15. if(adminid)url+='&adminid='+adminid+'';
  16. if(device)url+='&device='+device+'';
  17. url+='&cfrom='+cfrom+'';
  18. if(token)url+='&token='+token+'';
  19. if(!cans)cans={};
  20. for(var i in cans)url+='&'+i+'='+cans[i]+'';
  21. return url;
  22. }
  23. js.ajax = function(m,a,d,funs, mod,checs, erfs, glx){
  24. if(js.ajaxbool && !js.ajaxwurbo)return;
  25. clearTimeout(js.ajax_time);
  26. var url = js.apiurl(m,a);
  27. js.ajaxbool = true;
  28. if(!mod)mod='mode';
  29. if(typeof(erfs)!='function')erfs=function(){};
  30. if(typeof(funs)!='function')funs=function(){};
  31. if(!checs)checs=function(){};
  32. var bs = checs(d);
  33. if(typeof(bs)=='string'&&bs!=''){
  34. js.msg('msg', bs);
  35. return;
  36. }
  37. if(typeof(bs)=='object')d=js.apply(d,bs);
  38. var tsnr = '努力处理中...';
  39. if(mod=='wait')js.msg(mod, tsnr);
  40. if(mod=='mode')js.wx.load(tsnr);
  41. function errsoers(ts, ds){
  42. js.wx.unload();
  43. js.setmsg(ts);
  44. js.msg('msg',ts);
  45. js.ajaxbool = false;
  46. erfs(ts, ds);
  47. }
  48. var type=(!d)?'get':'post';if(glx)type=glx;
  49. var ajaxcan={
  50. type:type,dataType:'json',data:d,url:url,
  51. success:function(ret){
  52. js.ajaxbool=false;
  53. js.wx.unload();
  54. clearTimeout(js.ajax_time);
  55. if(ret.code==199){
  56. js.wx.alert(ret.msg, function(){
  57. js.location('?d=we&m=login&backurl='+jm.base64encode(location.href)+'');
  58. });
  59. return;
  60. }
  61. if(ret.code!=200){
  62. errsoers(ret.msg, ret);
  63. }else{
  64. js.setmsg('');
  65. js.msg('none');
  66. funs(ret.data);
  67. }
  68. },
  69. error:function(e){
  70. errsoers('内部出错:'+e.responseText+'');
  71. }
  72. };
  73. $.ajax(ajaxcan);
  74. js.ajax_time = setTimeout(function(){
  75. if(js.ajaxbool){
  76. errsoers('Error:请求超时?');
  77. }
  78. }, 1000*30);
  79. }
  80. js.wx.load=function(txt){
  81. js.loading(txt);
  82. }
  83. js.wx.unload=function(){
  84. js.unloading();
  85. }
  86. js.wx.msgok=function(txt,fun,ms){
  87. js.msgok(txt,fun,ms);
  88. }
  89. js.showmenu=function(d){
  90. $('#menulistshow').remove();
  91. var d=js.apply({width:200,top:'50%',renderer:function(){},align:'center',onclick:function(){},oncancel:function(){}},d);
  92. var a=d.data;
  93. if(!a)return;
  94. var h1=$(window).height(),h2=document.body.scrollHeight,s1;
  95. if(h2>h1)h1=h2;
  96. var col='',oix;
  97. var s='<div align="center" id="menulistshow" style="background:rgba(0,0,0,0.6);height:'+h1+'px;width:100%;position:absolute;left:0px;top:0px;z-index:198;" oncontextmenu="return false">';
  98. s+='<div id="menulistshow_s" style="width:'+d.width+'px;margin-top:'+d.top+';position:fixed;-webkit-overflow-scrolling:touch;" class="menulist">';
  99. for(var i=0;i<a.length;i++){
  100. oix = '0';
  101. if(i>0)oix='0.5';
  102. s+='<div oi="'+i+'" style="text-align:'+d.align+';color:'+a[i].color+';border-top:'+oix+'px solid #dddddd">';
  103. s1=d.renderer(a[i]);
  104. if(s1){s+=s1}else{s+=''+a[i].name+'';}
  105. s+='</div>';
  106. }
  107. s+='</div>';
  108. s+='</div>';
  109. $('body').append(s);
  110. var mh = $(window).height();
  111. var l=($(window).width()-d.width)*0.5,o1 = $('#menulistshow_s'),t = (mh-o1.height()-10)*0.5;
  112. if(t<10){
  113. t = 10;
  114. o1.css({height:''+(mh-20)+'px','overflow':'auto'});
  115. }
  116. o1.css({'left':''+l+'px','margin-top':''+t+'px'});
  117. $('#menulistshow div[oi]').click(function(){
  118. var oi=parseFloat($(this).attr('oi'));
  119. d.onclick(a[oi],oi);
  120. });
  121. $('#menulistshow').click(function(){
  122. $(this).remove();
  123. try{d.oncancel();}catch(e){}
  124. });
  125. };
  126. js.wx.actionsheet=function(d){
  127. $('#actionsheetshow').remove();
  128. var d=js.apply({onclick:function(){},oncancel:function(){}},d);
  129. var a=d.data,s='';
  130. if(!a)return;
  131. s+='<div onclick="$(this).remove();" id="actionsheetshow">';
  132. s+='<div class="weui_mask_transition weui_fade_toggle" style="display:block"></div>';
  133. s+='<div class="weui_actionsheet weui_actionsheet_toggle" >';
  134. s+=' <div class="weui_actionsheet_menu">';
  135. for(var i=0;i<a.length;i++){
  136. s+='<div oi="'+i+'" style="color:'+a[i].color+'" class="weui_actionsheet_cell">'+a[i].name+'</div>';
  137. }
  138. s+=' </div>';
  139. s+=' <div class="weui_actionsheet_action"><div class="weui_actionsheet_cell" id="actionsheet_cancel">取消</div></div>';
  140. s+='</div>';
  141. s+='</div>';
  142. $('body').append(s);
  143. $('#actionsheetshow div[oi]').click(function(){
  144. var oi=parseFloat($(this).attr('oi'));
  145. d.onclick(a[oi],oi);
  146. });
  147. $('#actionsheetshow').click(function(){
  148. $(this).remove();
  149. try{d.oncancel();}catch(e){}
  150. });
  151. }
  152. js.isqywx=false;
  153. js.iswxbo=function(){
  154. var bo = true;
  155. var ua = navigator.userAgent.toLowerCase();
  156. if(ua.indexOf('micromessenger')<0)bo=false;
  157. if(bo && ua.indexOf('wxwork')>0)js.isqywx=true;
  158. return bo;
  159. }
  160. js.jssdkcall = function(bo){
  161. }
  162. js.jssdkstate = 0;
  163. js.jssdkwixin = function(qxlist,afe){
  164. if(!js.iswxbo())return js.jssdkcall(false);
  165. //if(js.isqywx)var wxurl = 'https://res.wx.qq.com/open/js/jweixin-1.1.0.js';
  166. var wxurl = 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js';
  167. if(!afe)$.getScript(wxurl, function(){
  168. js.jssdkwixin(qxlist, true);
  169. });
  170. if(!afe)return;
  171. var surl= location.href;
  172. if(!qxlist)qxlist= ['openLocation','getLocation','chooseImage','getLocalImgData','previewImage'];
  173. js.ajax('weixin','getsign',{url:jm.base64encode(surl),agentid:js.request('agentid')},function(ret){
  174. if(!ret.appId)return js.jssdkcall(false);
  175. wx.config({
  176. debug: false,
  177. appId: ret.appId,
  178. timestamp:ret.timestamp,
  179. nonceStr: ret.nonceStr,
  180. signature: ret.signature,
  181. jsApiList:qxlist
  182. });
  183. wx.ready(function(){
  184. if(js.jssdkstate==0)js.jssdkstate = 1;
  185. js.jssdkcall(true);
  186. });
  187. wx.error(function(res){
  188. js.jssdkstate = 2;
  189. });
  190. });
  191. }
  192. /**
  193. * 微信公众号jssdk授权
  194. */
  195. js.jssdkwxgzh = function(qxlist,afe){
  196. if(!js.iswxbo())return js.jssdkcall(false);
  197. var wxurl = 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js';
  198. if(!afe)$.getScript(wxurl, function(){
  199. js.jssdkwxgzh(qxlist, true);
  200. });
  201. if(!afe)return;
  202. var surl= location.href;
  203. if(!qxlist)qxlist= ['openLocation','getLocation','chooseImage','getLocalImgData','previewImage'];
  204. js.ajax('wxgzh','getsign',{url:jm.base64encode(surl)},function(ret){
  205. if(!ret.appId)return js.jssdkcall(false);
  206. wx.config({
  207. debug: false,
  208. appId: ret.appId,
  209. timestamp:ret.timestamp,
  210. nonceStr: ret.nonceStr,
  211. signature: ret.signature,
  212. jsApiList:qxlist
  213. });
  214. wx.ready(function(){
  215. if(js.jssdkstate==0)js.jssdkstate = 1;
  216. js.jssdkcall(true);
  217. });
  218. wx.error(function(res){
  219. js.jssdkstate = 2;
  220. });
  221. });
  222. }
  223. //长按处理
  224. function touchclass(cans){
  225. var me = this;
  226. this.onlongclick = function(){}
  227. this.onclick = function(){}
  228. this.onlongmenu = function(){}
  229. this.initbool = false;
  230. this.islongbool = false;
  231. for(var i in cans)this[i]=cans[i];
  232. this.touchstart=function(o1,evt){
  233. touchnowobj = this;
  234. this.islongbool = false;
  235. if(!this.initbool){
  236. o1.addEventListener('click', function(){
  237. me.onclicks(this, event);
  238. }, false);
  239. }
  240. this.obj = o1;
  241. this.initbool = true;
  242. clearTimeout(this.touchtime);
  243. this.touchtime = setTimeout('touchnowobj=false',1000);
  244. return true;
  245. }
  246. this.ismobile=function(){
  247. var llq = navigator.userAgent;
  248. llq = llq.toLowerCase();
  249. var sarr= ['android','mobile','iphone'],bo=false,i;
  250. for(i=0;i<sarr.length;i++){
  251. if(llq.indexOf(sarr[i])>-1){
  252. bo=true;
  253. break;
  254. }
  255. }
  256. return bo;
  257. }
  258. this.onclicks=function(o1, evt){
  259. var lx = evt.target.nodeName.toLowerCase();
  260. if(!this.islongbool && lx!='a')this.onclick(o1, evt);
  261. }
  262. this.touchstring=function(){
  263. var rnd = 'a'+js.getrand();
  264. touchnowoba[rnd] = this;
  265. var str = ' ontouchstart="return touchnowoba.'+rnd+'.touchstart(this,event)"';
  266. if(!this.ismobile()){
  267. str = ' onmouseover="touchnowoba.'+rnd+'.touchstart(this,event)"';
  268. str+= ' oncontextmenu="touchnowoba.'+rnd+'.onlongclick();return false;"';
  269. }
  270. return str;
  271. }
  272. this.reglongmenu=function(){
  273. touchnowobj = false;
  274. touchnowoba = {};
  275. document.addEventListener('touchstart', function(){
  276. clearTimeout(me.longtapv);
  277. me.longtapv = setTimeout(function(){me.longmenu();},300);
  278. }, false);
  279. document.addEventListener('touchmove', function(){
  280. clearTimeout(me.longtapv);
  281. }, false);
  282. document.addEventListener('touchend', function(){
  283. clearTimeout(me.longtapv);
  284. }, false);
  285. }
  286. this.longmenu = function(){
  287. setTimeout('touchnowobj=false',200);
  288. if(!touchnowobj)return;
  289. touchnowobj.islongbool = true;
  290. touchnowobj.onlongclick();
  291. this.onlongmenu();
  292. }
  293. }
  294. js.ling = function(w){
  295. var sve = 'style="height:'+w+'px;width:'+w+'px"';
  296. if(!w)sve='';
  297. return '<i '+sve+' class="rock-loading"></i>';
  298. }
粤ICP备19079148号