fix: 下载文件时(responseType === 'blob')需要判断下载失败(返回json而非二进制)的情况

This commit is contained in:
dap 2025-01-17 10:48:52 +08:00
parent 6716e0c979
commit 77cd005f15
2 changed files with 20 additions and 2 deletions

View File

@ -18,6 +18,7 @@
- 字典项为空时getDict方法无限调用接口(无奈兼容 不给字典item本来就是错误用法)
- 表格排序翻页会丢失排序参数
- 下载文件时(responseType === 'blob')需要判断下载失败(返回json而非二进制)的情况
**OTHERS**

View File

@ -140,7 +140,7 @@ function createRequestClient(baseURL: string) {
);
client.addResponseInterceptor<HttpResponse>({
fulfilled: (response) => {
fulfilled: async (response) => {
const encryptKey = (response.headers || {})['encrypt-key'];
if (encryptKey) {
/** RSA私钥解密 拿到解密秘钥的base64 */
@ -164,8 +164,25 @@ function createRequestClient(baseURL: string) {
// 不进行任何处理,直接返回
// 用于页面代码可能需要直接获取codedatamessage这些信息时开启
if (!isTransformResponse) {
/**
* json
* type为blob且content-type为application/json时
* blob的类型 json类型和报错的类型是一致的
*/
if (
response.config.responseType === 'blob' &&
response.headers['content-type']?.includes?.('application/json')
) {
// 这时候的data为blob类型
const blob = response.data as unknown as Blob;
// 拿到字符串转json对象
response.data = JSON.parse(await blob.text());
// 然后按正常逻辑执行下面的代码(判断业务状态码)
} else {
// 不为blob 直接返回
return response.data;
}
}
const axiosResponseData = response.data;
if (!axiosResponseData) {