🐛 修复 Excel 导出失败时,依然下载的问题

(cherry picked from commit ccb997ac2a)
pull/420/head
YunaiV 2023-12-30 19:11:29 +08:00 committed by shizhong
parent c124ca4879
commit ce62ded6b6
1 changed files with 8 additions and 4 deletions

View File

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