|
|
|
@ -112,15 +112,55 @@ instance.interceptors.response.use(response => { |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// ============================= 下载功能的请求 =============================
|
|
|
|
const instance2 = axios.create({ |
|
|
|
baseURL: (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi/' : window.SITE_CONFIG.baseUrl), |
|
|
|
timeout: 10000 * 30, |
|
|
|
withCredentials: true, |
|
|
|
responseType: 'blob', |
|
|
|
headers: { |
|
|
|
'Content-Type': 'application/json; charset=utf-8' |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
/** |
|
|
|
* 请求拦截 |
|
|
|
*/ |
|
|
|
instance2.interceptors.request.use(config => { |
|
|
|
config.headers['token'] = Vue.cookie.get('token') // 请求头带上token
|
|
|
|
return config |
|
|
|
}, error => { |
|
|
|
return Promise.reject(error) |
|
|
|
}) |
|
|
|
|
|
|
|
/** |
|
|
|
* 响应拦截 |
|
|
|
*/ |
|
|
|
instance2.interceptors.response.use(response => { |
|
|
|
if (response.data && response.data.code === 401) { // 401, token失效
|
|
|
|
clearLoginInfo() |
|
|
|
router.push({name: 'login'}) |
|
|
|
} |
|
|
|
return response |
|
|
|
}, error => { |
|
|
|
return Promise.reject(error) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
export const createAPI = (url, method, data) => { |
|
|
|
export const createAPI = (url, method, data, type) => { |
|
|
|
let config = {} |
|
|
|
if (method === 'get') { |
|
|
|
config.params = data |
|
|
|
} else { |
|
|
|
config.data = data |
|
|
|
} |
|
|
|
if (data === 777 || type === 'download'){ // 下载功能的请求
|
|
|
|
return instance2({ |
|
|
|
url, |
|
|
|
method, |
|
|
|
...config |
|
|
|
}) |
|
|
|
} |
|
|
|
return instance({ |
|
|
|
url, |
|
|
|
method, |
|
|
|
|