You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
1.8 KiB

import Vue from "vue";
import App from "./App";
//配置公共方法
//配置公共方法
// 导入网络请求的包
import { $http } from '@escook/request-miniprogram';
uni.$http = $http;
// 请求的根路径
// #ifdef H5
$http.baseUrl = 'https://www.sanduolantoyoga.com/yoga'
// #endif
//#ifdef APP-PLUS
$http.baseUrl = 'https://www.sanduolantoyoga.com/yoga'
//#endif
// 请求开始之前做一些事情
$http.beforeRequest = function (options) {
// 判断是否需要登录
// 暂时隐藏加载
// uni.showLoading({
// title: '数据加载中...'
// });
var iftoken = uni.getStorageSync("iftoken");
if(iftoken){
// 去掉身份认证
options.header = {
isToken: false
}
uni.setStorageSync('iftoken', "");
}
else{
var token = uni.getStorageSync("token");
// 判断请求是否为有权限的 API 接口
if(token) {
// 为请求头添加身份认证
options.header = {
Authorization: token
}
}
uni.setStorageSync('iftoken', "");
}
};
// 请求完成之后做一些事情
$http.afterRequest = function (response) {
uni.hideLoading();
// 拦截未登录,跳转到登录
if (response.data.status == 10105) {
uni.showToast({
title: '登录已失效!请您重新登录!',
duration: 2000,
icon: "none"
});
setTimeout(function() {
uni.redirectTo({
url: '/pages/login/login'
});
}, 2000);
}
//
else if (response.data.status == 10106) {
uni.showToast({
title: '登录已失效!请您重新登录!',
duration: 2000,
icon: "none"
});
setTimeout(function() {
uni.redirectTo({
url: '/pages/login/login'
});
}, 2000);
}
else {
return
}
}
Vue.config.productionTip = false;
App.mpType = "app";
// 引入全局uView
import uView from "uview-ui";
Vue.use(uView);
const app = new Vue({
...App
})
app.$mount();