let parms = `?start=${this.searchForm.timeValue[0]}&end=${this.searchForm.timeValue[1]}¢erId=${this.searchForm.centerId}&customerId=${this.searchForm.customerId}&queryStr=${this.searchForm.queryStr}&status=${3}`
axios({ // 用axios发送请求
method: \'get\',
url: baseURL + \'/sales/order/realTimeOrderExport\' + parms, // 请求地址
headers: {
token: store.state.UserToken
},
responseType: \'blob\' // 表明返回服务器返回的数据类型
}).then((res) => { // 处理返回的文件流
const content = res.data // 返回的内容
const fileName = \'明细下载.xlsx\'// 下载文件名
download(content, fileName)
}).catch(e => {
this.$message.error(\'获取自雇者协议出错\')
})
function download (content, fileName) {
const blob = new Blob([content]) // 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
const url = window.URL.createObjectURL(blob)// URL.createObjectURL(object)表示生成一个File对象或Blob对象
let dom = document.createElement(\'a\')// 设置一个隐藏的a标签,href为输出流,设置download
dom.style.display = \'none\'
dom.href = url
dom.setAttribute(\'download\', fileName)// 指示浏览器下载url,而不是导航到它;因此将提示用户将其保存为本地文件
document.body.appendChild(dom)
dom.click()
}