api.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // const BASE_URL = 'https://iot.usky.cn/USKYOF/USKYOF.php/Home/' //(测试域名)
  2. const BASE_URL = 'https://wx.ewoogi.com/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. function 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. } else {
  35. return uni.showToast({
  36. title: res.data.msg ? res.data.msg : "获取数据失败",
  37. icon: "none"
  38. })
  39. }
  40. // end
  41. // return uni.showToast({
  42. // title: res.data.msg ? res.data.msg : "获取数据失败",
  43. // icon: "none"
  44. // })
  45. }
  46. resolve(res)
  47. }
  48. },
  49. fail: (err) => {
  50. // 修复首页请求接口失败bug start
  51. let notIndexFail = ['Index/getDataStatistics', 'Com/getAuthorizationUrl'];
  52. if (notIndexFail.includes(options.url)) {
  53. window.location.href =
  54. 'https://wx.ewoogi.com/wx/index.html#/pages/index/index';
  55. } else {
  56. uni.showModal({
  57. showCancel: false,
  58. content: '请求接口失败'
  59. });
  60. }
  61. // end
  62. reject(err)
  63. },
  64. // 完成之后关闭加载效果
  65. complete: () => {
  66. if (showLoading) {
  67. ajaxTimes--;
  68. if (ajaxTimes === 0) {
  69. // 关闭正在等待的图标
  70. uni.hideLoading();
  71. }
  72. }
  73. }
  74. })
  75. })
  76. }
  77. export default {
  78. BASE_URL,myRequest,websiteUrl
  79. }