1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import {
- $http
- } from '@escook/request-miniprogram'
- //$http.baseUrl = "http://localhost:8081"
- //$http.baseUrl = "http://192.168.0.12:8081"
- $http.baseUrl = "http://192.168.1.99:8089"
- uni.$http = $http
- import {
- getToken,
- removeAll
- } from "./auth.js"
- // 请求拦截器
- $http.beforeRequest = function(options) {
- if (getToken()) {
- options.header['Authorization'] = 'Bearer ' + getToken()
- options.header['token'] = getToken()
- }
- // uni.showLoading({
- // title: "数据加载中..."
- // })
- }
- // 响应拦截器
- $http.afterRequest = function(res) {
- try {
- const code = res.data.code
- const msg = res.data.msg
- if (code === 401 || code === 403) {
- uni.showLoading({
- title: msg
- })
- removeAll()
- uni.navigateTo({
- url: "/pages/login/index"
- })
- } else if (code !== 200) {
- uni.showToast({
- title: msg,
- duration: 2000,
- icon: "error"
- });
- uni.hideToast();
- } else {
- }
- uni.hideLoading()
- } catch (e) {
- }
- }
|