import { $http } from '@escook/request-miniprogram' $http.baseUrl = "http://192.168.0.40:8081" uni.$http = $http import { getToken, removeAll } from "./auth.js" // const baseUrl = window.location.origin // $http.baseUrl = baseUrl // 请求拦截器 $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) { } }