|
|
@@ -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)
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|