http.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const config_config = require("../config/config.js");
  4. const stores_userDataManager = require("../stores/userDataManager.js");
  5. class http {
  6. //动态请求
  7. static DynamicRequest(api, post_data, call_back, isPost = true) {
  8. common_vendor.index.request({
  9. url: config_config.config.url_addr.Dynamic + api,
  10. data: post_data,
  11. method: isPost ? "POST" : "GET",
  12. header: {
  13. "token": stores_userDataManager.UserData().getUserToken()
  14. //自定义请求头信息
  15. },
  16. success: (res) => {
  17. if (call_back != null) {
  18. call_back(null, res);
  19. }
  20. },
  21. fail(res) {
  22. if (call_back != null) {
  23. call_back(res, null);
  24. }
  25. }
  26. });
  27. }
  28. //静态请求
  29. static StaticRequest(api, call_back) {
  30. common_vendor.index.request({
  31. dataType: "json",
  32. responseType: "json",
  33. url: api,
  34. method: "GET",
  35. success: (res) => {
  36. if (call_back != null) {
  37. call_back(null, res.data);
  38. }
  39. },
  40. fail(res) {
  41. if (call_back != null) {
  42. call_back(res, null);
  43. }
  44. }
  45. });
  46. }
  47. static getStaticText(api, call_back) {
  48. common_vendor.index.request({
  49. dataType: "text",
  50. responseType: "text",
  51. url: api,
  52. method: "GET",
  53. success: (res) => {
  54. if (call_back != null) {
  55. call_back(null, res.data);
  56. }
  57. },
  58. fail(res) {
  59. if (call_back != null) {
  60. call_back(res, null);
  61. }
  62. }
  63. });
  64. }
  65. }
  66. exports.http = http;