Utils.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Created by Jacky.gao on 2016/7/27.
  3. */
  4. window.iframe_id_=1;
  5. export function nextIFrameId(){
  6. window.iframe_id_++;
  7. return '_iframe'+window.iframe_id_;
  8. };
  9. export function getParameter(name) {
  10. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  11. var r = window.location.search.substr(1).match(reg);
  12. if (r != null)return r[2];
  13. return null;
  14. };
  15. export function ajaxSave(url,parameters,callback) {
  16. $.ajax({
  17. type:'POST',
  18. url,
  19. data:parameters,
  20. success:function (result) {
  21. callback(result);
  22. },
  23. error:function (req) {
  24. if(req.status===401){
  25. bootbox.alert("权限不足,不能进行此操作.");
  26. }else{
  27. bootbox.alert('服务端错误,操作失败!');
  28. }
  29. }
  30. });
  31. }
  32. export function formatDate(date,format){
  33. if(typeof date === 'number'){
  34. date=new Date(date);
  35. }
  36. if(typeof date==='string'){
  37. return date;
  38. }
  39. var o = {
  40. "M+" : date.getMonth()+1,
  41. "d+" : date.getDate(),
  42. "H+" : date.getHours(),
  43. "m+" : date.getMinutes(),
  44. "s+" : date.getSeconds()
  45. };
  46. if(/(y+)/.test(format))
  47. format=format.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
  48. for(var k in o)
  49. if(new RegExp("("+ k +")").test(format))
  50. format = format.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  51. return format;
  52. };