Sfoglia il codice sorgente

feat:发票管理

jinx 3 anni fa
parent
commit
7031f061ed
1 ha cambiato i file con 13 aggiunte e 3 eliminazioni
  1. 13 3
      src/page/invoice/index.vue

+ 13 - 3
src/page/invoice/index.vue

@@ -485,9 +485,19 @@ export default {
 
         try {
           let blob = new Blob([exec], {type: 'application/vnd.ms-excel'})
-          let url = URL.createObjectURL(blob)
-          console.log(url)
-          location.href = url
+          let href = URL.createObjectURL(blob)
+          console.log(href)
+          // location.href = url
+
+          // 谷歌浏览器 创建a标签 添加download属性下载
+          const downloadElement = document.createElement('a')
+          downloadElement.href = href
+          downloadElement.target = '_blank'
+          downloadElement.download = new Date().getTime() + '.xls'
+          document.body.appendChild(downloadElement)
+          downloadElement.click() // 点击下载
+          document.body.removeChild(downloadElement) // 下载完成移除元素
+          window.URL.revokeObjectURL(href) // 释放掉blob对象
         } catch (e) {
           console.error(e)
         }