| | |
| | | import { getStorage, clearStorage } from './storage' |
| | | // 导入封装的增强 API |
| | | import { toast, modal } from './extendApi' |
| | | import { debounce } from 'miniprogram-licia'; |
| | | //#region ====================== 后端 res.err_code ====================== |
| | | export const ErrorCode = { |
| | | /** @description 权限验证失败 */ |
| | |
| | | if (!session) { |
| | | // 既然用户需要重新进行登录,就需要把之前用户存储的信息(过期的 token) 进行清除 |
| | | clearStorage() |
| | | wx.redirectTo({ |
| | | wx.reLaunch({ |
| | | url: '/pages/login/login' |
| | | }) |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | const debounceCheckAuth = debounce(checkAuth); |
| | | const debounceCheckAuth = wx.$_.debounce(checkAuth); |
| | | // 对类进行实例化 |
| | | const instance = new WxRequest({ |
| | | baseURL: 'https://wi.cpolar.top', |
| | |
| | | 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: |