浏览代码

导出兼容ie内核

chenrui 3 年之前
父节点
当前提交
f2bea6ba86
共有 1 个文件被更改,包括 14 次插入7 次删除
  1. 14 7
      src/libs/exportExcel.js

+ 14 - 7
src/libs/exportExcel.js

@@ -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对象
+  }
 }