|
|
@ -1,8 +1,10 @@ |
|
|
|
import axios from 'axios'; |
|
|
|
import axios from 'axios'; |
|
|
|
import QS from 'qs'; |
|
|
|
import QS from 'qs'; |
|
|
|
import store from '../store/index' |
|
|
|
import store from '../store/index' |
|
|
|
|
|
|
|
import api from './api' |
|
|
|
import { Message } from 'element-ui' |
|
|
|
import { Message } from 'element-ui' |
|
|
|
import router from '../router/index' |
|
|
|
import router from '../router/index' |
|
|
|
|
|
|
|
import core from './core' |
|
|
|
|
|
|
|
|
|
|
|
// 环境的切换
|
|
|
|
// 环境的切换
|
|
|
|
// if (process.env.NODE_ENV == 'development') {
|
|
|
|
// 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请求 |
|
|
|
* get方法,对应get请求 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export function get(url, params){ |
|
|
|
export function get(url, params){ |
|
|
|
|
|
|
|
getToken() |
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
axios.get(url, { |
|
|
|
axios.get(url, { |
|
|
|
params: params |
|
|
|
params: params |
|
|
@ -184,6 +205,7 @@ export function get(url, params){ |
|
|
|
* post方法,对应post请求 |
|
|
|
* post方法,对应post请求 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export function post(url, params) { |
|
|
|
export function post(url, params) { |
|
|
|
|
|
|
|
getToken() |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
axios.post(url,params) |
|
|
|
axios.post(url,params) |
|
|
|
.then(res => { |
|
|
|
.then(res => { |
|
|
@ -256,6 +278,7 @@ export function post(url, params) { |
|
|
|
* delete方法,对应delete请求 |
|
|
|
* delete方法,对应delete请求 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export function del(url, params){ |
|
|
|
export function del(url, params){ |
|
|
|
|
|
|
|
getToken() |
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
axios.delete(url, { |
|
|
|
axios.delete(url, { |
|
|
|
params: params |
|
|
|
params: params |
|
|
@ -330,6 +353,7 @@ export function post(url, params) { |
|
|
|
* @param {*} params
|
|
|
|
* @param {*} params
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export function put(url, params){ |
|
|
|
export function put(url, params){ |
|
|
|
|
|
|
|
getToken() |
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
return new Promise((resolve, reject) =>{ |
|
|
|
axios.put(url, params) |
|
|
|
axios.put(url, params) |
|
|
|
.then(res => { |
|
|
|
.then(res => { |
|
|
|