Files
foton-laws-system-front/src/common/axiosV2/index.js
T
2021-08-03 15:07:08 +08:00

64 lines
1.5 KiB
JavaScript

import axios from 'axios'
import router from '@/router'
import store from '@/store'
import {Message} from 'element-ui'
import { baseUrl } from '@/sysConfig'
// 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: process.env.NODE_ENV === 'production' ? 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