|
|
@@ -1,5 +1,6 @@
|
|
|
import axios from 'axios';
|
|
|
-
|
|
|
+import {Message,Loading,MessageBox} from "element-ui";
|
|
|
+import router from "../routes";
|
|
|
let http = axios.create({
|
|
|
//baseURL: 'http://www.yytp.com/',
|
|
|
//withCredentials: true,
|
|
|
@@ -17,6 +18,41 @@ let http = axios.create({
|
|
|
}]
|
|
|
});
|
|
|
|
|
|
+http.interceptors.request.use(
|
|
|
+ config => {
|
|
|
+ let authKey = sessionStorage.getItem('authKey');//token
|
|
|
+ if(authKey){
|
|
|
+ config.headers.authKey = JSON.parse(authKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ return config;
|
|
|
+ },
|
|
|
+ error => {
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+http.interceptors.response.use(response => {
|
|
|
+ let data = response.data;
|
|
|
+ if(data.code == "103"){
|
|
|
+ var loginParams = { is_reg: 0 }; //登录状态为未登录
|
|
|
+ http.post('/api/index/base/logout',loginParams).then((response) => {
|
|
|
+
|
|
|
+ })
|
|
|
+ MessageBox.alert(data.error,"登录超时",{
|
|
|
+ confirmButtonText:"跳转登录页面",
|
|
|
+ callback:action=>{
|
|
|
+
|
|
|
+ location.href = "/#/login";
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+});
|
|
|
function apiAxios(method, url, params, response) {
|
|
|
http({
|
|
|
method: method,
|