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.
 
 
 
 
 
 

372 lines
8.8 KiB

  1. var base_api = "http://wxsct.zhizhuchuxing.com/";
  2. var test_api = "http://127.0.0.1/";
  3. base_api = "";
  4. base_api = "http://http://wx.zhizhuchuxing.com/weixin2/";
  5. base_api = "http://192.168.6.119/";
  6. //base_api="http://nwx.zhizhuchuxing.cn/";
  7. //pic_api="http://nwx.zhizhuchuxing.cn";
  8. base_api = '/module/';
  9. //pic_api = 'http://nwx.zhizhuchuxing.cn';
  10. pic_api = '';
  11. //读取sessionStorage缓存
  12. function setSessionStorage(objName, objValue) {
  13. var sto = window.sessionStorage;
  14. if(sto)
  15. sto.setItem(objName, objValue);
  16. }
  17. //读取字符串类型的本地缓存
  18. function getSessionStorage(objName) {
  19. var ret = '';
  20. var sto = window.sessionStorage;
  21. if(sto)
  22. ret = sto.getItem(objName);
  23. return ret;
  24. }
  25. //清除本地缓存,如没指定名称则为清空所有缓存
  26. function clearSessionStorage(objName) {
  27. var sto = window.sessionStorage;
  28. if(sto) {
  29. if(objName)
  30. sto.removeItem(objName);
  31. else
  32. sto.clear();
  33. }
  34. }
  35. //设置Json类型的sessionStorage缓存
  36. function setJsonSessionStorage(objName, json) {
  37. if(json)
  38. setSessionStorage(objName, JSON.stringify(json));
  39. }
  40. //读取Json类型的sessionStorage缓存
  41. function getJsonSessionStorage(objName) {
  42. var ret = null;
  43. var str = getSessionStorage(objName);
  44. if(str)
  45. ret = JSON.parse(str);
  46. return ret;
  47. }
  48. //设置字符串类型的本地缓存
  49. function setStorage(objName, objValue) {
  50. var sto = window.localStorage;
  51. if(sto)
  52. sto.setItem(objName, objValue);
  53. }
  54. //读取字符串类型的本地缓存
  55. function getStorage(objName) {
  56. var ret = '';
  57. var sto = window.localStorage;
  58. if(sto)
  59. ret = sto.getItem(objName);
  60. return ret;
  61. }
  62. //清除本地缓存,如没指定名称则为清空所有缓存
  63. function clearStorage(objName) {
  64. var sto = window.localStorage;
  65. if(sto) {
  66. if(objName)
  67. sto.removeItem(objName);
  68. else
  69. sto.clear();
  70. }
  71. }
  72. //设置Json类型的本地缓存
  73. function setStorJson(objName, json) {
  74. if(json)
  75. setStorage(objName, JSON.stringify(json));
  76. }
  77. //读取Json类型的本地缓存
  78. function getStorJson(objName) {
  79. var ret = null;
  80. var str = getStorage(objName);
  81. if(str)
  82. ret = JSON.parse(str);
  83. return ret;
  84. }
  85. function iflogin() {
  86. $.ajax({
  87. type: "post",
  88. url: base_api + "./zz-fx/control.php",
  89. data: {
  90. type: "distribut_iflogin"
  91. },
  92. dataType: "json",
  93. success: function(data) {
  94. console.log(data);
  95. if(data.iflogin == 1) {
  96. //alert("用户未登录,请先登录");
  97. window.wxc.xcConfirm("用户未登录,请先登录", window.wxc.xcConfirm.typeEnum.info, {
  98. onOk: function() {
  99. window.location.href = "login.html"
  100. }
  101. });
  102. } else {
  103. return;
  104. }
  105. },
  106. fail: function(date) {
  107. // 此处放失败后执行的代码
  108. }
  109. });
  110. }
  111. //打印日志
  112. function ZZLog(str) {
  113. var isLog = true;
  114. if(isLog) {
  115. console.log(str);
  116. }
  117. }
  118. //获取时间
  119. function getDateTime(nTypeFlag) {
  120. var tNowTime = new Date();
  121. var myYear = ';' + tNowTime.getFullYear() + ';';
  122. var myMonth = ';' + (tNowTime.getMonth() + 1 - 0) + ';';
  123. var myDay = ';' + tNowTime.getDate() + ';';
  124. var myHour = ';' + tNowTime.getHours() + ';';
  125. var myMinu = ';' + tNowTime.getMinutes() + ';';
  126. var mySecond = ';' + tNowTime.getSeconds() + ';';
  127. if(myMonth.length < 4) myMonth = '0' + myMonth;
  128. if(myDay.length < 4) myDay = '0' + myDay;
  129. if(myHour.length < 4) myHour = '0' + myHour;
  130. if(myMinu.length < 4) myMinu = '0' + myMinu;
  131. if(mySecond.length < 4) mySecond = '0' + mySecond;
  132. var cNewTimeStr;
  133. switch(nTypeFlag + 1 - 1) {
  134. case 0:
  135. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  136. break;
  137. case 1:
  138. cNewTimeStr = myYear + myMonth + myDay;
  139. break;
  140. case 2:
  141. cNewTimeStr = myHour + ':' + myMinu + ':' + mySecond;
  142. break;
  143. case 3:
  144. cNewTimeStr = myHour + myMinu + mySecond;
  145. break;
  146. case 4:
  147. cNewTimeStr = myYear + myMonth + myDay + myHour + myMinu + mySecond;
  148. break;
  149. case 5:
  150. cNewTimeStr = myYear + '年' + myMonth + '月' + myDay + '日';
  151. break;
  152. case 6:
  153. cNewTimeStr = myYear;
  154. break;
  155. case 7:
  156. cNewTimeStr = myYear + '-' + myMonth;
  157. break;
  158. case 8: //得到上一个月的今天
  159. var date = getDateTime(0);
  160. var arr = date.split('-');
  161. var year = arr[0]; //获取当前日期的年份
  162. var month = arr[1]; //获取当前日期的月份
  163. var day = arr[2]; //获取当前日期的日
  164. var days = new Date(year, month, 0);
  165. days = days.getDate(); //获取当前日期中月的天数
  166. var year2 = year;
  167. var month2 = parseInt(month) - 1;
  168. if(month2 == 0) {
  169. year2 = parseInt(year2) - 1;
  170. month2 = 12;
  171. }
  172. var day2 = day;
  173. var days2 = new Date(year2, month2, 0);
  174. days2 = days2.getDate();
  175. if(day2 > days2) {
  176. day2 = days2;
  177. }
  178. if(month2 < 10) {
  179. month2 = '0' + month2;
  180. }
  181. cNewTimeStr = year2 + '-' + month2 + '-' + day2;
  182. break;
  183. case 9: //得到下一个月的今天
  184. var date = getDateTime(0);
  185. var arr = date.split('-');
  186. var year = arr[0]; //获取当前日期的年份
  187. var month = arr[1]; //获取当前日期的月份
  188. var day = arr[2]; //获取当前日期的日
  189. var days = new Date(year, month, 0);
  190. days = days.getDate(); //获取当前日期中的月的天数
  191. var year2 = year;
  192. var month2 = parseInt(month) + 1;
  193. if(month2 == 13) {
  194. year2 = parseInt(year2) + 1;
  195. month2 = 1;
  196. }
  197. var day2 = day;
  198. var days2 = new Date(year2, month2, 0);
  199. days2 = days2.getDate();
  200. if(day2 > days2) {
  201. day2 = days2;
  202. }
  203. if(month2 < 10) {
  204. month2 = '0' + month2;
  205. }
  206. var t2 = year2 + '-' + month2 + '-' + day2;
  207. return t2;
  208. break;
  209. case 10:
  210. cNewTimeStr = myYear + '/' + myMonth + '/' + myDay;
  211. break;
  212. case 11:
  213. if(myMonth != 10 || myMonth != 11 || myMonth != 12) {
  214. myMonth = myMonth.substring(1, myMonth.length - 1);
  215. }
  216. cNewTimeStr = myMonth + '月' + myDay + '日';
  217. break;
  218. case 13:
  219. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay;
  220. break;
  221. default:
  222. cNewTimeStr = myYear + '-' + myMonth + '-' + myDay + ' ' + myHour + ':' + myMinu + ':' + mySecond;
  223. break;
  224. }
  225. cNewTimeStr = cNewTimeStr.replace(/;/g, "");
  226. return cNewTimeStr;
  227. }
  228. //得到url上的参数
  229. function getPar(par) {
  230. var local_url = document.location.href;
  231. local_url = decodeURI(local_url);
  232. var get = local_url.indexOf(par + "=");
  233. if(get == -1) {
  234. return "";
  235. }
  236. var get_par = local_url.slice(par.length + get + 1);
  237. var nextPar = get_par.indexOf("&");
  238. if(nextPar != -1) {
  239. get_par = get_par.slice(0, nextPar);
  240. }
  241. return get_par;
  242. }
  243. //js判断一个日期是星期几 传入 年/月/日
  244. function getWeekDay(day) {
  245. var a = new Array("日", "一", "二", "三", "四", "五", "六");
  246. var week = new Date(day).getDay();
  247. var str = "星期" + a[week];
  248. return str;
  249. }
  250. //截取日期参数
  251. function getMonthAndDayByDate(datestr, info) {
  252. var dateAry = datestr.split('-');
  253. var cNewTimeStr;
  254. switch(info) {
  255. case 'year':
  256. cNewTimeStr = dateAry[0];
  257. break;
  258. case 'month':
  259. cNewTimeStr = dateAry[1];
  260. break;
  261. default:
  262. cNewTimeStr = dateAry[2];
  263. break;
  264. }
  265. return cNewTimeStr;
  266. }
  267. //html存入json
  268. function setJsonHtml(data) {
  269. if(typeof(data) == "object") {
  270. var jsonArrayFinal = JSON.stringify(data);
  271. jsonArrayFinal = jsonArrayFinal.replace(/ /g, '');
  272. // jsonArrayFinal = jsonArrayFinal.replace(/"/g, '&quot;');
  273. return jsonArrayFinal;
  274. }
  275. }
  276. //取出html存入的json
  277. function getJsonHtml(data) {
  278. if(data) {
  279. var data_info = JSON.parse(data);
  280. return data_info;
  281. }
  282. }
  283. //获取前一天日期
  284. function before(d) {
  285. d = new Date(d);
  286. d = +d - 10006060 / 3 * 24;
  287. d = new Date(d);
  288. //return d;
  289. //格式化
  290. var year = ";" + d.getFullYear() + ";";
  291. var month = ";" + (d.getMonth() + 0 + 1) + ";";
  292. var day = ";" + d.getDate() + ";";
  293. if(year.length < 4) {
  294. year = "0" + year;
  295. }
  296. if(month.length < 4) {
  297. month = "0" + month;
  298. }
  299. if(day.length < 4) {
  300. day = "0" + day;
  301. }
  302. var datestr = year + "-" + month + "-" + day;
  303. datestr = datestr.replace(/;/g, "");
  304. return datestr;
  305. // return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
  306. }
  307. // 获取指定日期的前后几天
  308. function getDateByDay(addDayCount, curDate) {
  309. var d = new Date(curDate);
  310. d.setDate(d.getDate() + addDayCount); //获取AddDayCount天后的日期
  311. //格式化
  312. var year = ";" + d.getFullYear() + ";";
  313. var month = ";" + (d.getMonth() + 0 + 1) + ";";
  314. var day = ";" + d.getDate() + ";";
  315. if(year.length < 4) {
  316. year = "0" + year;
  317. }
  318. if(month.length < 4) {
  319. month = "0" + month;
  320. }
  321. if(day.length < 4) {
  322. day = "0" + day;
  323. }
  324. var datestr = year + "-" + month + "-" + day;
  325. datestr = datestr.replace(/;/g, "");
  326. return datestr;
  327. }
  328. //获取后一天日期
  329. function after(d) {
  330. d = new Date(d);
  331. d = +d + 10006060 / 3 * 24;
  332. d = new Date(d);
  333. //return d;
  334. //格式化
  335. var year = ";" + d.getFullYear() + ";";
  336. var month = ";" + (d.getMonth() + 0 + 1) + ";";
  337. var day = ";" + d.getDate() + ";";
  338. if(year.length < 4) {
  339. year = "0" + year;
  340. }
  341. if(month.length < 4) {
  342. month = "0" + month;
  343. }
  344. if(day.length < 4) {
  345. day = "0" + day;
  346. }
  347. var datestr = year + "-" + month + "-" + day;
  348. datestr = datestr.replace(/;/g, "");
  349. return datestr;
  350. // return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
  351. }