1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- const install = (Vue, vm) => {
- Vue.prototype.$u.http.setConfig({
- baseUrl: 'http://192.168.0.119:6060/member',
- // baseUrl: 'http://test-member.uxianxin.com:8888/api/member',// 测试
- dataType: 'json',
- loadingText: '请求中...', // 请求loading中的文字提示
- loadingTime: 100, // 在此时间内,请求还没回来的话,就显示加载中动画,单位ms
- originalData: false, // 是否在拦截器中返回服务端的原始数据
- loadingMask: true, // 展示loading的时候,是否给一个透明的蒙层,防止触摸穿透
- });
-
- //是否是H5公众号--是否显示头部导航
-
- // #ifdef H5
- Vue.prototype.$isH5 = true;
- // #endif
- // #ifdef APP-PLUS
- Vue.prototype.$isH5 = false;
- // #endif
- //系统图片域名前缀
- Vue.prototype.$fileHost = 'http://fresh-life.oss-cn-shanghai.aliyuncs.com/'
- // 请求拦截,配置Token等参数
- Vue.prototype.$u.http.interceptor.request = (config) => {
- const token = uni.getStorageSync('token');
- config.header.token = token;
- Vue.prototype.$u.http.setConfig({
- showLoading: config.header.showLoading || false, // 是否显示请求中的loading
- });
- return config;
- }
- // 响应拦截,判断状态码是否通过
- Vue.prototype.$u.http.interceptor.response = (res) => {
- // console.log(JSON.stringify("------------"))
- // console.log(JSON.stringify(res))
- // console.log(res)
- if(res.code == 200) {
- // console.log("11111")
- return res;
- }else if(res.code == 401){
- // console.log("22222")
- uni.showToast({
- title:"登录过期,请重新登录",
- duration:1500, mask:false, icon:'none'
- });
- //此时应重新登录
- // console.log("goto--login")
- uni.navigateTo({
- url: '/pages/login/login'
- })
-
- return res;
- } else {
- // console.log("33333")
- uni.showToast({
- title: res.msg == null ? "出错了" : res.msg,
- duration:1500, mask:false, icon:'none'
- });
- return res;
- }
- }
- }
- export default {
- install
- }
|