fix: 修复文件下载时乱码的问题

This commit is contained in:
Xu Zhimeng 2023-11-14 11:12:31 +08:00
parent fb23e422d8
commit e0ae878a6d

View File

@ -113,7 +113,7 @@ export const fetchAndDownload = async (url, data, method='post') => {
method,
url,
data,
responseType: 'blob',
headers: {
'X-Sign': sign,
'X-TIMESTAMP': signMd5Utils.getTimestamp(),
@ -128,19 +128,18 @@ export const fetchAndDownload = async (url, data, method='post') => {
const response = await Axios(config)
const { status, headers, data: responseData } = response
if (status == 200) {
if (typeof responseData == 'object') {
const { message: msg } = responseData
if (responseData.type == 'application/json') {
const res = await readFile(responseData)
const parsed = JSON.parse(res)
const { message: msg } = parsed
message.error(msg)
throw new Error(msg)
} else {
const disposition = headers['content-disposition']
const fileName = getFileNameByHeaderContentDisposition(disposition)
if (typeof responseData == 'string') {
const blob = new Blob([responseData], { type: headers['content-type'] })
saveAs(blob, fileName)
saveAs(responseData, fileName)
return fileName
}
}
} else {
message.error('This operation fails. Contact your system administrator')
throw new Error('This operation fails. Contact your system administrator')