code init
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import axios from 'axios'
|
||||
import router from '@/router'
|
||||
import store from '@/store'
|
||||
import {Message} from 'element-ui'
|
||||
// import 'element-ui/lib/theme-chalk/index.css'
|
||||
|
||||
/**
|
||||
* @description: FormData
|
||||
* @author: xx
|
||||
* @date: 2018-08-14 16:57:48
|
||||
*/
|
||||
let formData = (data) => {
|
||||
let _formData = new FormData()
|
||||
for (let i in data) {
|
||||
_formData.append(i, data[i])
|
||||
}
|
||||
return _formData
|
||||
}
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: '/'
|
||||
})
|
||||
|
||||
service.defaults.timeout = 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
|
||||
service.defaults.headers['Content-type'] = 'application/json'
|
||||
/**
|
||||
* @description: axios请求拦截器
|
||||
* liuyan
|
||||
*/
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
if (config.params) {
|
||||
// 解决IE请求不刷新
|
||||
config.params._t = new Date().getTime()
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error.response)
|
||||
})
|
||||
/**
|
||||
* @description: axios响应拦截器
|
||||
* liuyan
|
||||
*/
|
||||
service.interceptors.response.use(
|
||||
res => {
|
||||
return res.data
|
||||
},
|
||||
error => {
|
||||
// 登录超时
|
||||
if (error.response.data.path === '/a/login' && store.state.isTimeOut === false) {
|
||||
for (let key in store.state) {
|
||||
if (key !== 'isTimeOut' && key !== 'laws_urm' && key !== 'laws_prm') {
|
||||
store.state[key] = ''
|
||||
}
|
||||
}
|
||||
Message.warning('登录超时,请重新登录')
|
||||
router.push('/login')
|
||||
store.state.isTimeOut = true
|
||||
}
|
||||
})
|
||||
export default service
|
||||
Reference in New Issue
Block a user