| | |
| | | import { trim } from './util' |
| | | import cache from '../plugins/cache' |
| | | import { Message } from 'element-ui' |
| | | import router from '@/router' |
| | | |
| | | axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8' |
| | | const axiosInstance = axios.create({ |
| | | baseURL: process.env.VUE_APP_API_PREFIX, |
| | | // 请求超时时间 |
| | | timeout: 60000 |
| | | timeout: 600000 |
| | | }) |
| | | |
| | | // 新建请求拦截器 |
| | |
| | | // 设置操作平台 |
| | | config.headers['eva-platform'] = `pc-${pkg.version}` |
| | | // 设置认证头 |
| | | const authToken = Cookies.get('eva-auth-token') |
| | | const authToken = Cookies.get('dm_user_token') |
| | | if (authToken != null) { |
| | | config.headers['eva-auth-token'] = authToken |
| | | config.headers['dm_user_token'] = authToken |
| | | } |
| | | return config |
| | | }, function (error) { |
| | |
| | | |
| | | // 新建响应拦截器 |
| | | axiosInstance.interceptors.response.use((response) => { |
| | | |
| | | // 请求失败 |
| | | if (response.status !== 200) { |
| | | return Promise.reject(new Error('服务器繁忙,请稍后再试')) |
| | |
| | | return Promise.resolve(response) |
| | | } |
| | | // 未登录 |
| | | if (response.data.code === 401) { |
| | | if (response.config.autoLogin !== false) { |
| | | window.location.href = process.env.VUE_APP_ROUTER_MODE === 'history' ? '/#/login' : '/login' |
| | | } |
| | | if (response.data.code === 503) { |
| | | return Promise.reject(new Error('服务器繁忙,请稍后再试')) |
| | | } |
| | | if (response.data.code === 401 || response.data.code === 5112) { |
| | | // if (response.config.autoLogin !== false) { |
| | | Cookies.set('dm_user_token','') |
| | | router.replace({name: 'login'}) |
| | | // } |
| | | return Promise.reject(response.data) |
| | | } |
| | | // 业务失败 |