解决token下载文件权限

This commit is contained in:
red-deng-deng 2021-11-29 14:37:25 +08:00
parent 528b300bc0
commit 26cfe3e8a6
1 changed files with 46 additions and 5 deletions

View File

@ -11,7 +11,29 @@ const upload = (method, url, params, responseType) => {
body: params,
}
let http = fetch(url, obj).then(res =>{
if(res.status==200){
return res.json()
}else{
switch (res.status) {
// 401: 未登录
case 401:
res.json().then(response =>{
if(response.code==403){
Notify.clear();
Notify.error(response.message);
setTimeout(() => {
window.location.href='/login';
}, 2000)
}else if(response.code==401){
Notify.clear();
Notify.error(response.message);
}
}
).catch();
break;
}
}
} );
return http.then(response => response).catch(error => console.error('Error:', error));
}
@ -36,7 +58,29 @@ const upload = (method, url, params, responseType) => {
}
}
let http = fetch(url, obj).then(res =>{
if(res.status==200){
return res.blob()
}else{
switch (res.status) {
// 401: 未登录
case 401:
res.json().then(response =>{
if(response.code==403){
Notify.clear();
Notify.error(response.message);
setTimeout(() => {
window.location.href='/login';
}, 2000)
}else if(response.code==401){
Notify.clear();
Notify.error(response.message);
}
}
).catch();
break;
}
}
} );
return http.then(response => response).catch(error => console.error('Error:', error));
}
@ -110,9 +154,6 @@ const req = (method, url, params, responseType) => {
break;
}
}
console.log(res);
} );
return http.then(response =>response).catch(error => console.error('Error:', error));
}