Commit 6bb2b3e8e027ebe7ec8927d8b33ca362b7bf5578
1 parent
2fd57d1f
feat:打印调整
Showing
2 changed files
with
32 additions
and
40 deletions
src/utils/index.js
@@ -614,15 +614,14 @@ export function getBlob(url) { | @@ -614,15 +614,14 @@ export function getBlob(url) { | ||
614 | }); | 614 | }); |
615 | } | 615 | } |
616 | export function fetchHTML(url) { | 616 | export function fetchHTML(url) { |
617 | - return new Promise((resolve) => { | ||
618 | - resolve( | ||
619 | - service({ | ||
620 | - url: url, | ||
621 | - withCredentials: false, | ||
622 | - method: "get" | ||
623 | - }) | ||
624 | - ); | ||
625 | - }); | 617 | + var xhr = new XMLHttpRequest(); |
618 | + xhr.open("GET", url, false); | ||
619 | + xhr.send(); | ||
620 | + if (xhr.status === 200) { | ||
621 | + return xhr.responseText; | ||
622 | + } else { | ||
623 | + return null; | ||
624 | + } | ||
626 | } | 625 | } |
627 | /** | 626 | /** |
628 | * 打包压缩下载 | 627 | * 打包压缩下载 |
@@ -884,8 +883,8 @@ export function formatGradeNameClass(data) { | @@ -884,8 +883,8 @@ export function formatGradeNameClass(data) { | ||
884 | } | 883 | } |
885 | 884 | ||
886 | ///试卷定制化打印 | 885 | ///试卷定制化打印 |
887 | -export async function paperPrint(paper) { | ||
888 | - let printWin = window.open("", "_blank", ""); | 886 | +export function paperPrint(paper) { |
887 | + let printWin = window.open(undefined, "_blank", ""); | ||
889 | var browser = getBrowserEngine(printWin); | 888 | var browser = getBrowserEngine(printWin); |
890 | var subjectName = paper.subjectName; | 889 | var subjectName = paper.subjectName; |
891 | var paperTitle = paper.title; | 890 | var paperTitle = paper.title; |
@@ -911,7 +910,7 @@ export async function paperPrint(paper) { | @@ -911,7 +910,7 @@ export async function paperPrint(paper) { | ||
911 | } | 910 | } |
912 | return "Blink"; // Assume it's Chrome, Safari, or an alternative Blink-based browser | 911 | return "Blink"; // Assume it's Chrome, Safari, or an alternative Blink-based browser |
913 | } | 912 | } |
914 | - function windowPrint(windowParams) { | 913 | + function windowPrint(windowParams) { |
915 | windowParams.print(); | 914 | windowParams.print(); |
916 | windowParams.close(); | 915 | windowParams.close(); |
917 | } | 916 | } |
@@ -1171,7 +1170,7 @@ export async function paperPrint(paper) { | @@ -1171,7 +1170,7 @@ export async function paperPrint(paper) { | ||
1171 | 1170 | ||
1172 | const questionDom = printWin.document.createElement('div'); | 1171 | const questionDom = printWin.document.createElement('div'); |
1173 | var subItem = item.subQuestions[idof]; | 1172 | var subItem = item.subQuestions[idof]; |
1174 | - var screenshotHtml = await fetchHTML(subItem.screenshot); | 1173 | + var screenshotHtml = fetchHTML(subItem.screenshot); |
1175 | var getStyleScripts = iof == 0 && idof == 0; | 1174 | var getStyleScripts = iof == 0 && idof == 0; |
1176 | var screenshotObject = htmlParseDom(screenshotHtml, getStyleScripts); | 1175 | var screenshotObject = htmlParseDom(screenshotHtml, getStyleScripts); |
1177 | var screenshotDoms = screenshotObject.doms; | 1176 | var screenshotDoms = screenshotObject.doms; |
@@ -1199,16 +1198,10 @@ export async function paperPrint(paper) { | @@ -1199,16 +1198,10 @@ export async function paperPrint(paper) { | ||
1199 | tableDom.appendChild(tfootDom); | 1198 | tableDom.appendChild(tfootDom); |
1200 | printWin.document.body.appendChild(bodyBoxDom); | 1199 | printWin.document.body.appendChild(bodyBoxDom); |
1201 | // generatePageParams(); | 1200 | // generatePageParams(); |
1202 | - const iamges = printWin.document.querySelectorAll('img'); | ||
1203 | - if (iamges.length >= 1) { | ||
1204 | - var lastImage = iamges[iamges.length - 1]; | ||
1205 | - if (lastImage.complete) { | ||
1206 | - windowPrint(printWin); | ||
1207 | - } else { | ||
1208 | - lastImage.onload = function () { | ||
1209 | - windowPrint(printWin); | ||
1210 | - } | ||
1211 | - } | 1201 | + const lastImage = printWin.document.querySelector('img:last-child'); |
1202 | + if (lastImage) { | ||
1203 | + if (lastImage.complete) windowPrint(printWin); | ||
1204 | + lastImage.onload = () => windowPrint(printWin); | ||
1212 | } else { | 1205 | } else { |
1213 | windowPrint(printWin); | 1206 | windowPrint(printWin); |
1214 | } | 1207 | } |
src/views/basic/askTestQuestion/index.vue
@@ -18,11 +18,11 @@ | @@ -18,11 +18,11 @@ | ||
18 | <el-input v-model="query.paper" :placeholder="dataType == '1' ? '搜索课件' : '搜索试卷'" | 18 | <el-input v-model="query.paper" :placeholder="dataType == '1' ? '搜索课件' : '搜索试卷'" |
19 | suffix-icon="el-icon-search" class="filter-input" clearable /> | 19 | suffix-icon="el-icon-search" class="filter-input" clearable /> |
20 | <el-select @change="_changeClass" v-model="query.class" class="filter-select" placeholder="选择班级"> | 20 | <el-select @change="_changeClass" v-model="query.class" class="filter-select" placeholder="选择班级"> |
21 | - <el-option v-for="item in classList" :key="item.classId" :label="item.className" | 21 | + <el-option v-for="item in classList" :key="item.classId" :label="item.className" |
22 | :value="item.classId" /> | 22 | :value="item.classId" /> |
23 | </el-select> | 23 | </el-select> |
24 | <el-select v-model="query.subject" placeholder="选择科目" class="filter-select"> | 24 | <el-select v-model="query.subject" placeholder="选择科目" class="filter-select"> |
25 | - <el-option v-for=" item in subjectList " :key="item" :label="item" :value="item" /> | 25 | + <el-option v-for=" item in subjectList " :key="item" :label="item" :value="item" /> |
26 | </el-select> | 26 | </el-select> |
27 | <el-select v-if="dataType == '2'" v-model="query.tagId" placeholder="选择测验类型" class="filter-select"> | 27 | <el-select v-if="dataType == '2'" v-model="query.tagId" placeholder="选择测验类型" class="filter-select"> |
28 | <el-option v-for="item in typeList" :key="item.label" :label="item.label" :value="item.value" /> | 28 | <el-option v-for="item in typeList" :key="item.label" :label="item.label" :value="item.value" /> |
@@ -70,9 +70,9 @@ | @@ -70,9 +70,9 @@ | ||
70 | <el-dropdown-menu slot="dropdown"> | 70 | <el-dropdown-menu slot="dropdown"> |
71 | <el-dropdown-item | 71 | <el-dropdown-item |
72 | @click.native="_detailQ(item.id)">查看</el-dropdown-item> | 72 | @click.native="_detailQ(item.id)">查看</el-dropdown-item> |
73 | - <el-dropdown-item v-if="dataType != 1" | ||
74 | - @click.native="_print(item)">打印</el-dropdown-item> | ||
75 | - <el-dropdown-item @click.native="_updateQ(item)">修改</el-dropdown-item> | 73 | + <el-dropdown-item v-if="dataType != 1" |
74 | + @click.native="_print(item)">打印</el-dropdown-item> | ||
75 | + <el-dropdown-item @click.native="_updateQ(item)">修改</el-dropdown-item> | ||
76 | <el-dropdown-item @click.native="_copy(item)">复制</el-dropdown-item> | 76 | <el-dropdown-item @click.native="_copy(item)">复制</el-dropdown-item> |
77 | <el-dropdown-item> | 77 | <el-dropdown-item> |
78 | <el-popconfirm style="color:gray !important;" | 78 | <el-popconfirm style="color:gray !important;" |
@@ -92,7 +92,7 @@ | @@ -92,7 +92,7 @@ | ||
92 | <span class="descption-label"> 授课端同步:</span> | 92 | <span class="descption-label"> 授课端同步:</span> |
93 | <div class="descption-box"> | 93 | <div class="descption-box"> |
94 | <span class="descption-tag" | 94 | <span class="descption-tag" |
95 | - v-for="( clazzChild, indexs ) in item.classList " | 95 | + v-for="( clazzChild, indexs ) in item.classList " |
96 | :key="clazzChild.classId" | 96 | :key="clazzChild.classId" |
97 | :class="clazzChild.keepStatus == 1 ? 'active' : ''"> | 97 | :class="clazzChild.keepStatus == 1 ? 'active' : ''"> |
98 | {{ clazzChild.className }} | 98 | {{ clazzChild.className }} |
@@ -198,7 +198,7 @@ | @@ -198,7 +198,7 @@ | ||
198 | <span class="descption-label"> 授课端同步:</span> | 198 | <span class="descption-label"> 授课端同步:</span> |
199 | <div class="descption-box"> | 199 | <div class="descption-box"> |
200 | <span class="descption-tag" | 200 | <span class="descption-tag" |
201 | - v-for="( clazzChild, indexs ) in item.classList " | 201 | + v-for="( clazzChild, indexs ) in item.classList " |
202 | :key="clazzChild.classId" | 202 | :key="clazzChild.classId" |
203 | :class="clazzChild.keepStatus == 1 ? 'active' : ''"> | 203 | :class="clazzChild.keepStatus == 1 ? 'active' : ''"> |
204 | {{ clazzChild.className }} | 204 | {{ clazzChild.className }} |
@@ -649,17 +649,16 @@ export default { | @@ -649,17 +649,16 @@ export default { | ||
649 | _delete() { | 649 | _delete() { |
650 | 650 | ||
651 | }, | 651 | }, |
652 | - async _print(item){ | 652 | + _print(item) { |
653 | this.$loading.open(); | 653 | this.$loading.open(); |
654 | - const { data, status, info } = await this.$request.tPaperDetail({ | ||
655 | - paperId: item.id | ||
656 | - }); | ||
657 | - this.$loading.close(); | ||
658 | - if (status != 0) { | ||
659 | - this.$message.error(info); | ||
660 | - return; | ||
661 | - } | ||
662 | - await paperPrint(data); | 654 | + this.$request.tPaperDetail({ paperId: item.id }).then(({ data, status, info }) => { |
655 | + if (status != 0) { | ||
656 | + this.$message.error(info); | ||
657 | + return; | ||
658 | + } | ||
659 | + paperPrint(data); | ||
660 | + this.$loading.close(); | ||
661 | + }) | ||
663 | }, | 662 | }, |
664 | _updateQ(item) { | 663 | _updateQ(item) { |
665 | 664 |