Utils.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 (response) {
  24. if(response && response.status===401){
  25. bootbox.alert("权限不足,不能进行此操作.");
  26. }else{
  27. if(response && response.responseText){
  28. bootbox.alert("<span style='color: red'>服务端错误:"+response.responseText+"</span>");
  29. }else{
  30. bootbox.alert("<span style='color: red'>服务端出错</span>");
  31. }
  32. }
  33. }
  34. });
  35. }
  36. export function formatDate(date,format){
  37. if(typeof date === 'number'){
  38. date=new Date(date);
  39. }
  40. if(typeof date==='string'){
  41. return date;
  42. }
  43. var o = {
  44. "M+" : date.getMonth()+1,
  45. "d+" : date.getDate(),
  46. "H+" : date.getHours(),
  47. "m+" : date.getMinutes(),
  48. "s+" : date.getSeconds()
  49. };
  50. if(/(y+)/.test(format))
  51. format=format.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
  52. for(var k in o)
  53. if(new RegExp("("+ k +")").test(format))
  54. format = format.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  55. return format;
  56. };