|
|
|
@ -1,8 +1,10 @@ |
|
|
|
|
import axios from 'axios'; |
|
|
|
|
import QS from 'qs'; |
|
|
|
|
import store from '../store/index' |
|
|
|
|
import api from './api' |
|
|
|
|
import { Message } from 'element-ui' |
|
|
|
|
import router from '../router/index' |
|
|
|
|
import core from './core' |
|
|
|
|
|
|
|
|
|
// 环境的切换
|
|
|
|
|
// if (process.env.NODE_ENV == 'development') {
|
|
|
|
@ -99,10 +101,29 @@ axios.interceptors.request.use(config => { |
|
|
|
|
// }
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
let logout = false |
|
|
|
|
export function getToken(){ |
|
|
|
|
// console.log(store.state.dataTime)
|
|
|
|
|
if(process.env.NODE_ENV == 'production'){ |
|
|
|
|
if(store.state.dataTime && !logout){ |
|
|
|
|
axios.get(`${api.queryToken}?token=${store.state.token}`).then(res => { |
|
|
|
|
if(store.state.dataTime && (res.data.message != store.state.dataTime)){ |
|
|
|
|
logout || Message.error('您已在另一台设备登录,本次登录已下线!') |
|
|
|
|
logout = true |
|
|
|
|
setTimeout(() => { |
|
|
|
|
core.logout() |
|
|
|
|
},1500) |
|
|
|
|
} |
|
|
|
|
}).catch(err => {}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* get方法,对应get请求 |
|
|
|
|
*/ |
|
|
|
|
export function get(url, params){ |
|
|
|
|
getToken() |
|
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
|
axios.get(url, { |
|
|
|
|
params: params |
|
|
|
@ -184,6 +205,7 @@ export function get(url, params){ |
|
|
|
|
* post方法,对应post请求 |
|
|
|
|
*/ |
|
|
|
|
export function post(url, params) { |
|
|
|
|
getToken() |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
axios.post(url,params) |
|
|
|
|
.then(res => { |
|
|
|
@ -256,6 +278,7 @@ export function post(url, params) { |
|
|
|
|
* delete方法,对应delete请求 |
|
|
|
|
*/ |
|
|
|
|
export function del(url, params){ |
|
|
|
|
getToken() |
|
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
|
axios.delete(url, { |
|
|
|
|
params: params |
|
|
|
@ -330,6 +353,7 @@ export function post(url, params) { |
|
|
|
|
* @param {*} params
|
|
|
|
|
*/ |
|
|
|
|
export function put(url, params){ |
|
|
|
|
getToken() |
|
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
|
axios.put(url, params) |
|
|
|
|
.then(res => { |
|
|
|
|