安全管理/知识库

This commit is contained in:
Teo
2025-06-26 20:00:26 +08:00
parent 04dac2eba1
commit 5e5803b641
9 changed files with 2030 additions and 2 deletions

View File

@ -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();
}
}
};