lihongxiao 3 lat temu
rodzic
commit
f3bd8f93b9
1 zmienionych plików z 37 dodań i 2 usunięć
  1. 37 2
      src/views/Letter/Orderlist.vue

+ 37 - 2
src/views/Letter/Orderlist.vue

@@ -1666,13 +1666,48 @@ export default {
       this.pageRequest.pageNum = val;
       this.findPage();
     },
+    getBlob(url) {
+      return new Promise(resolve => {
+        const xhr = new XMLHttpRequest()
+        xhr.open('GET', url)
+        xhr.responseType = 'blob'
+        xhr.onload = () => {
+          if (xhr.status === 200) {
+            resolve(xhr.response)
+          }
+        }
+        xhr.send()
+      })
+    },
+    saveAs(blob, filename) {
+      var link = document.createElement('a')
+      link.href = window.URL.createObjectURL(blob)
+      link.target = '_ blank';
+      link.download = filename
+      link.click()
+    },
+   
     //预览文件
     viewfile(index) {
+      console.log(index,11111111)
+
+      // fetch(index.fileUrl)
+      // .then(response => response.blob())
+      // .then(blob => {
+      //   console.log(blob,11111111)
+      //   this.saveAs(blob,  this.licenseNo  +'.pdf')
+      // })
+      // .catch(error => {
+      // });
+
+      // this.getBlob(index.fileUrl).then(blob => {
+      //   this.saveAs(blob,  this.licenseNo  +'.pdf')
+      // })
+
       const a = document.createElement('a')
       a.href = index.fileurl
       a.target = '_ blank';
-      a.download = this.licenseNo + '-' + index.filename + '-' + index.fileTitle;  // 下载文件的名字
-      document.body.appendChild(a)
+      a.download = this.licenseNo+ '.pdf';  // 下载文件的名字
       a.click()
     },
     //锚链接