前台代码
export function downLoad(id) {var url = baseURL + `/api/admin/system/promotion/downLoad/${id}`axios({method: 'get',url: url,responseType: 'blob',headers: { 'Authori-Zation': getToken() }}).then(async (res) => {// 从 Content-Disposition 头部解析文件名 const contentDisposition = res.headers['content-disposition']; let filename = ''; if (contentDisposition && contentDisposition.indexOf('attachment') !== -1) { const matches = /"([^"]*)"/.exec(contentDisposition); if (matches != null && matches[1]) { filename = matches[1]; } } // 如果文件名未解析到,可以使用默认名或错误处理 if (!filename) { filename = 'default_filename.png'; console.error('无法从响应头中获取文件名,使用默认文件名'); } // 创建一个 Blob 对象并保存文件