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.

88 lines
1.7 KiB

2 weeks ago
import Vue from "vue";
import App from "./App";
//配置公共方法
//配置公共方法
// 导入网络请求的包
import { $http } from '@escook/request-miniprogram';
uni.$http = $http;
// 请求的根路径
// $http.baseUrl = 'http://tpapp.runpengsoft.com';
$http.baseUrl = 'https://pallet.dsic.cn/api';
//$http.baseUrl = 'https://pallet.dsic.cn/api'
// $http.baseUrl = 'http://localhost:18080';
// 请求开始之前做一些事情
$http.beforeRequest = function (options) {
// 判断是否需要登录
// 暂时隐藏加载
// uni.showLoading({
// title: '数据加载中...'
// });
var token= uni.getStorageSync("token");
// 判断请求是否为有权限的 API 接口
if(token) {
// 为请求头添加身份认证字段
options.header = {
token: token
}
}
};
// 请求完成之后做一些事情
$http.afterRequest = function (response) {
uni.hideLoading();
// 拦截未登录,跳转到登录
if (response.data.status == 10105) {
uni.setStorageSync('token', "");
uni.showToast({
title: '登录已失效!请您重新登录!',
duration: 2000,
icon: "none"
});
setTimeout(function() {
uni.redirectTo({
url: '/pages/login/index'
});
}, 2000);
}
//
else if (response.data.status == 10106) {
uni.setStorageSync('token', "");
uni.showToast({
title: '登录已失效!请您重新登录!',
duration: 2000,
icon: "none"
});
setTimeout(function() {
uni.redirectTo({
url: '/pages/login/index'
});
}, 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();