New UI layout
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.

base.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {decrypt} from "./cookiehelper.js";
  2. import {_serverUrl} from "./setting.js";
  3. let serverUrl = _serverUrl();
  4. let baseUserInfo = decrypt(document.cookie.split("=")[1]);
  5. let baseSessionId = baseUserInfo.sessionId;
  6. export function getData(url) {
  7. var datastr = null;
  8. var method = "GET";
  9. let serviceurl = serverUrl + url;
  10. return $.ajax({
  11. type: method,
  12. url: serviceurl,
  13. crossDomain: true,
  14. contentType: "application/json",
  15. cache: true,
  16. jsonp: false,
  17. data: datastr,
  18. beforeSend: function (xhr) {
  19. if (baseUserInfo != undefined && baseUserInfo != null) {
  20. xhr.setRequestHeader(
  21. "Authorization",
  22. "Basic " + JSON.parse(baseUserInfo).sessionId
  23. );
  24. xhr.setRequestHeader("geoposition", 0 + ":" + 0);
  25. }
  26. },
  27. });
  28. }
  29. export function getDataObj(url, data, async, type) {
  30. //url, data, true, "POST"
  31. let serviceurl = serverUrl + url;
  32. return $.ajax({
  33. type: type,
  34. url: serviceurl,
  35. data: JSON.stringify(data),
  36. contentType: "application/json",
  37. traditional: true,
  38. crossDomain: true,
  39. async: async,
  40. beforeSend: function (xhr) {
  41. if (baseUserInfo != undefined && baseUserInfo != null) {
  42. xhr.setRequestHeader(
  43. "Authorization",
  44. "Basic " + JSON.parse(baseUserInfo).sessionId
  45. );
  46. xhr.setRequestHeader("geoposition", 0 + ":" + 0);
  47. }
  48. },
  49. });
  50. }
  51. export function formatLocal(dateTime) {
  52. var hou = new Date(dateTime).getHours(),
  53. sec,
  54. min,
  55. day,
  56. month,
  57. years;
  58. if (hou < 24) {
  59. min = new Date(dateTime).getMinutes();
  60. if (min < 60) {
  61. sec = new Date(dateTime).getSeconds();
  62. if (sec < 60) {
  63. return sec + " Seconds";
  64. }
  65. } else {
  66. return min + " Minutes";
  67. }
  68. return hou + " Hours";
  69. } else {
  70. //24 >
  71. day = new Date(dateTime).getHours();
  72. if (day > 31) {
  73. // 31 day
  74. month = new Date(dateTime).getMonth();
  75. if (month > 12) {
  76. // 12 months
  77. years = new Date(dateTime).getFullYear();
  78. return years + " Years";
  79. }
  80. return month + " month";
  81. }
  82. return day + " day";
  83. }
  84. }