|  |  |  | 
|---|
|  |  |  | 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({ | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 新建响应拦截器 | 
|---|
|  |  |  | axiosInstance.interceptors.response.use((response) => { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 请求失败 | 
|---|
|  |  |  | if (response.status !== 200) { | 
|---|
|  |  |  | return Promise.reject(new Error('服务器繁忙,请稍后再试')) | 
|---|
|  |  |  | 
|---|
|  |  |  | if (response.data.code === 503) { | 
|---|
|  |  |  | return Promise.reject(new Error('服务器繁忙,请稍后再试')) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (response.data.code === 401) { | 
|---|
|  |  |  | if (response.config.autoLogin !== false) { | 
|---|
|  |  |  | if (response.data.code === 401 || response.data.code === 5112) { | 
|---|
|  |  |  | // if (response.config.autoLogin !== false) { | 
|---|
|  |  |  | Cookies.set('dm_user_token','') | 
|---|
|  |  |  | window.location.href = process.env.VUE_APP_ROUTER_MODE === 'hash' ? (process.env.VUE_APP_CONTEXT_PATH +'/#/login') : (process.env.VUE_APP_CONTEXT_PATH+'/login') | 
|---|
|  |  |  | } | 
|---|
|  |  |  | router.replace({name: 'login'}) | 
|---|
|  |  |  | // } | 
|---|
|  |  |  | return Promise.reject(response.data) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 业务失败 | 
|---|