util.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. function doajax(method, dataurl, data, sucessCallBack, errorCallBack) {
  2. var user_key = undefined;
  3. var user = $.zui.store.get("user")
  4. if (typeof(user) == "undefined" || user == null) {
  5. } else {
  6. user_key = "XinTong " + (user.token);
  7. }
  8. if (typeof(user_key) == "undefined" || user_key == null) {
  9. $.ajax({
  10. type: method,
  11. url: dataurl,
  12. contentType: "application/json",
  13. dataType: "json",
  14. async: true,
  15. data: JSON.stringify(data),
  16. success: sucessCallBack,
  17. error: function(error) {
  18. if (HandleError(error)) return;
  19. errorCallBack(error);
  20. }
  21. })
  22. } else {
  23. $.ajax({
  24. type: method,
  25. url: dataurl,
  26. contentType: "application/json",
  27. dataType: "json",
  28. beforeSend: function(xhr) {
  29. xhr.setRequestHeader("token", user_key);
  30. },
  31. headers: {
  32. 'token': user_key
  33. },
  34. async: true,
  35. data: JSON.stringify(data),
  36. success: sucessCallBack,
  37. error: function(error) {
  38. if (HandleError(error)) return;
  39. errorCallBack(error);
  40. }
  41. })
  42. }
  43. }
  44. function ajaxGet(dataurl, data, sucessCallBack, errorCallBack) {
  45. doajax("GET", dataurl, data, sucessCallBack, errorCallBack)
  46. }
  47. function ajaxPost(dataurl, data, sucessCallBack, errorCallBack) {
  48. doajax("POST", dataurl, data, sucessCallBack, errorCallBack)
  49. }
  50. function ajaxPut(dataurl, data, sucessCallBack, errorCallBack) {
  51. doajax("PUT", dataurl, data, sucessCallBack, errorCallBack)
  52. }
  53. function ajaxDelete(dataurl, data, sucessCallBack, errorCallBack) {
  54. doajax("DELETE", dataurl, data, sucessCallBack, errorCallBack)
  55. }
  56. function HandleError(error) {
  57. if (typeof(error) != "undefined" && error != null) {
  58. if (typeof(error.status) != "undefined" && error.status != null) {
  59. if (error.status == 403) {
  60. //未登录退出
  61. swal({
  62. title: "提示",
  63. text: "登陆已经过期,将重新登陆!",
  64. timer: 3000,
  65. showConfirmButton: false
  66. }, function() {
  67. self.location = base_ui_url + UI_USER_LOGIN
  68. });
  69. return true;
  70. }
  71. }
  72. }
  73. return false;
  74. }
  75. // var ViewMap = new HashMap()
  76. // ViewMap.set("/view/mytask/unchecked.html", __inline('/view/mytask/unchecked.html'));
  77. // ViewMap.set("/view/mytask/unexamined.html", __inline('/view/mytask/unexamined.html'));
  78. // ViewMap.set("/view/mytask/undispatched.html", __inline('/view/mytask/undispatched.html'));
  79. // ViewMap.set("/view/mytask/dispatched.html", __inline('/view/mytask/dispatched.html'));
  80. // ViewMap.set("/view/constant/constant.html", __inline('/view/constant/constant.html'));