|
|
|
|
@ -26,7 +26,7 @@ const install = (Vue, vm) => {
|
|
|
|
|
// 引用token
|
|
|
|
|
// 方式一,存放在vuex的token,假设使用了uView封装的vuex方式
|
|
|
|
|
// 见:https://uviewui.com/components/globalVariable.html
|
|
|
|
|
if(vm.vuex_token){
|
|
|
|
|
if (vm.vuex_token) {
|
|
|
|
|
config.header['Authorization'] = `Bearer ${vm.vuex_token}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -39,21 +39,30 @@ const install = (Vue, vm) => {
|
|
|
|
|
// 响应拦截,如配置,每次请求结束都会执行本方法
|
|
|
|
|
Vue.prototype.$u.http.interceptor.response = (res) => {
|
|
|
|
|
console.log('res-http', res)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res.statusCode === 200) {
|
|
|
|
|
if (res.data.errcode === 40001) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "none",
|
|
|
|
|
title: "登陆过期,请重新登录"
|
|
|
|
|
})
|
|
|
|
|
if (res.data.hasOwnProperty("errcode")) {
|
|
|
|
|
if (res.data.errcode === 40001) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "none",
|
|
|
|
|
title: "登陆过期,请重新登录"
|
|
|
|
|
})
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.redirectTo({
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
})
|
|
|
|
|
}, 1500)
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.redirectTo({
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "none",
|
|
|
|
|
title: res.data.errmsg
|
|
|
|
|
})
|
|
|
|
|
}, 1500)
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
return res.data;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return res.data;
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
|