更新
This commit is contained in:
@ -73,17 +73,24 @@ service.interceptors.response.use(
|
||||
|
||||
// 通用下载方法
|
||||
export function download(url, params, filename, config) {
|
||||
let token = localStorage.getItem('token')
|
||||
return axios.post(url, params, {"Content-type": "multipart/form-data",headers:{"Authorization": `${token}`}}).then( async (data) => {
|
||||
const isBlob = blobValidate(data.data);
|
||||
console.log(isBlob,'====data');
|
||||
return service.post(url, params, {
|
||||
transformRequest: [(params) => { return tansParams(params) }],
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
responseType: 'blob',
|
||||
...config
|
||||
}).then(async (data) => {
|
||||
const isBlob = blobValidate(data);
|
||||
if (isBlob) {
|
||||
const blob = new Blob([data.data])
|
||||
const blob = new Blob([data])
|
||||
saveAs(blob, filename)
|
||||
} else {
|
||||
ElMessage.error('网络异常');
|
||||
const resText = await data.text();
|
||||
const rspObj = JSON.parse(resText);
|
||||
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default']
|
||||
ElMessage.error(errMsg);
|
||||
}
|
||||
// downloadLoadingInstance.close();
|
||||
}).catch((r) => {
|
||||
ElMessage.error('下载文件出现错误,请联系管理员!')
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user