//下載文件
export function downloadPDF(data, name = 'file.docx') {
if (!data) {
return
}
var blob = new Blob([data], {
type:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8',
})
if (isIE()) {
window.navigator.msSaveOrOpenBlob(blob, name)
return
}
var url = window.URL.createObjectURL(blob)
var aLink = document.createElement('a')
aLink.style.display = 'none'
aLink.href = url
aLink.setAttribute('download', name)
document.body.appendChild(aLink)
aLink.click()
document.body.removeChild(aLink) //下載完成移除元素
window.URL.revokeObjectURL(url) //釋放掉blob對象
}
//下載文件
export function downloadExcel(data, name = 'file.xls') {
if (!data) {
return
}
var blob = new Blob([data], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8',
})
if (isIE()) {
window.navigator.msSaveOrOpenBlob(blob, name)
return
}
var url = window.URL.createObjectURL(blob)
var aLink = document.createElement('a')
aLink.style.display = 'none'
aLink.href = url
aLink.setAttribute('download', name)
document.body.appendChild(aLink)
aLink.click()
document.body.removeChild(aLink) //下載完成移除元素
window.URL.revokeObjectURL(url) //釋放掉blob對象
}
//判斷瀏覽器類型
function isIE() {
if (!!window.ActiveXObject || 'ActiveXObject' in window) return true
else return false
}