From 6bb2b3e8e027ebe7ec8927d8b33ca362b7bf5578 Mon Sep 17 00:00:00 2001 From: LH_PC <2604481917@qq.com> Date: Thu, 28 Nov 2024 13:59:35 +0800 Subject: [PATCH] feat:打印调整 --- src/utils/index.js | 39 ++++++++++++++++----------------------- src/views/basic/askTestQuestion/index.vue | 33 ++++++++++++++++----------------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index bb691c0..9d9189f 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -614,15 +614,14 @@ export function getBlob(url) { }); } export function fetchHTML(url) { - return new Promise((resolve) => { - resolve( - service({ - url: url, - withCredentials: false, - method: "get" - }) - ); - }); + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, false); + xhr.send(); + if (xhr.status === 200) { + return xhr.responseText; + } else { + return null; + } } /** * 打包压缩下载 @@ -884,8 +883,8 @@ export function formatGradeNameClass(data) { } ///试卷定制化打印 -export async function paperPrint(paper) { - let printWin = window.open("", "_blank", ""); +export function paperPrint(paper) { + let printWin = window.open(undefined, "_blank", ""); var browser = getBrowserEngine(printWin); var subjectName = paper.subjectName; var paperTitle = paper.title; @@ -911,7 +910,7 @@ export async function paperPrint(paper) { } return "Blink"; // Assume it's Chrome, Safari, or an alternative Blink-based browser } - function windowPrint(windowParams) { + function windowPrint(windowParams) { windowParams.print(); windowParams.close(); } @@ -1171,7 +1170,7 @@ export async function paperPrint(paper) { const questionDom = printWin.document.createElement('div'); var subItem = item.subQuestions[idof]; - var screenshotHtml = await fetchHTML(subItem.screenshot); + var screenshotHtml = fetchHTML(subItem.screenshot); var getStyleScripts = iof == 0 && idof == 0; var screenshotObject = htmlParseDom(screenshotHtml, getStyleScripts); var screenshotDoms = screenshotObject.doms; @@ -1199,16 +1198,10 @@ export async function paperPrint(paper) { tableDom.appendChild(tfootDom); printWin.document.body.appendChild(bodyBoxDom); // generatePageParams(); - const iamges = printWin.document.querySelectorAll('img'); - if (iamges.length >= 1) { - var lastImage = iamges[iamges.length - 1]; - if (lastImage.complete) { - windowPrint(printWin); - } else { - lastImage.onload = function () { - windowPrint(printWin); - } - } + const lastImage = printWin.document.querySelector('img:last-child'); + if (lastImage) { + if (lastImage.complete) windowPrint(printWin); + lastImage.onload = () => windowPrint(printWin); } else { windowPrint(printWin); } diff --git a/src/views/basic/askTestQuestion/index.vue b/src/views/basic/askTestQuestion/index.vue index 2694e08..c5e639b 100644 --- a/src/views/basic/askTestQuestion/index.vue +++ b/src/views/basic/askTestQuestion/index.vue @@ -18,11 +18,11 @@ - - + @@ -70,9 +70,9 @@ 查看 - 打印 - 修改 + 打印 + 修改 复制 授课端同步:
{{ clazzChild.className }} @@ -198,7 +198,7 @@ 授课端同步:
{{ clazzChild.className }} @@ -649,17 +649,16 @@ export default { _delete() { }, - async _print(item){ + _print(item) { this.$loading.open(); - const { data, status, info } = await this.$request.tPaperDetail({ - paperId: item.id - }); - this.$loading.close(); - if (status != 0) { - this.$message.error(info); - return; - } - await paperPrint(data); + this.$request.tPaperDetail({ paperId: item.id }).then(({ data, status, info }) => { + if (status != 0) { + this.$message.error(info); + return; + } + paperPrint(data); + this.$loading.close(); + }) }, _updateQ(item) { -- libgit2 0.21.4