excel导出


function exportAllDeviceData (data) {
return instance({
url: baseUrl + devManage.exportAllDeviceUrl,
headers: {
'accept': 'application/octet-stream' // 重要
},
method: 'post',
data: data,
responseType: 'blob'
}).then(function (response) {
const data = response.data
const fileName = 'deviceList.xls'// 重要--决定下载文件名
util.exportExcel(data, fileName)
})
}

/**************** util.js ******************************/
function exportExcel (excelBlob, fileName) {
if (browse.isIE() || browse.isIE11()) {
window.navigator.msSaveOrOpenBlob(excelBlob, fileName)
} else {
const url = URL.createObjectURL(excelBlob)// 重要
const link = document.createElement('a')
link.href = url
link.download = fileName
link.click()
link.remove()
}
}

/**************** browse.js ******************************/
/**
* 判断是否是IE
*/
function isIE () {
if (!!window.ActiveXobject || 'ActiveXObject' in window) {
return true
} else {
return false
}
}
/**
* 判断是否是IE11
*/
function isIE11 () {
if ((/Trident\/7\./).test(navigator.userAgent)) {
return true
} else {
return false
}
}

export default {
isIE,
isIE11
}
posted @ 2021-07-01 09:14  w20200618  阅读(52)  评论(0)    收藏  举报