|
|
@ -22,6 +22,7 @@ |
|
|
|
></pdf> |
|
|
|
</div> |
|
|
|
<span slot="footer" class="dialog-footer"> |
|
|
|
<el-button v-if="showDownLoad && !loadingPDF" type="success" @click="downLoad">下 载</el-button> |
|
|
|
<el-button @click="close">取 消</el-button> |
|
|
|
</span> |
|
|
|
</el-dialog> |
|
|
@ -44,14 +45,25 @@ export default { |
|
|
|
} |
|
|
|
}, |
|
|
|
props: { |
|
|
|
// 预览链接(有data:application/pdf;base64,) |
|
|
|
urlPDF: { |
|
|
|
type: String, |
|
|
|
default: '', |
|
|
|
}, |
|
|
|
// 纯base64(去掉data:application/pdf;base64,) |
|
|
|
base64PDF:{ |
|
|
|
type: String, |
|
|
|
default: '', |
|
|
|
}, |
|
|
|
title: { |
|
|
|
type: String, |
|
|
|
default: '', |
|
|
|
}, |
|
|
|
//是否显示下载按钮 |
|
|
|
showDownLoad: { |
|
|
|
type: Boolean, |
|
|
|
default: false |
|
|
|
}, |
|
|
|
isShowPDF: { |
|
|
|
type: Boolean, |
|
|
|
default: false |
|
|
@ -76,6 +88,30 @@ export default { |
|
|
|
}, |
|
|
|
close(){ |
|
|
|
this.$emit('closePDF') |
|
|
|
}, |
|
|
|
// base64转换 |
|
|
|
base64ToArrayBuffer (base64) { |
|
|
|
var binaryString = window.atob(base64) |
|
|
|
var binaryLen = binaryString.length |
|
|
|
var bytes = new Uint8Array(binaryLen) |
|
|
|
for (var i = 0; i < binaryLen; i++) { |
|
|
|
var ascii = binaryString.charCodeAt(i) |
|
|
|
bytes[i] = ascii |
|
|
|
} |
|
|
|
return bytes |
|
|
|
}, |
|
|
|
downLoad(){ |
|
|
|
console.log(this.base64PDF) |
|
|
|
let byte = this.base64ToArrayBuffer(this.base64PDF) |
|
|
|
const link = document.createElement('a') // 创建a标签 |
|
|
|
const blob = new Blob([byte], { |
|
|
|
type: 'application/vnd.ms-excel;charset=utf-8', |
|
|
|
}) // response就是接口返回的文件流 |
|
|
|
const objectUrl = URL.createObjectURL(blob) |
|
|
|
link.href = objectUrl |
|
|
|
link.download = this.title |
|
|
|
link.click() // 下载文件 |
|
|
|
URL.revokeObjectURL(objectUrl) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|