globalapi.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*------------------ Date Function ------------------------*/
  2. function GetFullToday( )
  3. {
  4. var d=new Date();
  5. var nday=d.getDate();
  6. var nmonth=d.getMonth()+1;
  7. var nyear=d.getFullYear();
  8. var strM=nmonth+'';
  9. if( nmonth<10 )
  10. strM='0'+nmonth;
  11. var strD=nday+'';
  12. if( nday<10 )
  13. strD='0'+nday;
  14. return nyear+'-'+strM+'-'+strD;
  15. }
  16. function GetFullDate()
  17. {
  18. var d=new Date();
  19. var tDate={};
  20. tDate.nyear=d.getFullYear();
  21. tDate.nmonth=d.getMonth()+1;
  22. tDate.nday=d.getDate();
  23. tDate.nhour=d.getHours();
  24. tDate.nminute=d.getMinutes();
  25. tDate.nsecond=d.getSeconds();
  26. tDate.nweek=d.getDay();
  27. tDate.ndate=d.getDate();
  28. var strM=tDate.nmonth+'';
  29. if( tDate.nmonth<10 )
  30. strM='0'+tDate.nmonth;
  31. var strD=tDate.nday+'';
  32. if( tDate.nday<10 )
  33. strD='0'+tDate.nday;
  34. var strH=tDate.nhour+'';
  35. if( tDate.nhour<10 )
  36. strH='0'+tDate.nhour;
  37. var strMin=tDate.nminute+'';
  38. if( tDate.nminute<10 )
  39. strMin='0'+tDate.nminute;
  40. var strS=tDate.nsecond+'';
  41. if( tDate.nsecond<10 )
  42. strS='0'+tDate.nsecond;
  43. tDate.strdate=tDate.nyear+'-'+strM+'-'+strD;
  44. tDate.strFulldate=tDate.strdate+' '+strH+':'+strMin+':'+strS;
  45. return tDate;
  46. }
  47. function Unixtimestamp2Date( nSecond )
  48. {
  49. var d=new Date(nSecond*1000);
  50. var tDate={};
  51. tDate.nyear=d.getFullYear();
  52. tDate.nmonth=d.getMonth()+1;
  53. tDate.nday=d.getDate();
  54. tDate.nhour=d.getHours();
  55. tDate.nminute=d.getMinutes();
  56. tDate.nsecond=d.getSeconds();
  57. tDate.nweek=d.getDay();
  58. tDate.ndate=d.getDate();
  59. var strM=tDate.nmonth+'';
  60. if( tDate.nmonth<10 )
  61. strM='0'+tDate.nmonth;
  62. var strD=tDate.nday+'';
  63. if( tDate.nday<10 )
  64. strD='0'+tDate.nday;
  65. tDate.strdate=tDate.nyear+'-'+strM+'-'+strD;
  66. return tDate.strdate;
  67. }
  68. //------------Array Function-------------
  69. Array.prototype.in_array = function (e) {
  70. let sArray= ',' + this.join(this.S) + ',';
  71. let skey=','+e+',';
  72. if(sArray.indexOf(skey)>=0)
  73. return true;
  74. else
  75. return false;
  76. }
  77. //------------String Function------------------
  78. /**
  79. * Delete Left/Right Side Blank
  80. */
  81. String.prototype.trim=function()
  82. {
  83. return this.replace(/(^\s*)|(\s*$)/g, '');
  84. }
  85. /**
  86. * Delete Left Side Blank
  87. */
  88. String.prototype.ltrim=function()
  89. {
  90. return this.replace(/(^\s*)/g,'');
  91. }
  92. /**
  93. * Delete Right Side Blank
  94. */
  95. String.prototype.rtrim=function()
  96. {
  97. return this.replace(/(\s*$)/g,'');
  98. }
  99. //----------------Get Param-------------
  100. function GetQueryString(name)
  101. {
  102. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  103. var r = window.location.search.substr(1).match(reg);
  104. if (r!=null)
  105. {
  106. return unescape(r[2]);
  107. }
  108. else
  109. {
  110. return null;
  111. }
  112. }
  113. function GetGetStr()
  114. {
  115. let strGet="";
  116. //获取当前URL
  117. let url = document.location.href;
  118. //获取?的位置
  119. let index = url.indexOf("?")
  120. if(index != -1) {
  121. //截取出?后面的字符串
  122. strGet = url.substr(index + 1);
  123. }
  124. return strGet;
  125. }
  126. /*--------------------JSON Function------------*/
  127. /*
  128. 功能:检查一个字符串是不是标准的JSON格式
  129. 参数: strJson 被检查的字符串
  130. 返回值: 如果字符串是一个标准的JSON格式,则返回JSON对象
  131. 如果字符串不是标准JSON格式,则返回null
  132. */
  133. function IsJson( strJson )
  134. {
  135. var tJson=null;
  136. try
  137. {
  138. tJson=JSON.parse(strJson);
  139. }
  140. catch(exception)
  141. {
  142. return null;
  143. }
  144. return tJson;
  145. }
  146. /*-----------------------Ajax Function--------------------*/
  147. /*对JQuery的Ajax函数的封装,只支持异步
  148. 参数说明:
  149. url 目标地址
  150. action post/get
  151. data 字符串格式的发送内容
  152. asyn true---异步模式;false-----同步模式;
  153. */
  154. function HttpReq( url,action, data,callbackfunc)
  155. {
  156. var strAction=action.toLowerCase();
  157. if( strAction=="post")
  158. {
  159. $.post(url,data,callbackfunc);
  160. }
  161. else if( strAction=="get")
  162. {
  163. $.get(url,callbackfunc);
  164. }
  165. }
  166. /*---------------Cookie Function-------------------*/
  167. function setCookie(name, value, time='',path='') {
  168. if(time && path){
  169. var strsec = time * 1000;
  170. var exp = new Date();
  171. exp.setTime(exp.getTime() + strsec * 1);
  172. document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path="+path;
  173. }else if(time){
  174. var strsec = time * 1000;
  175. var exp = new Date();
  176. exp.setTime(exp.getTime() + strsec * 1);
  177. document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
  178. }else if(path){
  179. document.cookie = name + "=" + escape(value) + ";path="+path;
  180. }else{
  181. document.cookie = name + "=" + escape(value);
  182. }
  183. }
  184. function getCookie(c_name)
  185. {
  186. if(document.cookie.length > 0) {
  187. c_start = document.cookie.indexOf(c_name + "=");//获取字符串的起点
  188. if(c_start != -1) {
  189. c_start = c_start + c_name.length + 1;//获取值的起点
  190. c_end = document.cookie.indexOf(";", c_start);//获取结尾处
  191. if(c_end == -1) c_end = document.cookie.length;//如果是最后一个,结尾就是cookie字符串的结尾
  192. return decodeURI(document.cookie.substring(c_start, c_end));//截取字符串返回
  193. }
  194. }
  195. return "";
  196. }
  197. function checkCookie(c_name) {
  198. username = getCookie(c_name);
  199. console.log(username);
  200. if (username != null && username != "")
  201. { return true; }
  202. else
  203. { return false; }
  204. }
  205. function clearCookie(name) {
  206. setCookie(name, "", -1);
  207. }
  208. /*--------Studio WX Message-------*/
  209. function IsInSlicer()
  210. {
  211. let bMatch=navigator.userAgent.match( RegExp('BBL-Slicer','i') );
  212. return bMatch;
  213. }
  214. function SendWXMessage( strMsg )
  215. {
  216. let bCheck=IsInSlicer();
  217. if(bCheck!=null)
  218. {
  219. window.wx.postMessage(strMsg);
  220. }
  221. }