安全管理/知识库
This commit is contained in:
@ -61,5 +61,24 @@ export default {
|
||||
const rspObj = JSON.parse(resText);
|
||||
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'];
|
||||
ElMessage.error(errMsg);
|
||||
},
|
||||
async direct(fileUrl: string, filename?: string) {
|
||||
downloadLoadingInstance = ElLoading.service({ text: '正在下载文件,请稍候...', background: 'rgba(0, 0, 0, 0.7)' });
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: fileUrl,
|
||||
responseType: 'blob',
|
||||
headers: globalHeaders() // 可根据是否跨域决定是否保留
|
||||
});
|
||||
const blob = new Blob([res.data], { type: 'application/octet-stream' });
|
||||
const name = filename || decodeURIComponent(fileUrl.split('/').pop()!);
|
||||
FileSaver.saveAs(blob, name);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
ElMessage.error('下载文件失败,请检查链接或联系管理员');
|
||||
} finally {
|
||||
downloadLoadingInstance.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user