爱简收旧衣按件回收前端代码仓库
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.

58 lines
1.8 KiB

  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const utils_utils = require("../utils/utils.js");
  4. const config = require("../config.js");
  5. function http(uri, data, callback, method = "GET", showLoading, title) {
  6. if (showLoading) {
  7. common_vendor.index.showLoading({
  8. title: title || "加载中..."
  9. });
  10. }
  11. return new Promise((resolve, reject) => {
  12. common_vendor.index.request({
  13. url: config.ossConfig.baseUrl + uri,
  14. // 使用 config.baseUrl
  15. data,
  16. method,
  17. header: {
  18. "X-Access-Token": common_vendor.index.getStorageSync("token"),
  19. "Content-Type": "application/x-www-form-urlencoded"
  20. },
  21. success: (res) => {
  22. if (showLoading) {
  23. common_vendor.index.hideLoading();
  24. }
  25. if (res.statusCode == 401 || res.data.message == "操作失败,token非法无效!" || res.data.message == "操作失败,用户不存在!") {
  26. common_vendor.index.__f__("error", "at api/http.js:30", "登录过期");
  27. utils_utils.util.toLogin();
  28. }
  29. if (res.statusCode == 200 && res.data.code != 200 && res.data.code != 902) {
  30. common_vendor.index.showToast({
  31. mask: true,
  32. duration: 1e3,
  33. title: res.data.message,
  34. icon: "none"
  35. });
  36. }
  37. callback && callback(res.data);
  38. resolve(res.data);
  39. },
  40. fail: () => {
  41. reject("api fail");
  42. common_vendor.index.showLoading({});
  43. setTimeout(() => {
  44. common_vendor.index.hideLoading();
  45. common_vendor.index.showToast({ icon: "none", title: "网络异常" });
  46. }, 3e3);
  47. if (showLoading) {
  48. common_vendor.index.hideLoading();
  49. }
  50. }
  51. });
  52. });
  53. }
  54. const http$1 = {
  55. http
  56. };
  57. exports.http = http$1;
  58. //# sourceMappingURL=../../.sourcemap/mp-weixin/api/http.js.map