src/libs/util.js
文件中
// 下载文件-base64格式
export const downloadFile = (res, customName) => {
const blob = new Blob([res.data])
// const fileName = customName ? `${customName}.xlsx` : `导出文件.xlsx` // 下载文件名称
let name = res.headers['content-disposition']
let regFileNames = name?.match(/=(.*)$/)[1]
let fileName = regFileNames ? decodeURI(regFileNames) : '导出文件.xlsx'
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
}
src/api/collect.js
文件中
// 导出付款信息
export const exportPayOrder = data => {
return axios.request({
url: '/mall/order/collection/backend/exportPayOrder',
params: data,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'get',
responseType: 'blob'
})
}
collectList.vue
文件中使用
// 导出付款信息
handleExport() {
this.formInline.payDateMin = this.payDate && this.payDate.length ? this.payDate[0] : ''
this.formInline.payDateMax = this.payDate && this.payDate.length ? this.payDate[1] : ''
let param = {
baseId: this.baseId,
...this.formInline
}
this.exporLoading = true
exportPayOrder(param)
.then(res => {
downloadFile(res)
this.exporLoading = false
})
.catch(err => {
this.exporLoading = false
})
}