liukangdong
2024-07-30 1a6905045d38bb50b0c6554c3440bdfd339c8d23
wechat_jiaxuan/utils/request.js
@@ -1,9 +1,10 @@
import { baseUrl } from "./config"
let number = 0
export function request(options){
  let loading = options.loading || '1' // 默认值1显示,否则不显示
  if(loading == '1'){
    wx.showLoading()
    number ++
  }
  return new Promise(resolve => {
    wx.request({
@@ -19,9 +20,9 @@
        if (res.data.code === 200) {
          resolve(res.data || true)
        } else {
          if(res.data.code && res.data.code == 5112){
            wx.navigateTo({
              url: '/pages/auth/auth',
          if(res.data.code == 5111 || res.data.code == 5112){
            wx.switchTab({
              url: '/pages/index/index',
            })
          }
          res.data.message && wx.showToast({
@@ -39,7 +40,10 @@
      },
      complete() {
        if(loading == '1'){
          wx.hideLoading()
          number --
          if(number == 0){
            wx.hideLoading()
          }
        }
      }
    })