|
@@ -29,13 +29,20 @@ export const hdExportExcel = function (url, params, fileName, callback) {
|
|
|
// 导出下载excel
|
|
|
export const downloadExcel = function (data, fileName) {
|
|
|
if (!data) { return }
|
|
|
- const url = window.URL.createObjectURL(new Blob([data]))
|
|
|
- const link = document.createElement('a')
|
|
|
- link.style.display = 'none'
|
|
|
- link.href = url
|
|
|
const a = moment().format('YYYYMMDDHHmmss')
|
|
|
const fname = fileName + a
|
|
|
- link.setAttribute('download', fname + '.xlsx')
|
|
|
- document.body.appendChild(link)
|
|
|
- link.click()
|
|
|
+ const blob = new Blob([data], { type: 'application/vnd.ms-excel' })
|
|
|
+ if (window.navigator && window.navigator.msSaveOrOpenBlob) {
|
|
|
+ navigator.msSaveBlob(blob, fname + '.xlsx')
|
|
|
+ } else {
|
|
|
+ const link = document.createElement('a')
|
|
|
+ link.style.display = 'none'
|
|
|
+ var href = URL.createObjectURL(blob)
|
|
|
+ link.href = href
|
|
|
+ link.setAttribute('download', fname + '.xlsx')
|
|
|
+ document.body.appendChild(link)
|
|
|
+ link.click()
|
|
|
+ document.body.removeChild(link)
|
|
|
+ window.URL.revokeObjectURL(href) // 释放掉blob对象
|
|
|
+ }
|
|
|
}
|