🐛 修复 Excel 导出失败时,依然下载的问题
This commit is contained in:
parent
9591ed7084
commit
ccb997ac2a
@ -104,7 +104,7 @@ service.interceptors.request.use(
|
|||||||
// response 拦截器
|
// response 拦截器
|
||||||
service.interceptors.response.use(
|
service.interceptors.response.use(
|
||||||
async (response: AxiosResponse<any>) => {
|
async (response: AxiosResponse<any>) => {
|
||||||
const { data } = response
|
let { data } = response
|
||||||
const config = response.config
|
const config = response.config
|
||||||
if (!data) {
|
if (!data) {
|
||||||
// 返回“[HTTP]请求没有返回值”;
|
// 返回“[HTTP]请求没有返回值”;
|
||||||
@ -112,14 +112,18 @@ service.interceptors.response.use(
|
|||||||
}
|
}
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
// 未设置状态码则默认成功状态
|
// 未设置状态码则默认成功状态
|
||||||
const code = data.code || result_code
|
// 二进制数据则直接返回,例如说 Excel 导出
|
||||||
// 二进制数据则直接返回
|
|
||||||
if (
|
if (
|
||||||
response.request.responseType === 'blob' ||
|
response.request.responseType === 'blob' ||
|
||||||
response.request.responseType === 'arraybuffer'
|
response.request.responseType === 'arraybuffer'
|
||||||
) {
|
) {
|
||||||
|
// 注意:如果导出的响应为 json,说明可能失败了,不直接返回进行下载
|
||||||
|
if (response.data.type !== 'application/json') {
|
||||||
return response.data
|
return response.data
|
||||||
}
|
}
|
||||||
|
data = await new Response(response.data).json()
|
||||||
|
}
|
||||||
|
const code = data.code || result_code
|
||||||
// 获取错误信息
|
// 获取错误信息
|
||||||
const msg = data.msg || errorCode[code] || errorCode['default']
|
const msg = data.msg || errorCode[code] || errorCode['default']
|
||||||
if (ignoreMsgs.indexOf(msg) !== -1) {
|
if (ignoreMsgs.indexOf(msg) !== -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user