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

pull/346/MERGE
YunaiV 2023-12-30 19:11:29 +08:00
parent 9591ed7084
commit ccb997ac2a
1 changed files with 8 additions and 4 deletions

View File

@ -104,7 +104,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]请求没有返回值”;
@ -112,14 +112,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) {