Commit 44f5886e09171a9f7a29f657cbc47f513fbc589b
1 parent
bfb748bf
wip: 代码提交
Showing
1 changed file
with
95 additions
and
74 deletions
src/utils/index.js
| ... | ... | @@ -276,7 +276,7 @@ export function b64DecodeUnicode(str) { |
| 276 | 276 | }) |
| 277 | 277 | .join("") |
| 278 | 278 | ); |
| 279 | - } catch (e) { } | |
| 279 | + } catch (e) {} | |
| 280 | 280 | return uni; |
| 281 | 281 | } |
| 282 | 282 | |
| ... | ... | @@ -623,8 +623,7 @@ export function fetchHTML(url) { |
| 623 | 623 | } else { |
| 624 | 624 | return ""; |
| 625 | 625 | } |
| 626 | - } | |
| 627 | - catch (e) { | |
| 626 | + } catch (e) { | |
| 628 | 627 | return ""; |
| 629 | 628 | } |
| 630 | 629 | } |
| ... | ... | @@ -907,11 +906,17 @@ export function paperPrint(paper) { |
| 907 | 906 | if (windowParams.navigator.userAgent.indexOf("Trident") > -1) { |
| 908 | 907 | return "Trident"; // IE |
| 909 | 908 | } |
| 910 | - if (/Chrome/.test(windowParams.navigator.userAgent) && /Google Inc/.test(windowParams.navigator.vendor)) { | |
| 911 | - return 'Google Chrome'; | |
| 909 | + if ( | |
| 910 | + /Chrome/.test(windowParams.navigator.userAgent) && | |
| 911 | + /Google Inc/.test(windowParams.navigator.vendor) | |
| 912 | + ) { | |
| 913 | + return "Google Chrome"; | |
| 912 | 914 | } |
| 913 | - if (/360/.test(windowParams.navigator.userAgent) || /QIHU/.test(windowParams.navigator.userAgent)) { | |
| 914 | - return '360 Browser'; | |
| 915 | + if ( | |
| 916 | + /360/.test(windowParams.navigator.userAgent) || | |
| 917 | + /QIHU/.test(windowParams.navigator.userAgent) | |
| 918 | + ) { | |
| 919 | + return "360 Browser"; | |
| 915 | 920 | } |
| 916 | 921 | return "Blink"; // Assume it's Chrome, Safari, or an alternative Blink-based browser |
| 917 | 922 | } |
| ... | ... | @@ -920,15 +925,26 @@ export function paperPrint(paper) { |
| 920 | 925 | windowParams.close(); |
| 921 | 926 | } |
| 922 | 927 | function numberToChinese(num) { |
| 923 | - const chineseDigits = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"]; | |
| 928 | + const chineseDigits = [ | |
| 929 | + "零", | |
| 930 | + "一", | |
| 931 | + "二", | |
| 932 | + "三", | |
| 933 | + "四", | |
| 934 | + "五", | |
| 935 | + "六", | |
| 936 | + "七", | |
| 937 | + "八", | |
| 938 | + "九", | |
| 939 | + ]; | |
| 924 | 940 | const chineseUnits = ["", "十", "百", "千", "万", "亿"]; |
| 925 | 941 | |
| 926 | - let result = ''; | |
| 927 | - let unitPos = 0; // 单位的位置 | |
| 928 | - let zeroFlag = false; // 是否出现过零 | |
| 942 | + let result = ""; | |
| 943 | + let unitPos = 0; // 单位的位置 | |
| 944 | + let zeroFlag = false; // 是否出现过零 | |
| 929 | 945 | |
| 930 | 946 | if (num === 0) { |
| 931 | - return chineseDigits[0]; // 特殊情况,0 返回 "零" | |
| 947 | + return chineseDigits[0]; // 特殊情况,0 返回 "零" | |
| 932 | 948 | } |
| 933 | 949 | |
| 934 | 950 | // 处理数字,每次取一位并加上单位 |
| ... | ... | @@ -949,34 +965,34 @@ export function paperPrint(paper) { |
| 949 | 965 | } |
| 950 | 966 | |
| 951 | 967 | // 处理 '一十' 和 '一百' 等情况 |
| 952 | - if (result.startsWith('一十')) { | |
| 968 | + if (result.startsWith("一十")) { | |
| 953 | 969 | result = result.substring(1); // 去掉 '一',例如 '一十' -> '十' |
| 954 | 970 | } |
| 955 | 971 | |
| 956 | 972 | return result; |
| 957 | 973 | } |
| 958 | 974 | function htmlParseDom(html, getStyleScripts) { |
| 959 | - var tempDom = document.createElement('div'); | |
| 975 | + var tempDom = document.createElement("div"); | |
| 960 | 976 | tempDom.innerHTML = html; |
| 961 | - var doms = tempDom.querySelectorAll('p'); | |
| 977 | + var doms = tempDom.querySelectorAll("p"); | |
| 962 | 978 | if (getStyleScripts == true) { |
| 963 | - var styleDoms = tempDom.querySelectorAll('style'); | |
| 964 | - var scriptDoms = tempDom.querySelectorAll('script'); | |
| 979 | + var styleDoms = tempDom.querySelectorAll("style"); | |
| 980 | + var scriptDoms = tempDom.querySelectorAll("script"); | |
| 965 | 981 | return { |
| 966 | 982 | doms: doms, |
| 967 | 983 | styles: styleDoms, |
| 968 | - scripts: scriptDoms | |
| 969 | - } | |
| 984 | + scripts: scriptDoms, | |
| 985 | + }; | |
| 970 | 986 | } |
| 971 | - return { doms: doms } | |
| 987 | + return { doms: doms }; | |
| 972 | 988 | } |
| 973 | 989 | function generatePageParams() { |
| 974 | 990 | const totalHeightPx = Math.max( |
| 975 | 991 | printWin.document.documentElement.scrollHeight, // 整个文档高度 |
| 976 | - printWin.document.body.scrollHeight // Body 的高度 | |
| 992 | + printWin.document.body.scrollHeight // Body 的高度 | |
| 977 | 993 | ); |
| 978 | - const a4Box = printWin.document.createElement('div'); | |
| 979 | - a4Box.classList.add('altA4Box'); | |
| 994 | + const a4Box = printWin.document.createElement("div"); | |
| 995 | + a4Box.classList.add("altA4Box"); | |
| 980 | 996 | printWin.document.body.appendChild(a4Box); |
| 981 | 997 | const a4BoxHeightPx = a4Box.offsetHeight; |
| 982 | 998 | if (a4BoxHeightPx > 0) { |
| ... | ... | @@ -984,18 +1000,20 @@ export function paperPrint(paper) { |
| 984 | 1000 | var pages = Math.ceil(totalHeightPx / a4BoxHeightPx); |
| 985 | 1001 | if (pages > 2) pages += 1; |
| 986 | 1002 | for (var page = 0; page < pages; page++) { |
| 987 | - var pageFooteDiv = printWin.document.createElement('div'); | |
| 988 | - pageFooteDiv.classList.add('page-footer'); | |
| 989 | - pageFooteDiv.innerText = `${paperTitle} ${subjectName} 第${page + 1}页(共${pages}页)`; | |
| 990 | - pageFooteDiv.style.top = (page + 1) * a4BoxHeightPx + (page * 25) + 'px'; | |
| 1003 | + var pageFooteDiv = printWin.document.createElement("div"); | |
| 1004 | + pageFooteDiv.classList.add("page-footer"); | |
| 1005 | + pageFooteDiv.innerText = `${paperTitle} ${subjectName} 第${ | |
| 1006 | + page + 1 | |
| 1007 | + }页(共${pages}页)`; | |
| 1008 | + pageFooteDiv.style.top = (page + 1) * a4BoxHeightPx + page * 25 + "px"; | |
| 991 | 1009 | printWin.document.body.appendChild(pageFooteDiv); |
| 992 | 1010 | } |
| 993 | 1011 | } |
| 994 | 1012 | } |
| 995 | - // size: A4 portrait; | |
| 1013 | + // size: A4 portrait; | |
| 996 | 1014 | // size: A3 landscape; |
| 997 | 1015 | |
| 998 | - const style = printWin.document.createElement('style'); | |
| 1016 | + const style = printWin.document.createElement("style"); | |
| 999 | 1017 | style.innerHTML = ` |
| 1000 | 1018 | @media print |
| 1001 | 1019 | { |
| ... | ... | @@ -1112,56 +1130,58 @@ export function paperPrint(paper) { |
| 1112 | 1130 | |
| 1113 | 1131 | printWin.document.head.appendChild(style); |
| 1114 | 1132 | |
| 1115 | - const bodyBoxDom = printWin.document.createElement('div'); | |
| 1116 | - bodyBoxDom.classList.add('bodyBox'); | |
| 1133 | + const bodyBoxDom = printWin.document.createElement("div"); | |
| 1134 | + bodyBoxDom.classList.add("bodyBox"); | |
| 1117 | 1135 | |
| 1118 | - const titleBoxDom = printWin.document.createElement('div'); | |
| 1119 | - titleBoxDom.classList.add('title-header'); | |
| 1120 | - const titleDom = printWin.document.createElement('h3'); | |
| 1136 | + const titleBoxDom = printWin.document.createElement("div"); | |
| 1137 | + titleBoxDom.classList.add("title-header"); | |
| 1138 | + const titleDom = printWin.document.createElement("h3"); | |
| 1121 | 1139 | titleDom.innerText = paperTitle; |
| 1122 | - titleDom.classList.add('title-content'); | |
| 1123 | - const subjectDom = printWin.document.createElement('h2'); | |
| 1140 | + titleDom.classList.add("title-content"); | |
| 1141 | + const subjectDom = printWin.document.createElement("h2"); | |
| 1124 | 1142 | subjectDom.innerText = subjectName; |
| 1125 | - subjectDom.classList.add('title-content'); | |
| 1143 | + subjectDom.classList.add("title-content"); | |
| 1126 | 1144 | titleBoxDom.appendChild(titleDom); |
| 1127 | 1145 | titleBoxDom.appendChild(subjectDom); |
| 1128 | 1146 | bodyBoxDom.appendChild(titleBoxDom); |
| 1129 | 1147 | |
| 1130 | - const studentInputBoxDom = printWin.document.createElement('div'); | |
| 1131 | - studentInputBoxDom.classList.add('student-input'); | |
| 1132 | - const studentClassInputDom = printWin.document.createElement('span'); | |
| 1133 | - studentClassInputDom.innerHTML = '班级:________________'; | |
| 1134 | - const studentNameInputDom = printWin.document.createElement('span'); | |
| 1135 | - studentNameInputDom.innerHTML = '姓名:________________'; | |
| 1136 | - const studentNoInputDom = printWin.document.createElement('span'); | |
| 1137 | - studentNoInputDom.innerHTML = '学号:________________'; | |
| 1148 | + const studentInputBoxDom = printWin.document.createElement("div"); | |
| 1149 | + studentInputBoxDom.classList.add("student-input"); | |
| 1150 | + const studentClassInputDom = printWin.document.createElement("span"); | |
| 1151 | + studentClassInputDom.innerHTML = "班级:________________"; | |
| 1152 | + const studentNameInputDom = printWin.document.createElement("span"); | |
| 1153 | + studentNameInputDom.innerHTML = "姓名:________________"; | |
| 1154 | + const studentNoInputDom = printWin.document.createElement("span"); | |
| 1155 | + studentNoInputDom.innerHTML = "学号:________________"; | |
| 1138 | 1156 | studentInputBoxDom.appendChild(studentClassInputDom); |
| 1139 | 1157 | studentInputBoxDom.appendChild(studentNameInputDom); |
| 1140 | 1158 | studentInputBoxDom.appendChild(studentNoInputDom); |
| 1141 | 1159 | bodyBoxDom.appendChild(studentInputBoxDom); |
| 1142 | 1160 | |
| 1143 | - const tableDom = printWin.document.createElement('table'); | |
| 1144 | - const theadDom = printWin.document.createElement('thead'); | |
| 1145 | - const theadTrDom = printWin.document.createElement('tr'); | |
| 1146 | - theadTrDom.appendChild(printWin.document.createElement('th')); | |
| 1147 | - theadTrDom.appendChild(printWin.document.createElement('th')); | |
| 1148 | - theadTrDom.appendChild(printWin.document.createElement('th')); | |
| 1161 | + const tableDom = printWin.document.createElement("table"); | |
| 1162 | + const theadDom = printWin.document.createElement("thead"); | |
| 1163 | + const theadTrDom = printWin.document.createElement("tr"); | |
| 1164 | + theadTrDom.appendChild(printWin.document.createElement("th")); | |
| 1165 | + theadTrDom.appendChild(printWin.document.createElement("th")); | |
| 1166 | + theadTrDom.appendChild(printWin.document.createElement("th")); | |
| 1149 | 1167 | theadDom.appendChild(theadTrDom); |
| 1150 | 1168 | tableDom.appendChild(theadDom); |
| 1151 | 1169 | |
| 1152 | - const tbodyDom = printWin.document.createElement('tbody'); | |
| 1170 | + const tbodyDom = printWin.document.createElement("tbody"); | |
| 1153 | 1171 | |
| 1154 | 1172 | for (var iof = 0; iof < paperQuestions.length; iof++) { |
| 1155 | 1173 | var item = paperQuestions[iof]; |
| 1156 | 1174 | if (!item || !item.subQuestions) continue; |
| 1157 | 1175 | |
| 1158 | - const tbodyTrDom = printWin.document.createElement('tr'); | |
| 1159 | - const tbodyLeftAltTdDom = printWin.document.createElement('td'); | |
| 1160 | - const tbodyContentTdDom = printWin.document.createElement('td'); | |
| 1161 | - const tbodyRightAltTdDom = printWin.document.createElement('td'); | |
| 1176 | + const tbodyTrDom = printWin.document.createElement("tr"); | |
| 1177 | + const tbodyLeftAltTdDom = printWin.document.createElement("td"); | |
| 1178 | + const tbodyContentTdDom = printWin.document.createElement("td"); | |
| 1179 | + const tbodyRightAltTdDom = printWin.document.createElement("td"); | |
| 1162 | 1180 | |
| 1163 | - const questionTitleDom = printWin.document.createElement('div'); | |
| 1164 | - questionTitleDom.innerText = `${numberToChinese(iof + 1)}、${item.questionTitle}(本节共${item.subQuestions.length}小题,共${item.score}分)`; | |
| 1181 | + const questionTitleDom = printWin.document.createElement("div"); | |
| 1182 | + questionTitleDom.innerText = `${numberToChinese(iof + 1)}、${ | |
| 1183 | + item.questionTitle | |
| 1184 | + }(本节共${item.subQuestions.length}小题,共${item.score}分)`; | |
| 1165 | 1185 | |
| 1166 | 1186 | tbodyContentTdDom.appendChild(questionTitleDom); |
| 1167 | 1187 | tbodyTrDom.appendChild(tbodyLeftAltTdDom); |
| ... | ... | @@ -1170,12 +1190,12 @@ export function paperPrint(paper) { |
| 1170 | 1190 | tbodyDom.appendChild(tbodyTrDom); |
| 1171 | 1191 | |
| 1172 | 1192 | for (var idof = 0; idof < item.subQuestions.length; idof++) { |
| 1173 | - const qTbodyTrDom = printWin.document.createElement('tr'); | |
| 1174 | - const qTbodyLeftAltTdDom = printWin.document.createElement('td'); | |
| 1175 | - const qTbodyContentTdDom = printWin.document.createElement('td'); | |
| 1176 | - const qTbodyRightAltTdDom = printWin.document.createElement('td'); | |
| 1193 | + const qTbodyTrDom = printWin.document.createElement("tr"); | |
| 1194 | + const qTbodyLeftAltTdDom = printWin.document.createElement("td"); | |
| 1195 | + const qTbodyContentTdDom = printWin.document.createElement("td"); | |
| 1196 | + const qTbodyRightAltTdDom = printWin.document.createElement("td"); | |
| 1177 | 1197 | |
| 1178 | - const questionDom = printWin.document.createElement('div'); | |
| 1198 | + const questionDom = printWin.document.createElement("div"); | |
| 1179 | 1199 | var subItem = item.subQuestions[idof]; |
| 1180 | 1200 | var screenshotHtml = fetchHTML(subItem.screenshot); |
| 1181 | 1201 | var getStyleScripts = iof == 0 && idof == 0; |
| ... | ... | @@ -1196,16 +1216,16 @@ export function paperPrint(paper) { |
| 1196 | 1216 | tableDom.appendChild(tbodyDom); |
| 1197 | 1217 | bodyBoxDom.appendChild(tableDom); |
| 1198 | 1218 | |
| 1199 | - const tfootDom = printWin.document.createElement('tfoot'); | |
| 1200 | - const tfootTrDom = printWin.document.createElement('tr'); | |
| 1201 | - tfootTrDom.appendChild(printWin.document.createElement('td')); | |
| 1202 | - tfootTrDom.appendChild(printWin.document.createElement('td')); | |
| 1203 | - tfootTrDom.appendChild(printWin.document.createElement('td')); | |
| 1219 | + const tfootDom = printWin.document.createElement("tfoot"); | |
| 1220 | + const tfootTrDom = printWin.document.createElement("tr"); | |
| 1221 | + tfootTrDom.appendChild(printWin.document.createElement("td")); | |
| 1222 | + tfootTrDom.appendChild(printWin.document.createElement("td")); | |
| 1223 | + tfootTrDom.appendChild(printWin.document.createElement("td")); | |
| 1204 | 1224 | tfootDom.appendChild(tfootTrDom); |
| 1205 | 1225 | tableDom.appendChild(tfootDom); |
| 1206 | 1226 | printWin.document.body.appendChild(bodyBoxDom); |
| 1207 | 1227 | // generatePageParams(); |
| 1208 | - const lastImage = printWin.document.querySelector('img:last-child'); | |
| 1228 | + const lastImage = printWin.document.querySelector("img:last-child"); | |
| 1209 | 1229 | if (lastImage) { |
| 1210 | 1230 | if (lastImage.complete) windowPrint(printWin); |
| 1211 | 1231 | lastImage.onload = () => windowPrint(printWin); |
| ... | ... | @@ -1225,9 +1245,7 @@ export function tablePrint(options) { |
| 1225 | 1245 | var diffStNumber = options.diffStNumber ?? 0; |
| 1226 | 1246 | let divs = document.getElementById(id); |
| 1227 | 1247 | let awin = window.open("中天易教", "_blank", ""); |
| 1228 | - awin.document.getElementsByTagName( | |
| 1229 | - "head" | |
| 1230 | - )[0].innerHTML = `<style> | |
| 1248 | + awin.document.getElementsByTagName("head")[0].innerHTML = `<style> | |
| 1231 | 1249 | @media print { |
| 1232 | 1250 | @page { |
| 1233 | 1251 | size: A4 portrait; |
| ... | ... | @@ -1659,8 +1677,11 @@ function getDateRange() { |
| 1659 | 1677 | const currentMonth = currentDate.getMonth() + 1; // getMonth() 返回的是 0-11 |
| 1660 | 1678 | |
| 1661 | 1679 | let startDate, endDate; |
| 1662 | - | |
| 1663 | - if (currentMonth >= 2 && currentMonth <= 7) { | |
| 1680 | + if (currentMonth == 1) { | |
| 1681 | + // 如果是1月直接重新返回 | |
| 1682 | + startDate = `${currentYear - 1}-08-01`; | |
| 1683 | + endDate = `${currentYear}-01-31`; // 下一年的 1 月 31 日 | |
| 1684 | + } else if (currentMonth >= 2 && currentMonth <= 7) { | |
| 1664 | 1685 | // 在 2 月到 7 月之间 |
| 1665 | 1686 | startDate = `${currentYear}-02-01`; |
| 1666 | 1687 | endDate = `${currentYear}-07-31`; | ... | ... |