|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
import axios from 'axios'; |
|
|
|
|
import QS from 'qs'; |
|
|
|
|
// import store from '../store/index'
|
|
|
|
|
import store from '../store/index' |
|
|
|
|
import { Message } from 'element-ui' |
|
|
|
|
import router from '../router/index' |
|
|
|
|
|
|
|
|
@ -20,21 +20,21 @@ axios.defaults.timeout = 30000; |
|
|
|
|
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; |
|
|
|
|
|
|
|
|
|
// 请求拦截器
|
|
|
|
|
// axios.interceptors.request.use(config => {
|
|
|
|
|
// if (sessionStorage.getItem('token')) {
|
|
|
|
|
// // 存在将token写入 request header
|
|
|
|
|
// config.headers.Authorization = `${sessionStorage.getItem('token')}`;
|
|
|
|
|
// }
|
|
|
|
|
// return config;
|
|
|
|
|
// }, err => {
|
|
|
|
|
// Message.error({
|
|
|
|
|
// message: '退出登陆',
|
|
|
|
|
// onClose: function () {
|
|
|
|
|
// router.push({name: 'login'});
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// return Promise.reject(err);
|
|
|
|
|
// })
|
|
|
|
|
axios.interceptors.request.use(config => { |
|
|
|
|
let token = store.state.loginToken |
|
|
|
|
if(token){ |
|
|
|
|
config.headers.token = token |
|
|
|
|
} |
|
|
|
|
return config; |
|
|
|
|
}, err => { |
|
|
|
|
Message.error({ |
|
|
|
|
message: '退出登陆', |
|
|
|
|
onClose: function () { |
|
|
|
|
router.push({name: 'login'}); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
return Promise.reject(err); |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 响应拦截器
|
|
|
|
|
// axios.interceptors.response.use(
|
|
|
|
@ -99,6 +99,17 @@ axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; |
|
|
|
|
// }
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function logouts(){ |
|
|
|
|
store.replaceState({}) |
|
|
|
|
localStorage.removeItem('ms_username') |
|
|
|
|
location.reload() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let tokenStatus = { |
|
|
|
|
0: '用户未登录,请登录后操作!', |
|
|
|
|
1: 'token错误,请重新登录!' |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* get方法,对应get请求 |
|
|
|
|
*/ |
|
|
|
@ -108,6 +119,11 @@ export function get(url, params){ |
|
|
|
|
params: params |
|
|
|
|
}) |
|
|
|
|
.then(res => { |
|
|
|
|
if(typeof res.data == 'number'){ |
|
|
|
|
this.$message.error(tokenStatus[res.data])
|
|
|
|
|
setTimeout(logouts,1500) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
if (res.data.status) { |
|
|
|
|
switch (res.data.status) { |
|
|
|
|
case 200: |
|
|
|
|