request.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //动态获取url
  2. //const URL = getUrl();
  3. //console.log('动态获取URL' + URL)
  4. // function getUrl(){
  5. // return window.location.protocol+'//'+window.location.host
  6. // }
  7. //本地调试url
  8. const URL = "http://172.16.120.213:8080/";
  9. //const URL = "http://127.0.0.1:5500/";
  10. //这里登陆用户名、密码 写活?
  11. const LOGIN_NAME = "admin";
  12. const LOGIN_PASSWORD = "e10adc3949ba59abbe56e057f20f883e";
  13. const STATISTICS = "YtIoT/iot/alarm/view/getWjDataStatisticsList"; //数据统计查询
  14. //const STATISTICS = "data/statistics.json"; //数据统计查询
  15. const DEVICE_LIST = "YtIoT/iot/alarm/view/getWjDeviceList"; //设备列表查询
  16. //const DEVICE_LIST = "../data/deviceList.json";//设备列表查询
  17. const DEVICE_INFO_LIST = "YtIoT/iot/alarm/view/getWjDeviceInfoList" //设备详情查询
  18. const ALARM_LIST = "YtIoT/iot/alarm/view/getWjAlarmList"; //告警列表查询
  19. //const ALARM_LIST = "../data/alarmList.json";//告警列表查询
  20. const ALARM_HANDLE = "YtIoT/iot/alarm/view/updateWjAlarm";
  21. function ajaxRequest(path, method, data, success, error, type = 1) {
  22. let url = URL + path;
  23. let loginUser = {
  24. "V_LOGINNAME": LOGIN_NAME,
  25. "V_PASSWORD": LOGIN_PASSWORD,
  26. }
  27. if (type == 1) {
  28. data.queryJson = JSON.stringify(loginUser);
  29. } else {
  30. let paramJson = {};
  31. for (key in loginUser) {
  32. paramJson[key] = loginUser[key];
  33. }
  34. for (key in data) {
  35. paramJson[key] = data[key];
  36. }
  37. data = {}
  38. data.queryJson = JSON.stringify(paramJson);
  39. }
  40. $.ajax({
  41. async: false, //同步
  42. data: data,
  43. url: url,
  44. type: method, //请求方式 post get delete put
  45. dataType: "json",
  46. beforeSend: function(XMLHttpRequest) {
  47. // $("#loading").html("<img src='images/loading.gif' />")
  48. // handlePreloader();
  49. // $(".loadingdata").append('<div class="preloader"></div>');
  50. },
  51. success: success,
  52. error: error
  53. });
  54. }