function downloadFile() {
// 文件下载地址
const fileUrl = ‘http://localhost:8089/SmartProperty/HouseFileController/downFile’;
// 设置请求头
const headers = new Headers();
headers.append(‘token’, ‘eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIxIiwib3JnTmFtZSI6IuW6k-WwlOWLkuW4guaDoOWxheeJqeS4muaciemZkOWFrOWPuCIsInVzZXJSZWFsTmFtZSI6ImFkbWluIiwiYXBwZmxhZyI6Ik4iLCJ0eXBlTmFtZSI6IueJqeS4miIsImNvbW11bml0eUxpc3QiOiIxLDEwOCwyLDQyLDg1LDEwOSwxMTAsMTExLDExMiwxMTQsMTIxLDEyNCwxMjUsMTIyLDEyMywiLCJleHAiOjE3MDkxNDQ2NDUsIm9yZ0lkIjoiMSIsInVzZXJuYW1lIjoiYWRtaW4iLCJ0eXBlQ29kZSI6IjEifQ.fiLlGvGsDjRp4LYfCrKvPy5Mxb2XNsN3gwxOfr1VIa0’); // 设置授权头,替换YourAccessToken为实际的访问令牌
// 发起 Fetch 请求
fetch(fileUrl, {
method: ‘GET’,
headers: headers,
})
.then(response => response.blob())
.then(blob => {
// 创建一个虚拟的链接元素,模拟点击下载
const link = document.createElement(‘a’);
link.href = window.URL.createObjectURL(blob);
link.download = ‘房产信息表.xlsx’; // 设置下载文件名,替换filename.ext为实际的文件名和扩展名
document.body.appendChild(link);
// 模拟点击
link.click();
// 移除虚拟链接元素
document.body.removeChild(link);
})
.catch(error => console.error('下载失败:', error));
}