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.2KB

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