| | |
| | | </el-dialog> |
| | | </div> |
| | | |
| | | |
| | | <el-dialog |
| | | title="PDF 预览" |
| | | :visible.sync="dialogVisible" |
| | |
| | | import { |
| | | addComp, |
| | | plRevokeTjOrderByTjNum, |
| | | getListByCompId, makeTjPDF, |
| | | getListByCompId, |
| | | makeTjPDF, |
| | | } from "@/api/system/comp"; |
| | | import { getCompany, queryCompany } from "@/api/team/tuanti"; |
| | | |
| | |
| | | this.objs.reservationTime = val; |
| | | }, |
| | | |
| | | 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() { |
| | | 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: "报告正在生成,请两分钟后预览!", |
| | | type: "warning", |
| | | 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.dialogVisible = true; |
| | | const newBlob = []; |
| | | newBlob.push(response); |
| | | const blob = new Blob(newBlob, { type: "application/pdf" }); |
| | | this.url = window.webkitURL.createObjectURL(blob); //将后端返回的blob文件读取出url |
| | | this.$modal.msgError("请选择撤销人员"); |
| | | } |
| | | }); |
| | | |
| | | }, |
| | | }, |
| | | }; |