xlcs/xlcs-user/common/http.interceptor.js

40 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const install = (Vue, vm) => {
Vue.prototype.$u.http.setConfig({
baseUrl: 'http://192.168.31.67:8200/api',
// baseUrl: 'http://127.0.0.1:8206/api',
// baseUrl: 'http://152.136.42.114:8200/api',
loadingText: '请求中...', // 请求loading中的文字提示
loadingTime: 800, // 在此时间内请求还没回来的话就显示加载中动画单位ms
loadingMask: true, // 展示loading的时候是否给一个透明的蒙层防止触摸穿透
});
// 请求拦截配置Token等参数
Vue.prototype.$u.http.interceptor.request = (config) => {
config.header.token = uni.getStorageSync('token')
return config;
}
// 响应拦截,判断状态码是否通过
Vue.prototype.$u.http.interceptor.response = (res) => {
if (res.code == 200) {
return res.data;
} else if (res.code == 208) {
// 未登陆token过期
uni.reLaunch({
url: '/pages/loginh5/loginh5'
})
return false;
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
return false;
}
}
}
export default {
install
}