scorpio 2 år sedan
förälder
incheckning
c3c9c65d01
2 ändrade filer med 25 tillägg och 5 borttagningar
  1. 24 4
      src/views/resource/component/preview.vue
  2. 1 1
      src/views/task/component/task.vue

+ 24 - 4
src/views/resource/component/preview.vue

@@ -201,12 +201,32 @@ export default {
         }
       })
     },
-    async downloadClick() {
-      console.log(this.data)
+    // 将一个url转化为blob格式的
+    getBlob(url) {
+      return new Promise(resolve => {
+        const xhr = new XMLHttpRequest()
+        xhr.open('GET', url, true)
+        xhr.responseType = 'blob'
+        xhr.onload = () => {
+          if (xhr.status === 200) {
+            resolve(xhr.response)
+          }
+        }
+        xhr.send()
+      })
+    },
+    // 最简单a标签那一套
+    saveAs(blob, fileName) {
       const link = document.createElement('a')
-      link.href = this.data.fileAttach.filePath
-      link.download = this.data.title
+      link.href = window.URL.createObjectURL(blob)
+      link.download = fileName
       link.click()
+    },
+
+    async downloadClick() {
+      this.getBlob(this.data.fileAttach.filePath).then(blob => {
+        this.saveAs(blob, this.data.title)
+      })
     }
   }
 }

+ 1 - 1
src/views/task/component/task.vue

@@ -338,7 +338,7 @@ export default {
       this.resultFileInfo()
     },
     fetchIndex(list, key) {
-      const index = list.findIndex(ele => ele.value === key)
+      1st index = list.findIndex(ele => ele.value === key)
       if (index > -1) {
         list.map(ele => {
           ele.checked = false