You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

228 lines
5.7 KiB

  1. var base_api="http://wxsct.zhizhuchuxing.com/";
  2. base_api="";
  3. //设置字符串类型的本地缓存
  4. function setStorage(objName, objValue){
  5. var sto = window.localStorage;
  6. if (sto)
  7. sto.setItem(objName, objValue);
  8. }
  9. //读取字符串类型的本地缓存
  10. function getStorage(objName){
  11. var ret = '';
  12. var sto = window.localStorage;
  13. if (sto)
  14. ret = sto.getItem(objName);
  15. return ret;
  16. }
  17. //清除本地缓存,如没指定名称则为清空所有缓存
  18. function clearStorage(objName){
  19. var sto = window.localStorage;
  20. if (sto) {
  21. if (objName)
  22. sto.removeItem(objName);
  23. else
  24. sto.clear();
  25. }
  26. }
  27. //设置Json类型的本地缓存
  28. function setStorJson(objName, json){
  29. if (json)
  30. setStorage(objName, JSON.stringify(json));
  31. }
  32. //读取Json类型的本地缓存
  33. function getStorJson(objName){
  34. var ret = null;
  35. var str = getStorage(objName);
  36. if (str)
  37. ret = JSON.parse(str);
  38. return ret;
  39. }
  40. function iflogin(){
  41. $.ajax({
  42. type:"post",
  43. url:base_api+"./zz-fx/control.php",
  44. data:{type:"distribut_iflogin"},
  45. dataType: "json",
  46. success: function (data) {
  47. console.log(data);
  48. if(data.iflogin == 1){
  49. //alert("用户未登录,请先登录");
  50. window.wxc.xcConfirm("用户未登录,请先登录", window.wxc.xcConfirm.typeEnum.info,{
  51. onOk:function(){
  52. window.location.href="login.html"
  53. }
  54. });
  55. }else{
  56. return;
  57. }
  58. },
  59. fail: function (date) {
  60. // 此处放失败后执行的代码
  61. }
  62. });
  63. }
  64. //打印日志
  65. function ZZLog(str){
  66. var isLog=true;
  67. if(isLog){
  68. console.log(str);
  69. }
  70. }
  71. //获取时间
  72. function getDateTime(nTypeFlag) {
  73. var tNowTime = new Date();
  74. var myYear = ';' + tNowTime.getFullYear() + ';';
  75. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  76. var myDay = ';' + tNowTime.getDate() + ';';
  77. var myHour = ';' + tNowTime.getHours() + ';';
  78. var myMinu = ';' + tNowTime.getMinutes() + ';';
  79. var mySecond = ';' + tNowTime.getSeconds() + ';';
  80. if(myMonth.length < 4) myMonth = '0' + myMonth;
  81. if(myDay.length < 4) myDay = '0' + myDay;
  82. if(myHour.length < 4) myHour = '0' + myHour;
  83. if(myMinu.length < 4) myMinu = '0' + myMinu;
  84. if(mySecond.length < 4) mySecond = '0' + mySecond;
  85. var cNewTimeStr;
  86. switch(nTypeFlag + 1 - 1) {
  87. case 0:
  88. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  89. break;
  90. case 1:
  91. cNewTimeStr = myYear + myMonth + myDay;
  92. break;
  93. case 2:
  94. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  95. break;
  96. case 3:
  97. cNewTimeStr = myHour + myMinu + mySecond;
  98. break;
  99. case 4:
  100. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  101. break;
  102. case 5:
  103. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  104. break;
  105. case 6:
  106. cNewTimeStr = myYear;
  107. break;
  108. case 7:
  109. cNewTimeStr = myYear + '-' + myMonth;
  110. break;
  111. case 8: //得到上一个月的今天
  112. var date = getDateTime(0);
  113. var arr = date.split('-');
  114. var year = arr[0]; //获取当前日期的年份
  115. var month = arr[1]; //获取当前日期的月份
  116. var day = arr[2]; //获取当前日期的日
  117. var days = new Date(year, month, 0);
  118. days = days.getDate(); //获取当前日期中月的天数
  119. var year2 = year;
  120. var month2 = parseInt(month) - 1;
  121. if(month2 == 0) {
  122. year2 = parseInt(year2) - 1;
  123. month2 = 12;
  124. }
  125. var day2 = day;
  126. var days2 = new Date(year2, month2, 0);
  127. days2 = days2.getDate();
  128. if(day2 > days2) {
  129. day2 = days2;
  130. }
  131. if(month2 < 10) {
  132. month2 = '0' + month2;
  133. }
  134. cNewTimeStr = year2 + '-' + month2 + '-' + day2;
  135. break;
  136. case 9: //得到下一个月的今天
  137. var date = getDateTime(0);
  138. var arr = date.split('-');
  139. var year = arr[0]; //获取当前日期的年份
  140. var month = arr[1]; //获取当前日期的月份
  141. var day = arr[2]; //获取当前日期的日
  142. var days = new Date(year, month, 0);
  143. days = days.getDate(); //获取当前日期中的月的天数
  144. var year2 = year;
  145. var month2 = parseInt(month) + 1;
  146. if(month2 == 13) {
  147. year2 = parseInt(year2) + 1;
  148. month2 = 1;
  149. }
  150. var day2 = day;
  151. var days2 = new Date(year2, month2, 0);
  152. days2 = days2.getDate();
  153. if(day2 > days2) {
  154. day2 = days2;
  155. }
  156. if(month2 < 10) {
  157. month2 = '0' + month2;
  158. }
  159. var t2 = year2 + '-' + month2 + '-' + day2;
  160. return t2;
  161. break;
  162. case 10:
  163. cNewTimeStr = myYear +'/' +myMonth +'/'+ myDay;
  164. break;
  165. case 11:
  166. if (myMonth != 10 || myMonth != 11 || myMonth != 12) {
  167. myMonth = myMonth.substring(1,myMonth.length-1);
  168. }
  169. cNewTimeStr = myMonth +'月'+ myDay+'日';
  170. break;
  171. default:
  172. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  173. break;
  174. }
  175. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  176. return cNewTimeStr;
  177. }
  178. //得到url上的参数
  179. function getPar(par){
  180. var local_url = document.location.href;
  181. local_url = decodeURI(local_url);
  182. var get = local_url.indexOf(par +"=");
  183. if(get == -1){
  184. return "";
  185. }
  186. var get_par = local_url.slice(par.length + get + 1);
  187. var nextPar = get_par.indexOf("&");
  188. if(nextPar != -1){
  189. get_par = get_par.slice(0, nextPar);
  190. }
  191. return get_par;
  192. }
  193. //js判断一个日期是星期几 传入 年/月/日
  194. function getWeekDay(day){
  195. var a = new Array("日", "一", "二", "三", "四", "五", "六");
  196. var week = new Date(day).getDay();
  197. var str = "星期"+ a[week];
  198. return str;
  199. }
  200. //截取日期参数
  201. function getMonthAndDayByDate(datestr,info){
  202. var dateAry = datestr.split('-');
  203. var cNewTimeStr;
  204. switch(info){
  205. case 'year':
  206. cNewTimeStr = dateAry[0];
  207. break;
  208. case 'month':
  209. cNewTimeStr = dateAry[1];
  210. break;
  211. default:
  212. cNewTimeStr = dateAry[2];
  213. break;
  214. }
  215. return cNewTimeStr;
  216. }