api.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // const BASE_URL = 'https://iot.usky.cn/USKYOF/USKYOF.php/Home/' //(测试域名)
  2. const BASE_URL = 'https://wx.ewoogi.com/wx/USKYOF/USKYOF.php/Home/' //(正式域名新)
  3. // const websiteUrl = 'https://wx.ewoogi.com'
  4. // const BASE_URL='http://https://qhome.usky.cn/USKYOF/USKYOF.php/Home/'
  5. // 同时发送异步代码的次数,防止一次点击中有多次请求,用于处理
  6. let ajaxTimes = 0;
  7. export const myRequest = (options) => {
  8. let showLoading = options.showLoading || false;
  9. // 显示加载中 效果
  10. if (showLoading) {
  11. ajaxTimes++;
  12. uni.showLoading({
  13. title: "加载中",
  14. mask: true,
  15. });
  16. }
  17. return new Promise((resolve, reject) => {
  18. uni.request({
  19. url: BASE_URL + options.url,
  20. method: options.method || 'POST',
  21. data: options.data || {},
  22. header: {
  23. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  24. },
  25. success: (res) => {
  26. let notShowToastUrl = ['Login/getLoginAuthorize'];
  27. if (!notShowToastUrl.includes(options.url)) {
  28. if (res.data.flag == false) {
  29. // 修复首页操作失败bug start
  30. let notIndexFail2 = ['Index/getDataStatistics'];
  31. let ua = navigator.userAgent.toLowerCase();
  32. if (notIndexFail2.includes(options.url) && ua.match(
  33. /MicroMessenger/i) == "micromessenger") {
  34. // alert('数据拉取失败,请重新进入公众号')
  35. // window.location.href = 'https://wx.ewoogi.com/wx/index.html#/pages/index/index';
  36. } else {
  37. return uni.showToast({
  38. title: res.data.msg ? res.data.msg : "获取数据失败",
  39. icon: "none"
  40. })
  41. }
  42. // end
  43. // return uni.showToast({
  44. // title: res.data.msg ? res.data.msg : "获取数据失败",
  45. // icon: "none"
  46. // })
  47. }
  48. resolve(res)
  49. }
  50. },
  51. fail: (err) => {
  52. // 修复首页请求接口失败bug start
  53. let notIndexFail = ['Index/getDataStatistics', 'Com/getAuthorizationUrl'];
  54. if (notIndexFail.includes(options.url)) {
  55. window.location.href =
  56. '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. // websiteUrl,
  81. }