apiServer.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Created by JKZL-A on 2017/10/24.
  3. */
  4. define(['jquery', 'promise', 'layer', 'jsHelper'], function ($, Promise, layer, jsHelper) {
  5. jsHelper.setLayerCon();
  6. var baseUrl = '/iot/';
  7. function httpGet(url,options) {
  8. //发送ajax请求
  9. return new Promise(function(resolve, reject) {
  10. $.ajax(url,
  11. $.extend({},{
  12. type: 'GET',
  13. dataType: 'JSON',
  14. beforeSend: function(request) {
  15. },
  16. error: function(res) {
  17. reject(res)
  18. },
  19. success: function(res) {
  20. if(res.status && res.status == -200) {
  21. layer.msg("登录失效,请重新登录!")
  22. setTimeout(function() {
  23. window.location.replace('./login.html')
  24. },2000)
  25. return ;
  26. } else {
  27. resolve(res)
  28. }
  29. }
  30. },options));
  31. })
  32. }
  33. function httpPost(url,options) {
  34. //发送ajax请求
  35. return new Promise(function(resolve, reject) {
  36. $.ajax( url,
  37. $.extend({},{
  38. type: 'POST',
  39. dataType: 'JSON',
  40. beforeSend: function(request) {
  41. },
  42. error: function(res) {
  43. reject(res)
  44. },
  45. success: function(res) {
  46. if(res.status && res.status == -200) {
  47. layer.msg("登录失效,请重新登录!")
  48. setTimeout(function() {
  49. window.location.replace('./login.html')
  50. },2000)
  51. return ;
  52. } else {
  53. resolve(res)
  54. }
  55. }
  56. },options));
  57. })
  58. }
  59. var APIService = {
  60. indexPage: function () {//首页
  61. return baseUrl + 'attendance/index'
  62. },
  63. autoLogin: function (opt) {//单点登录
  64. return httpPost(baseUrl + 'login/autoLogin', opt)
  65. },
  66. login: function(opt) {//登录
  67. return httpPost(baseUrl + 'login/submit', opt)
  68. },
  69. out: function (opt) {//退出
  70. sessionStorage.clear();
  71. return httpGet(baseUrl + 'login/exit', opt)
  72. },
  73. ambulanceSearch:function (opt) {//救护车列表
  74. return httpGet(baseUrl + 'ambulance/search', opt)
  75. },
  76. attendanceList:function (opt) {//保存出勤记录
  77. return httpGet(baseUrl + 'attendance/list', opt)
  78. },
  79. attendanceSave:function (opt) {//保存出勤记录
  80. return httpPost(baseUrl + 'attendance/save', opt)
  81. },
  82. attendanceUpdate:function (opt) {//更改出勤状态
  83. return httpPost(baseUrl + 'attendance/update', opt)
  84. },
  85. attendanceDetail:function (opt) {//出勤任务详情
  86. return httpGet(baseUrl + 'attendance/detail', opt)
  87. }
  88. }
  89. return APIService;
  90. });