api.js 2.2 KB

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