From 015aeab7a6a99afd0b24ee6ea7b5e4a9c950c3b5 Mon Sep 17 00:00:00 2001 From: qinxianzhangyao <11053546+qinxianzhangyao@user.noreply.gitee.com> Date: 星期一, 27 五月 2024 18:05:52 +0800 Subject: [PATCH] qxtj --- src/views/reservation/grouprecords/index.vue | 81 +++++++++++++++++++++++++++------------- 1 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/views/reservation/grouprecords/index.vue b/src/views/reservation/grouprecords/index.vue index 2360633..6bfe0c7 100644 --- a/src/views/reservation/grouprecords/index.vue +++ b/src/views/reservation/grouprecords/index.vue @@ -281,7 +281,6 @@ </el-dialog> </div> - <el-dialog title="PDF 棰勮" :visible.sync="dialogVisible" @@ -303,7 +302,8 @@ import { addComp, plRevokeTjOrderByTjNum, - getListByCompId, makeTjPDF, + getListByCompId, + makeTjPDF, } from "@/api/system/comp"; import { getCompany, queryCompany } from "@/api/team/tuanti"; @@ -466,7 +466,7 @@ single: true, // 闈炲涓鐢� multiple: true, - ids:[], + ids: [], // 鎬绘潯鏁� total: 0, // 寮瑰嚭灞傛爣棰� @@ -591,32 +591,61 @@ this.objs.reservationTime = val; }, - /** 纭鎸夐挳 */ - submitForm() { - makeTjPDF().then((response) => { - if (response.size === 0) { - const loading = this.$loading({ - lock: true, - text: "Loading", - spinner: "el-icon-loading", - background: "rgba(0, 0, 0, 0.7)", - }); - setTimeout(() => { - loading.close(); - }, 3000); - this.$message({ - message: "鎶ュ憡姝e湪鐢熸垚锛岃涓ゅ垎閽熷悗棰勮锛�", - type: "warning", - }); - } else { - this.dialogVisible = true; - const newBlob = []; - newBlob.push(response); - const blob = new Blob(newBlob, { type: "application/pdf" }); - this.url = window.webkitURL.createObjectURL(blob); //灏嗗悗绔繑鍥炵殑blob鏂囦欢璇诲彇鍑簎rl + base64ToBlob({ b64data = "", contentType = "", sliceSize = 512 } = {}) { + return new Promise((resolve, reject) => { + // 浣跨敤 atob() 鏂规硶灏嗘暟鎹В鐮� + let byteCharacters = atob(b64data); + let byteArrays = []; + for ( + let offset = 0; + offset < byteCharacters.length; + offset += sliceSize + ) { + let slice = byteCharacters.slice(offset, offset + sliceSize); + let byteNumbers = []; + for (let i = 0; i < slice.length; i++) { + byteNumbers.push(slice.charCodeAt(i)); + } + // 8 浣嶆棤绗﹀彿鏁存暟鍊肩殑绫诲瀷鍖栨暟缁勩�傚唴瀹瑰皢鍒濆鍖栦负 0銆� + // 濡傛灉鏃犳硶鍒嗛厤璇锋眰鏁扮洰鐨勫瓧鑺傦紝鍒欏皢寮曞彂寮傚父銆� + byteArrays.push(new Uint8Array(byteNumbers)); } + let result = new Blob(byteArrays, { + type: contentType, + }); + result = Object.assign(result, { + // jartto: 杩欓噷涓�瀹氳澶勭悊涓�涓� URL.createObjectURL + preview: URL.createObjectURL(result), + // name: `鍥剧墖绀轰緥.png`, + }); + resolve(result); }); }, + + /** 纭鎸夐挳 */ + submitForm() { + if (this.ids.length != 0) { + makeTjPDF(this.ids).then((response) => { + let base64 = response.file; + this.base64ToBlob({ + b64data: base64, + contentType: "application/pdf", + }).then((res) => { + this.dialogVisible = true; + // 杞悗鍚庣殑blob瀵硅薄 + console.log("blob", res.preview); + try { + this.url =res.preview; + } catch (error) { + this.url = window.webkitURL.createObjectURL(res.preview); + } + }) + }); + } else { + this.$modal.msgError("璇烽�夋嫨鎾ら攢浜哄憳"); + } + + }, }, }; </script> -- Gitblit v1.8.0