1
0

jswx.js 8.8 KB

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