Commit 6bb2b3e8e027ebe7ec8927d8b33ca362b7bf5578

Authored by LH_PC
1 parent 2fd57d1f

feat:打印调整

src/utils/index.js
... ... @@ -614,15 +614,14 @@ export function getBlob(url) {
614 614 });
615 615 }
616 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 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 888 var browser = getBrowserEngine(printWin);
890 889 var subjectName = paper.subjectName;
891 890 var paperTitle = paper.title;
... ... @@ -911,7 +910,7 @@ export async function paperPrint(paper) {
911 910 }
912 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 914 windowParams.print();
916 915 windowParams.close();
917 916 }
... ... @@ -1171,7 +1170,7 @@ export async function paperPrint(paper) {
1171 1170  
1172 1171 const questionDom = printWin.document.createElement('div');
1173 1172 var subItem = item.subQuestions[idof];
1174   - var screenshotHtml = await fetchHTML(subItem.screenshot);
  1173 + var screenshotHtml = fetchHTML(subItem.screenshot);
1175 1174 var getStyleScripts = iof == 0 && idof == 0;
1176 1175 var screenshotObject = htmlParseDom(screenshotHtml, getStyleScripts);
1177 1176 var screenshotDoms = screenshotObject.doms;
... ... @@ -1199,16 +1198,10 @@ export async function paperPrint(paper) {
1199 1198 tableDom.appendChild(tfootDom);
1200 1199 printWin.document.body.appendChild(bodyBoxDom);
1201 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 1205 } else {
1213 1206 windowPrint(printWin);
1214 1207 }
... ...
src/views/basic/askTestQuestion/index.vue
... ... @@ -18,11 +18,11 @@
18 18 <el-input v-model="query.paper" :placeholder="dataType == '1' ? '搜索课件' : '搜索试卷'"
19 19 suffix-icon="el-icon-search" class="filter-input" clearable />
20 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 22 :value="item.classId" />
23 23 </el-select>
24 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 26 </el-select>
27 27 <el-select v-if="dataType == '2'" v-model="query.tagId" placeholder="选择测验类型" class="filter-select">
28 28 <el-option v-for="item in typeList" :key="item.label" :label="item.label" :value="item.value" />
... ... @@ -70,9 +70,9 @@
70 70 <el-dropdown-menu slot="dropdown">
71 71 <el-dropdown-item
72 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 76 <el-dropdown-item @click.native="_copy(item)">复制</el-dropdown-item>
77 77 <el-dropdown-item>
78 78 <el-popconfirm style="color:gray !important;"
... ... @@ -92,7 +92,7 @@
92 92 <span class="descption-label"> 授课端同步:</span>
93 93 <div class="descption-box">
94 94 <span class="descption-tag"
95   - v-for="( clazzChild, indexs ) in item.classList "
  95 + v-for="( clazzChild, indexs ) in item.classList "
96 96 :key="clazzChild.classId"
97 97 :class="clazzChild.keepStatus == 1 ? 'active' : ''">
98 98 {{ clazzChild.className }}
... ... @@ -198,7 +198,7 @@
198 198 <span class="descption-label"> 授课端同步:</span>
199 199 <div class="descption-box">
200 200 <span class="descption-tag"
201   - v-for="( clazzChild, indexs ) in item.classList "
  201 + v-for="( clazzChild, indexs ) in item.classList "
202 202 :key="clazzChild.classId"
203 203 :class="clazzChild.keepStatus == 1 ? 'active' : ''">
204 204 {{ clazzChild.className }}
... ... @@ -649,17 +649,16 @@ export default {
649 649 _delete() {
650 650  
651 651 },
652   - async _print(item){
  652 + _print(item) {
653 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 663 _updateQ(item) {
665 664  
... ...