init.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var genUrl = "http://121.201.66.101:9999";
  2. var baseUrl = "http://121.37.6.200:8088";
  3. // GET请求
  4. function getAjax(opts, data) {
  5. $.Deferred(function(){});
  6. return new Promise(function(resolve, reject) {
  7. $.ajax({
  8. url: opts.http + opts.url,
  9. type: opts.type,
  10. dataType: "json",
  11. data: data,
  12. headers: {
  13. "Authorization": opts.tok
  14. },
  15. error: function() {
  16. localStorage.removeItem("AjaxGen");
  17. localStorage.removeItem("ylToken");
  18. top.location.href = "../index.html";
  19. },
  20. success: function(dart) {
  21. if(dart.code == 401||(dart.status != undefined&&dart.status != 1)){
  22. let _src = window.location.pathname.split("/view/");
  23. localStorage.removeItem("AjaxGen");
  24. localStorage.removeItem("ylToken");
  25. top.location.href = "../index.html?id="+(_src[1].split(".html")[0]);
  26. }else{
  27. resolve(dart);
  28. }
  29. }
  30. });
  31. })
  32. }
  33. // POST请求
  34. function postAjax(opts, data) {
  35. $.Deferred(function(){});
  36. return new Promise(function(resolve, reject) {
  37. $.ajax({
  38. url: opts.http + opts.url,
  39. type: opts.type,
  40. dataType: "JSON",
  41. contentType: 'application/json; charset=UTF-8',
  42. data: JSON.stringify(data),
  43. headers: {
  44. "Authorization": opts.tok
  45. },
  46. error: function() {
  47. localStorage.removeItem("AjaxGen");
  48. localStorage.removeItem("ylToken");
  49. top.location.href = "../index.html";
  50. },
  51. success: function(dart) {
  52. if(dart.code == 401||dart.status == -1){
  53. let _src = window.location.pathname.split("/view/");
  54. localStorage.removeItem("AjaxGen");
  55. localStorage.removeItem("ylToken");
  56. top.location.href = "../index.html?id="+(_src[1].split(".html")[0]);
  57. }else{
  58. resolve(dart);
  59. }
  60. }
  61. });
  62. })
  63. }
  64. function getTime(_time) {
  65. let date = _time
  66. const yyyy = date.getFullYear();
  67. const MM = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
  68. const dd = date.getDate() > 9 ? date.getDate() : '0' + date.getDate();
  69. const HH = date.getHours() > 9 ? date.getHours() : '0' + date.getHours();
  70. const mm = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes();
  71. const ss = date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds();
  72. return [yyyy + '-' + MM + '-' + dd, " " + HH + ':' + mm + ':' + ss];
  73. }