| | |
| | | import pkg from '../../package' |
| | | import { trim } from './util' |
| | | import cache from '../plugins/cache' |
| | | import { Message } from 'element-ui' |
| | | |
| | | axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8' |
| | | const axiosInstance = axios.create({ |
| | |
| | | |
| | | // 新建请求拦截器 |
| | | axiosInstance.interceptors.request.use(config => { |
| | | // debugger |
| | | // 参数去空格 |
| | | if (config.trim === true) { |
| | | if (config.data != null) { |
| | |
| | | config.headers['eva-platform'] = `pc-${pkg.version}` |
| | | // 设置认证头 |
| | | const authToken = Cookies.get('eva-auth-token') |
| | | |
| | | if (authToken != null) { |
| | | config.headers['eva-auth-token'] = authToken |
| | | } |
| | | // debugger |
| | | return config |
| | | }, function (error) { |
| | | return Promise.reject(error) |
| | |
| | | |
| | | // 新建响应拦截器 |
| | | axiosInstance.interceptors.response.use((response) => { |
| | | |
| | | // console.log(response.status) |
| | | // debugger |
| | | // 请求失败 |
| | | if (response.status !== 200) { |
| | |
| | | } |
| | | // 未登录 |
| | | if (response.data.code === 401) { |
| | | // window.location.href = '/#/' |
| | | // debugger |
| | | if (response.config.autoLogin !== false) { |
| | | // window.location.href = process.env.VUE_APP_ROUTER_MODE === 'history' ? '/#/login' : '/login' |
| | | window.location.href = process.env.VUE_APP_CONTEXT_PATH |
| | | // window.location.href = '/hfznzzzd_web' |
| | | location.reload() |
| | | // window.location.href = process.env.VUE_APP_ROUTER_MODE === 'history' ? '/login' : '/#/login' |
| | | } |
| | | return Promise.reject(response.data) |
| | | } |