From 5a8aa7f9ae26577e3f204dbacee755f928d12e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E8=99=B9=E7=9D=BF?= <297504645@qq.com> Date: Wed, 23 Aug 2023 09:42:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=85=A7=E7=89=87=E9=A2=84=E8=A7=88+pdf?= =?UTF-8?q?=E9=A2=84=E8=A7=88=EF=BC=8C=E7=BB=84=E4=BB=B6=E5=B0=81=E8=A3=85?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fe/PC/src/components/pdf/index.vue | 36 +++++++++++++++++++ fe/PC/src/utils/tableColumns/index.js | 2 +- .../quality/InspectRequest.vue | 5 +++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/fe/PC/src/components/pdf/index.vue b/fe/PC/src/components/pdf/index.vue index 434d2e959..fd1f15607 100644 --- a/fe/PC/src/components/pdf/index.vue +++ b/fe/PC/src/components/pdf/index.vue @@ -22,6 +22,7 @@ > + 下 载 取 消 @@ -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) } } } diff --git a/fe/PC/src/utils/tableColumns/index.js b/fe/PC/src/utils/tableColumns/index.js index 2594e9d7a..df03bd080 100644 --- a/fe/PC/src/utils/tableColumns/index.js +++ b/fe/PC/src/utils/tableColumns/index.js @@ -1261,7 +1261,7 @@ export const unqualifiedInfo = [ { label: "质量缺陷", prop: "massDefect" }, { label: "到货日期", prop: "arriveDate",type: "dateTime" }, { label: "过期时间", prop: "expireDate",type: "dateTime" }, - { label:"查看照片",type:"button", fixed: "right",tableAlign:"center",tableHeaderAlign:"center" }, + { label:"查看照片",prop: 'inspectPhotoJson',type:"button", fixed: "right",tableAlign:"center",tableHeaderAlign:"center" }, { label: "创建时间", prop: "creationTime",type: "dateTime" }, { label: "上次修改时间", prop: 'lastModificationTime', type: "dateTime" }, { label: "订单号", prop: "poNumber" }, diff --git a/fe/PC/src/views/rawMaterialManage/quality/InspectRequest.vue b/fe/PC/src/views/rawMaterialManage/quality/InspectRequest.vue index f1f0c3517..d8ad667c1 100644 --- a/fe/PC/src/views/rawMaterialManage/quality/InspectRequest.vue +++ b/fe/PC/src/views/rawMaterialManage/quality/InspectRequest.vue @@ -213,11 +213,13 @@ @@ -267,6 +269,8 @@ export default { rowId: '', // pdf预览路径 urlPDF: '', + // 纯base64(去掉data:application/pdf;base64,) + base64PDF:'', // titlePDF 文件预览标题 titlePDF: '', // 是否显示文件预览框 @@ -531,6 +535,7 @@ export default { this.loadingPDF = true getFilestore({blobName:_file_id}).then(res=>{ this.urlPDF = 'data:application/pdf;base64,'+res.bytes + this.base64PDF=res.bytes this.titlePDF = res.fileName this.loadingPDF = false }).catch(res=>{