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.

78 lines
2.8 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const config_site_config = require("./site.config.js");
  4. const store_index = require("../store/index.js");
  5. let { H5_API, WX_API, httpPrefix } = config_site_config.obj;
  6. const counterStore = store_index.useUserStoreHook();
  7. let secretKey = "22d90e09d1374f0f9e4accd07d333e55";
  8. const request = (vm) => {
  9. common_vendor.index.$u.http.setConfig((config) => {
  10. let prefix = config.prefix ? config.prefix : httpPrefix;
  11. config.baseURL = H5_API + WX_API + prefix;
  12. return config;
  13. });
  14. common_vendor.index.$u.http.interceptors.request.use((config) => {
  15. var _a;
  16. config.data = config.data || {};
  17. config.data["timestamp"] = Date.now();
  18. let jsonString = JSON.stringify(config.data);
  19. let strSecretKey = jsonString + secretKey;
  20. let hash = common_vendor.md5(strSecretKey);
  21. config.header["Signature"] = hash;
  22. config.data = jsonString;
  23. let token = common_vendor.index.getStorageSync("token");
  24. if (token) {
  25. config.header.Authorization = "Bearer " + token;
  26. }
  27. let noToken = (_a = config.custom) == null ? void 0 : _a.noToken;
  28. if (noToken && config.header.Authorization) {
  29. delete config.header.Authorization;
  30. }
  31. console.log("config");
  32. console.log(config);
  33. return config;
  34. }, (config) => {
  35. return Promise.reject(config);
  36. });
  37. common_vendor.index.$u.http.interceptors.response.use(async (response) => {
  38. var _a;
  39. const data = response.data;
  40. if (data.code == 406 && response.config.url != "member/auth/refresh-token" && response.config.url !== "member/auth/logout") {
  41. let obj = response.config;
  42. let method = obj.method.toLowerCase();
  43. if (method == "get") {
  44. return common_vendor.index.$u.http[method](obj.url, { params: obj.params });
  45. } else {
  46. return common_vendor.index.$u.http[method](obj.url, obj.data);
  47. }
  48. }
  49. if (data.code == 401) {
  50. console.log("报401的接口");
  51. let url = response.config.url;
  52. console.log(url);
  53. if (url == "mime/houses" || url == "face/user_info") {
  54. console.log("还是到这里面来了?");
  55. return Promise.reject(data);
  56. }
  57. return counterStore.goLogin();
  58. }
  59. const custom = (_a = response.config) == null ? void 0 : _a.custom;
  60. if (data.code !== 0 && data.code != 406 && data.code != "200240213") {
  61. console.log("不正常的code");
  62. console.log(data);
  63. if (custom.toast !== false) {
  64. common_vendor.index.$u.toast(data.msg);
  65. }
  66. if (custom == null ? void 0 : custom.catch) {
  67. return Promise.reject(data);
  68. } else {
  69. return new Promise(() => {
  70. });
  71. }
  72. }
  73. return data === void 0 ? {} : data;
  74. }, (response) => {
  75. return Promise.reject(response);
  76. });
  77. };
  78. exports.request = request;