wujingjing
2024-08-12 42794ac8486759c805e5d465ba4588cc31cdcb83
miniprogram/utils/http.ts
@@ -4,7 +4,6 @@
import { getStorage, clearStorage } from './storage'
// 导入封装的增强 API
import { toast, modal } from './extendApi'
import { debounce } from 'miniprogram-licia';
//#region ====================== 后端 res.err_code ======================
export const ErrorCode = {
  /** @description 权限验证失败 */
@@ -21,7 +20,7 @@
  if (!session) {
    // 既然用户需要重新进行登录,就需要把之前用户存储的信息(过期的 token) 进行清除
    clearStorage()
    wx.redirectTo({
    wx.reLaunch({
      url: '/pages/login/login'
    })
  }
@@ -29,7 +28,7 @@
}
const debounceCheckAuth = debounce(checkAuth);
const debounceCheckAuth = wx.$_.debounce(checkAuth);
// 对类进行实例化
const instance = new WxRequest({
  baseURL: 'https://wi.cpolar.top',
@@ -96,15 +95,10 @@
    switch (data?.err_code) {
      case ErrorCode.Auth:
        const res = await modal({
          content: '鉴权失败,请重新登录',
          showCancel: false
        clearStorage()
        wx.redirectTo({
          url: '/pages/login/login'
        })
        if (res) {
          debounceCheckAuth();
        }
        return Promise.reject(response)
      case ErrorCode.Exception: