- api接口
// 数据管理新版导出(表单、流程表单)
export function exportExcelV2(formId, data) {
return request({
responseType: 'blob',
url: `application-service/v1/form/${formId}/export/excel`,
method: 'post',
data
})
}
- 接口实现
if (!res.data.code) {
const content = res.data
const blob = new Blob([content])
const formName = this.$route.query.formName !== undefined ? this.$route.query.formName : '导出测试'
const fileName = formName + '.xls'
if ('download' in document.createElement('a')) { // 非IE下载
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)
} else {
navigator.msSaveBlob(blob, fileName)
}