api.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /** qhome.usky.cn测试域名 wx.ewoogi.com 正式域名 **/
  2. var BASE_URL = "";
  3. if (window.location.host.indexOf("localhost") == -1) {
  4. BASE_URL = "https://wx.ewoogi.com/USKYOF/USKYOF.php/Home/";
  5. } else {
  6. BASE_URL = "https://qhome.usky.cn/USKYOF/USKYOF.php/Home/";
  7. }
  8. const websiteUrl = "https://wx.ewoogi.com";
  9. // 同时发送异步代码的次数,防止一次点击中有多次请求,用于处理
  10. let ajaxTimes = 0;
  11. function myRequest(options) {
  12. let showLoading = options.showLoading || false;
  13. // 显示加载中 效果
  14. if (showLoading) {
  15. ajaxTimes++;
  16. uni.showLoading({
  17. title: "加载中",
  18. mask: true,
  19. });
  20. }
  21. return new Promise((resolve, reject) => {
  22. uni.request({
  23. url: BASE_URL + options.url,
  24. method: options.method || "POST",
  25. data: options.data || {},
  26. header: {
  27. "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
  28. },
  29. success: (res) => {
  30. let notShowToastUrl = ["Login/getLoginAuthorize"];
  31. if (!notShowToastUrl.includes(options.url)) {
  32. if (res.data.flag == false) {
  33. // 修复首页操作失败bug start
  34. let notIndexFail2 = ["Index/getDataStatistics"];
  35. let ua = navigator.userAgent.toLowerCase();
  36. if (notIndexFail2.includes(options.url) && ua.match(/MicroMessenger/i) == "micromessenger") {
  37. } else {
  38. return uni.showToast({
  39. title: res.data.msg ? res.data.msg : "获取数据失败",
  40. icon: "none",
  41. });
  42. }
  43. // end
  44. // return uni.showToast({
  45. // title: res.data.msg ? res.data.msg : "获取数据失败",
  46. // icon: "none"
  47. // })
  48. }
  49. resolve(res);
  50. }
  51. },
  52. fail: (err) => {
  53. // 修复首页请求接口失败bug start
  54. let notIndexFail = ["Index/getDataStatistics", "Com/getAuthorizationUrl"];
  55. if (notIndexFail.includes(options.url)) {
  56. window.location.href = "https://wx.ewoogi.com/wx/index.html#/pages/index/index";
  57. } else {
  58. uni.showModal({
  59. showCancel: false,
  60. content: "请求接口失败",
  61. });
  62. }
  63. // end
  64. reject(err);
  65. },
  66. // 完成之后关闭加载效果
  67. complete: () => {
  68. if (showLoading) {
  69. ajaxTimes--;
  70. if (ajaxTimes === 0) {
  71. // 关闭正在等待的图标
  72. uni.hideLoading();
  73. }
  74. }
  75. },
  76. });
  77. });
  78. }
  79. export default {
  80. BASE_URL,
  81. myRequest,
  82. websiteUrl,
  83. };