Blame view

src/utils/index.js 39.9 KB
13b58a42   梁保满   备题组卷部分前端页面基本完成
1
  // import CryptoJS from "crypto-js"
db11048f   阿宝   设备状态,学校管理
2
  import { JSEncrypt } from "jsencrypt";
191d5bfa   梁保满   学生管理、基站管理下载名称设置,上...
3
  import service from "@/api/axios";
c1b532ad   梁保满   权限配置,路由基础设置
4
  
db11048f   阿宝   设备状态,学校管理
5
6
  const encryptKey = "WfJTKO9S4eLkrPz2JKrAnzdb";
  const encryptIV = "D076D35C";
13b58a42   梁保满   备题组卷部分前端页面基本完成
7
8
9
10
11
  /**
   * 登录密码加密,公钥直接写死在方法里
   * @param data 待加密数据
   * @returns 加密结果
   */
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
12
  export function encryptLoginPassword(data) {
db11048f   阿宝   设备状态,学校管理
13
14
    const secret =
      "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjh2ei17z5k2r4VzbqoSCE6RmYzWySJTgVQYulgfVM+vqcDoUE4cFB4XCFA2lHWjjpsuJP1EtwKlvUgxo5okr3x/a88o8eERxBynnVQZbEYpKteW5aqSEb/g1yPLWnKV88b/ED445ITYbZZuInRo5lkCvd6QEjL6d2Fch6mEo5awYXC4/S4BJf9YlYRhGzR7wpiXCLvyBHQ4iSIIDNpmrPBPQzGP0rx09aDu54kz/42CR6SX2OqXSi4ZoieqkPFl/iuX4RoD/NKKR+haDn1UzoD3k1WzHSTBFFs27rxRpxfBUZzfXQeskgKyw/Slcl3jUFizczsY4CLgTRrfey48Q6QIDAQAB";
13b58a42   梁保满   备题组卷部分前端页面基本完成
15
16
17
18
19
20
21
22
23
    // 新建JSEncrypt对象
    let encryptor = new JSEncrypt();
    // 设置公钥
    encryptor.setPublicKey(secret);
    // 加密数据
    return encryptor.encrypt(data);
  }
  
  /**
f45b3c05   LH_PC   云平台新UI界面
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
   * 设置本周,本月,本季度
   * @param index 规则值
   * @returns startDay=开始时间,endDay=结束时间
   */
  export function setDateRules(type) {
    var that = {};
    let aYear = new Date().getFullYear();
    let aMonth = new Date().getMonth() + 1;
  
    that.day = "";
    that.startDay = "";
    that.endDay = "";
  
    switch (type) {
      case "onDay":
        that.day = formatDate(new Date(), "yyyy-MM-dd");
        that.startDay = that.day;
        that.endDay = that.day;
        break;
      case "onWeek":
        let day = new Date().getDay();
        if (day == 0) {
          //中国式星期天是一周的最后一天
          day = 7;
        }
        day--;
        let aTime = new Date().getTime() - 24 * 60 * 60 * 1000 * day;
        that.startDay = formatDate(new Date(aTime), "yyyy-MM-dd");
        that.endDay = formatDate(new Date(), "yyyy-MM-dd");
        break;
      case "onMonth":
        aMonth = aMonth < 10 ? "0" + aMonth : aMonth;
        that.startDay = `${aYear}-${aMonth}-01`;
        that.endDay = formatDate(new Date(), "yyyy-MM-dd");
        break;
      case "onQuarter":
        if (aMonth > 0 && aMonth < 4) {
          aMonth = "1";
        } else if (aMonth > 3 && aMonth < 7) {
          aMonth = "4";
        } else if (aMonth > 6 && aMonth < 10) {
          aMonth = "7";
        } else {
          aMonth = "10";
        }
  
        aMonth = aMonth < 10 ? "0" + aMonth : aMonth;
        that.startDay = `${aYear}-${aMonth}-01`;
        that.endDay = formatDate(new Date(), "yyyy-MM-dd");
        break;
    }
  
    return that;
  }
  
  /**
db11048f   阿宝   设备状态,学校管理
80
81
82
83
84
   * 对称加密
   * @param secret:加密公钥
   * @param data 待加密数据
   * @returns 加密结果
   */
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
85
  export function encryptData(secret, data) {
13b58a42   梁保满   备题组卷部分前端页面基本完成
86
87
88
89
90
91
92
    // 新建JSEncrypt对象
    let encryptor = new JSEncrypt();
    // 设置公钥
    encryptor.setPublicKey(secret);
    // 加密数据
    return encryptor.encrypt(data);
  }
c1b532ad   梁保满   权限配置,路由基础设置
93
94
  
  // 深度复制
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
95
  export function deepClone(obj) {
db11048f   阿宝   设备状态,学校管理
96
    let result = Array.isArray(obj) ? [] : {};
c1b532ad   梁保满   权限配置,路由基础设置
97
98
99
    for (let key in obj) {
      if (obj.hasOwnProperty(key)) {
        if (typeof obj[key] === "object") {
db11048f   阿宝   设备状态,学校管理
100
          result[key] = deepClone(obj[key]);
c1b532ad   梁保满   权限配置,路由基础设置
101
        } else {
db11048f   阿宝   设备状态,学校管理
102
          result[key] = obj[key];
c1b532ad   梁保满   权限配置,路由基础设置
103
104
105
        }
      }
    }
db11048f   阿宝   设备状态,学校管理
106
    return result;
c1b532ad   梁保满   权限配置,路由基础设置
107
108
  }
  
ef16e57e   LH_PC   fix:前端版本迭代
109
110
  export function getKnowledge(knowledgeParam) {
    if (!knowledgeParam) return "";
6bca489d   LH_PC   云平台二期UI
111
  
ef16e57e   LH_PC   fix:前端版本迭代
112
    var knowledge = knowledgeParam + "";
6bca489d   LH_PC   云平台二期UI
113
  
ef16e57e   LH_PC   fix:前端版本迭代
114
    var knowledges = knowledge.split(',');
6bca489d   LH_PC   云平台二期UI
115
  
ef16e57e   LH_PC   fix:前端版本迭代
116
    var resultArray = [];
6bca489d   LH_PC   云平台二期UI
117
  
ef16e57e   LH_PC   fix:前端版本迭代
118
119
    knowledges.forEach(ksplit => {
      var ss = ksplit.split('#').filter(dd => dd.length >= 1);
6bca489d   LH_PC   云平台二期UI
120
      if (ss.length > 0) {
ef16e57e   LH_PC   fix:前端版本迭代
121
        resultArray.push(ss[ss.length - 1]);
6bca489d   LH_PC   云平台二期UI
122
123
124
      }
    })
  
ef16e57e   LH_PC   fix:前端版本迭代
125
    return resultArray.join(';');
6bca489d   LH_PC   云平台二期UI
126
127
  }
  
13b58a42   梁保满   备题组卷部分前端页面基本完成
128
129
130
131
132
133
134
135
136
137
138
  // // 3DES加密
  // export function desEncrypt (str, key = encryptKey, iv = encryptIV) {
  //   var cryptoKey = CryptoJS.enc.Utf8.parse(key)
  //   var cryptoIv = CryptoJS.enc.Utf8.parse(iv.substr(0, 8))
  //   var encodeStr = CryptoJS.TripleDES.encrypt(str, cryptoKey, {
  //     iv: cryptoIv,
  //     mode: CryptoJS.mode.CBC,
  //     padding: CryptoJS.pad.Pkcs7
  //   })
  //   return encodeStr.toString()
  // }
c1b532ad   梁保满   权限配置,路由基础设置
139
  
13b58a42   梁保满   备题组卷部分前端页面基本完成
140
141
142
143
144
145
146
147
148
149
150
  // // 3DES解密
  // export function desDecrypt (str, key = encryptKey, iv = encryptIV) {
  //   var cryptoKey = CryptoJS.enc.Utf8.parse(key)
  //   var cryptoIv = CryptoJS.enc.Utf8.parse(iv.substr(0, 8))
  //   var decryptStr = CryptoJS.TripleDES.decrypt(str, cryptoKey, {
  //     iv: cryptoIv,
  //     mode: CryptoJS.mode.CBC,
  //     padding: CryptoJS.pad.Pkcs7
  //   })
  //   return decryptStr.toString(CryptoJS.enc.Utf8)
  // }
c1b532ad   梁保满   权限配置,路由基础设置
151
152
  
  // 随机生成由字母+数字的字符串
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
153
  export function randomWord(randomFlag, min, max) {
c1b532ad   梁保满   权限配置,路由基础设置
154
155
156
    // randomFlag: Boolean 是否随机个数
    // min 最少个数
    // max 最大个数
db11048f   阿宝   设备状态,学校管理
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    var str = "";
    var range = min;
    var arr = [
      "0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "8",
      "9",
      "a",
      "b",
      "c",
      "d",
      "e",
      "f",
      "g",
      "h",
      "i",
      "j",
      "k",
      "l",
      "m",
      "n",
      "o",
      "p",
      "q",
      "r",
      "s",
      "t",
      "u",
      "v",
      "w",
      "x",
      "y",
      "z",
      "A",
      "B",
      "C",
      "D",
      "E",
      "F",
      "G",
      "H",
      "I",
      "J",
      "K",
      "L",
      "M",
      "N",
      "O",
      "P",
      "Q",
      "R",
      "S",
      "T",
      "U",
      "V",
      "W",
      "X",
      "Y",
      "Z",
    ];
c1b532ad   梁保满   权限配置,路由基础设置
223
224
    // 随机产生
    if (randomFlag) {
db11048f   阿宝   设备状态,学校管理
225
      range = Math.round(Math.random() * (max - min)) + min;
c1b532ad   梁保满   权限配置,路由基础设置
226
    }
db11048f   阿宝   设备状态,学校管理
227
    var pos = "";
c1b532ad   梁保满   权限配置,路由基础设置
228
    for (var i = 0; i < range; i++) {
db11048f   阿宝   设备状态,学校管理
229
230
      pos = Math.round(Math.random() * (arr.length - 1));
      str += arr[pos];
c1b532ad   梁保满   权限配置,路由基础设置
231
    }
db11048f   阿宝   设备状态,学校管理
232
    return str;
c1b532ad   梁保满   权限配置,路由基础设置
233
234
235
  }
  
  // 判断数组中是否存在相同值
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
236
  export function hasRepeatValue(arr, key = null) {
db11048f   阿宝   设备状态,学校管理
237
    if (key) arr = arr.map((d) => d[key]);
c1b532ad   梁保满   权限配置,路由基础设置
238
239
240
    if (arr.length) {
      let nameNum = arr.reduce((pre, cur) => {
        if (cur in pre) {
db11048f   阿宝   设备状态,学校管理
241
          pre[cur]++;
c1b532ad   梁保满   权限配置,路由基础设置
242
        } else {
db11048f   阿宝   设备状态,学校管理
243
          pre[cur] = 1;
c1b532ad   梁保满   权限配置,路由基础设置
244
        }
db11048f   阿宝   设备状态,学校管理
245
246
247
        return pre;
      }, {});
      return Object.values(nameNum).findIndex((d) => d > 1) < 0;
c1b532ad   梁保满   权限配置,路由基础设置
248
    }
db11048f   阿宝   设备状态,学校管理
249
    return true;
c1b532ad   梁保满   权限配置,路由基础设置
250
251
252
  }
  
  // 获取cookie值
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
253
  export function getCookie(name, defaultValue) {
db11048f   阿宝   设备状态,学校管理
254
255
256
257
    const result = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    return result[0] === document.cookie.match(result[1])
      ? unescape(result[0][2])
      : defaultValue;
c1b532ad   梁保满   权限配置,路由基础设置
258
259
  }
  
13b58a42   梁保满   备题组卷部分前端页面基本完成
260
261
262
  /**
   * base64转化unicode
   */
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
263
  export function b64DecodeUnicode(str) {
13b58a42   梁保满   备题组卷部分前端页面基本完成
264
265
266
    let uni;
    try {
      // atob 经过 base-64 编码的字符串进行解码
db11048f   阿宝   设备状态,学校管理
267
268
269
270
271
272
273
274
      uni = decodeURIComponent(
        atob(str)
          .split("")
          .map(function (c) {
            return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
          })
          .join("")
      );
e371f2dc   梁保满   软件下载,学校,班级老师等报表导入...
275
    } catch (e) { }
13b58a42   梁保满   备题组卷部分前端页面基本完成
276
277
278
    return uni;
  }
  
c1b532ad   梁保满   权限配置,路由基础设置
279
  // base64ToFile
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
280
  export function base64ToFile(base64Data, tempfilename, contentType) {
db11048f   阿宝   设备状态,学校管理
281
282
283
284
285
286
    contentType = contentType || "";
    var sliceSize = 1024;
    var byteCharacters = atob(base64Data);
    var bytesLength = byteCharacters.length;
    var slicesCount = Math.ceil(bytesLength / sliceSize);
    var byteArrays = new Array(slicesCount);
c1b532ad   梁保满   权限配置,路由基础设置
287
288
  
    for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
db11048f   阿宝   设备状态,学校管理
289
290
      var begin = sliceIndex * sliceSize;
      var end = Math.min(begin + sliceSize, bytesLength);
c1b532ad   梁保满   权限配置,路由基础设置
291
  
db11048f   阿宝   设备状态,学校管理
292
      var bytes = new Array(end - begin);
c1b532ad   梁保满   权限配置,路由基础设置
293
      for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
db11048f   阿宝   设备状态,学校管理
294
        bytes[i] = byteCharacters[offset].charCodeAt(0);
c1b532ad   梁保满   权限配置,路由基础设置
295
      }
db11048f   阿宝   设备状态,学校管理
296
      byteArrays[sliceIndex] = new Uint8Array(bytes);
c1b532ad   梁保满   权限配置,路由基础设置
297
    }
db11048f   阿宝   设备状态,学校管理
298
299
    var file = new File(byteArrays, tempfilename, { type: contentType });
    return file;
c1b532ad   梁保满   权限配置,路由基础设置
300
301
302
  }
  
  // 将base64转换为文件
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
303
  export function dataURLtoFile(dataurl, filename) {
db11048f   阿宝   设备状态,学校管理
304
305
306
307
308
    var arr = dataurl.split(",");
    var mime = arr[0].match(/:(.*?);/)[1];
    var bstr = atob(arr[1]);
    var n = bstr.length;
    var u8arr = new Uint8Array(n);
c1b532ad   梁保满   权限配置,路由基础设置
309
    while (n--) {
db11048f   阿宝   设备状态,学校管理
310
      u8arr[n] = bstr.charCodeAt(n);
c1b532ad   梁保满   权限配置,路由基础设置
311
    }
db11048f   阿宝   设备状态,学校管理
312
    return new File([u8arr], filename, { type: mime });
c1b532ad   梁保满   权限配置,路由基础设置
313
314
315
  }
  
  // 将图片转换为Base64
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
316
  export function getImgToBase64(url, callback, outputFormat) {
db11048f   阿宝   设备状态,学校管理
317
318
319
320
    var canvas = document.createElement("canvas");
    var ctx = canvas.getContext("2d");
    var img = new Image();
    img.crossOrigin = "Anonymous";
c1b532ad   梁保满   权限配置,路由基础设置
321
    img.onload = function () {
db11048f   阿宝   设备状态,学校管理
322
323
324
325
326
327
328
329
      canvas.height = img.height;
      canvas.width = img.width;
      ctx.drawImage(img, 0, 0);
      var dataURL = canvas.toDataURL(outputFormat || "image/png");
      callback(dataURL);
      canvas = null;
    };
    img.src = url;
c1b532ad   梁保满   权限配置,路由基础设置
330
331
332
  }
  
  // 转换级联下拉数据
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
333
  export function loopOptions(list, option = {}) {
c1b532ad   梁保满   权限配置,路由基础设置
334
335
336
337
    option = {
      value: "id",
      label: "name",
      children: "children",
db11048f   阿宝   设备状态,学校管理
338
339
      ...option,
    };
c1b532ad   梁保满   权限配置,路由基础设置
340
341
    if (list instanceof Array && list.length) {
      return list.map((d, i) => {
db11048f   阿宝   设备状态,学校管理
342
343
        d.value = d[option.value] || i + 1;
        d.label = d[option.label];
c1b532ad   梁保满   权限配置,路由基础设置
344
        if (d[option.children]) {
db11048f   阿宝   设备状态,学校管理
345
          d[option.children] = loopOptions(d[option.children], option);
c1b532ad   梁保满   权限配置,路由基础设置
346
        }
db11048f   阿宝   设备状态,学校管理
347
348
        return d;
      });
c1b532ad   梁保满   权限配置,路由基础设置
349
    }
db11048f   阿宝   设备状态,学校管理
350
    return [];
c1b532ad   梁保满   权限配置,路由基础设置
351
352
353
  }
  
  // 通过Id获取级联数据id数组
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
354
  export function getTreeIds(tree, currentId, key = "id") {
db11048f   阿宝   设备状态,学校管理
355
356
    let parent = {};
    let pid = {};
c1b532ad   梁保满   权限配置,路由基础设置
357
358
359
    const loop = (list, level) => {
      if (list instanceof Array && list.length) {
        for (let index = 0; index < list.length; index++) {
db11048f   阿宝   设备状态,学校管理
360
361
          const d = list[index];
          parent[level] = d.id;
c1b532ad   梁保满   权限配置,路由基础设置
362
363
          if (d[key] === currentId) {
            for (let idx = 1; idx <= level; idx++) {
db11048f   阿宝   设备状态,学校管理
364
              pid[idx] = parent[idx];
c1b532ad   梁保满   权限配置,路由基础设置
365
            }
db11048f   阿宝   设备状态,学校管理
366
            break;
c1b532ad   梁保满   权限配置,路由基础设置
367
          } else if (d.children) {
db11048f   阿宝   设备状态,学校管理
368
            loop(d.children, level + 1);
c1b532ad   梁保满   权限配置,路由基础设置
369
370
371
          }
        }
      }
db11048f   阿宝   设备状态,学校管理
372
373
374
375
376
377
378
379
380
    };
    loop(tree, 1);
    let result = [];
    Object.keys(pid)
      .sort((a, b) => a - b)
      .forEach((k) => {
        result.push(pid[k]);
      });
    return result;
c1b532ad   梁保满   权限配置,路由基础设置
381
382
  }
  
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
  /*
   * 格式化时间
   * yyyy-MM-dd hh:mm:ss
   * */
  export function formatDate(date, fmt) {
    if (!date || date == null) return null;
    if (isNaN(date)) {
      return date;
    }
    let format = fmt || "yyyy-MM-dd hh:mm:ss";
  
    let dates = new Date(Number(date));
  
    let formatObj = {
      y: dates.getFullYear(),
      M: dates.getMonth() + 1,
      d: dates.getDate(),
      h: dates.getHours(),
      m: dates.getMinutes(),
      s: dates.getSeconds(),
    };
    let time_str = format.replace(/(y|M|d|h|m|s)+/g, (result, key) => {
      let value = formatObj[key];
      if (result.length > 0 && value < 10) {
        value = "0" + value;
      }
      return value || 0;
    });
    return time_str;
c1b532ad   梁保满   权限配置,路由基础设置
412
413
  }
  
06869a45   LH_PC   fix:修改测验时长显示不对的逻辑
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
  export function formatTimeWithHours(seconds) {
    if (!seconds || seconds <= 0) return "0秒";
    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const sec = seconds % 60;
  
    // 根据是否有小时动态调整格式
    var ret = '';
    if (hours > 0) {
      ret += hours + "小时";
    }
    if (minutes > 0) {
      ret += minutes + "分钟";
    }
    if (sec > 0) {
      ret += sec + "秒";
    }
    return ret;
  }
  
c1b532ad   梁保满   权限配置,路由基础设置
434
  // 获取日期时间戳
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
435
  export function getTime(dayNum) {
db11048f   阿宝   设备状态,学校管理
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
    var myDate = new Date();
    var lw = new Date(myDate - 1000 * 60 * 60 * 24 * dayNum); // 最后一个数字多少天前的意思
    var lastY = lw.getFullYear();
    var lastM = lw.getMonth() + 1;
    var lastD = lw.getDate();
    var startdate =
      lastY +
      "-" +
      (lastM < 10 ? "0" + lastM : lastM) +
      "-" +
      (lastD < 10 ? "0" + lastD : lastD);
    var b = startdate.split(/\D/);
    var date = new Date(b[0], b[1] - 1, b[2]);
    var time = date.getTime();
    return time;
c1b532ad   梁保满   权限配置,路由基础设置
451
452
453
  }
  
  // 获取几天之前日期
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
454
  export function getData(dayNum) {
db11048f   阿宝   设备状态,学校管理
455
456
457
458
459
460
461
462
463
464
465
466
    var myDate = new Date();
    var lw = new Date(myDate - 1000 * 60 * 60 * 24 * dayNum); // 最后一个数字多少天前的意思
    var lastY = lw.getFullYear();
    var lastM = lw.getMonth() + 1;
    var lastD = lw.getDate();
    var startdate =
      lastY +
      "-" +
      (lastM < 10 ? "0" + lastM : lastM) +
      "-" +
      (lastD < 10 ? "0" + lastD : lastD);
    return startdate;
c1b532ad   梁保满   权限配置,路由基础设置
467
468
469
  }
  
  // 日期转换时间戳
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
470
  export function getNewTime(dayNum) {
db11048f   阿宝   设备状态,学校管理
471
472
473
474
    var b = dayNum.split(/\D/);
    var date = new Date(b[0], b[1] - 1, b[2]);
    var time = date.getTime();
    return time;
c1b532ad   梁保满   权限配置,路由基础设置
475
  }
13b58a42   梁保满   备题组卷部分前端页面基本完成
476
477
478
479
480
481
482
483
484
485
486
487
488
  
  /*
   * 获取URL参数
   *
   * */
  export function getURLParams(variable) {
    let str = window.location.href.split("?")[1];
    if (!str) return null;
    let ar = str.split("&");
    let obj = {};
    let data;
    for (var i = 0; i < ar.length; i++) {
      var pair = ar[i].split("=");
db11048f   阿宝   设备状态,学校管理
489
      pair[1] = decodeURIComponent(pair[1]);
13b58a42   梁保满   备题组卷部分前端页面基本完成
490
491
  
      if (pair[0] == variable) {
db11048f   阿宝   设备状态,学校管理
492
493
        data = pair[1];
        return pair[1];
13b58a42   梁保满   备题组卷部分前端页面基本完成
494
495
      }
      if (pair[0]) {
db11048f   阿宝   设备状态,学校管理
496
        obj[pair[0]] = pair[1];
13b58a42   梁保满   备题组卷部分前端页面基本完成
497
498
      }
    }
db11048f   阿宝   设备状态,学校管理
499
    return variable ? data : obj;
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
500
501
502
503
504
505
506
507
508
509
  }
  
  /**
   * 校验答案
   * @param {*} s 源字符串
   * @param {*} questionType 题型,2单选 3多选
   * @param {*} optionCount 选项数目
   * @param {*} questionCount 题目数目
   */
  function filtterChar(s, b, optionCount) {
ec6394d1   梁保满   v1.3.1。细节调整
510
    const ms = "ABCDEFGHIJ";
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
511
512
513
    let rs = "";
    for (let i = 0; i < s.length; i++) {
      let c = s[i];
db11048f   阿宝   设备状态,学校管理
514
      if (c == "," || c == " " || c == ",") {
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
515
516
517
        if (!b) {
          continue;
        }
db11048f   阿宝   设备状态,学校管理
518
519
        c = ",";
      } else if (c < "A" || c >= ms[optionCount]) {
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
520
521
522
523
524
525
526
527
        continue;
      }
      rs += c;
    }
    return rs;
  }
  
  function removeDup(s) {
ec6394d1   梁保满   v1.3.1。细节调整
528
    const ms = "ABCDEFGHIJ";
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
529
530
531
532
533
534
535
536
    let rs = "";
    for (let i = 0; i < ms.length; i++) {
      if (s.indexOf(ms[i]) >= 0) {
        rs += ms[i];
      }
    }
    return rs;
  }
db11048f   阿宝   设备状态,学校管理
537
538
539
540
541
542
  export function checkAnswer(
    s,
    questionType,
    optionCount = 4,
    questionCount = 1
  ) {
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
543
544
545
546
547
548
    if (optionCount > 10 || questionCount < 1) {
      return null;
    }
    let pre = s;
    s = s.toUpperCase();
    s = filtterChar(s, questionType == 3 && questionCount > 1, optionCount);
db11048f   阿宝   设备状态,学校管理
549
550
    if (questionType == 2) {
      //单选
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
551
      if (s.length > questionCount) {
11a4e518   梁保满   背题组卷修改答案设置,即使测随堂问...
552
        s = s.substring(0, questionCount);
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
553
      }
db11048f   阿宝   设备状态,学校管理
554
555
    } else if (questionType == 3) {
      //多选
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
556
557
558
559
560
561
562
563
564
565
      //允许逗号
      let ss = s.split(",");
      let len = questionCount;
      if (len > ss.length) {
        len = ss.length;
      }
      let rs = "";
      for (let i = 0; i < len; i++) {
        rs += removeDup(ss[i]);
        if (i < len - 1) {
db11048f   阿宝   设备状态,学校管理
566
          rs += ",";
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
567
568
569
        }
      }
      s = rs;
db11048f   阿宝   设备状态,学校管理
570
    } else {
b769660c   梁保满   备课组题细节调整,随堂问列表页面开发完成
571
572
573
574
      return null;
    }
    return s;
  }
db11048f   阿宝   设备状态,学校管理
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
  
  export function downloadFile(fileName, files) {
    if (typeof window.navigator.msSaveBlob !== "undefined") {
      window.navigator.msSaveBlob(files, fileName);
    } else {
      let URL = window.URL || window.webkitURL;
      let objectUrl;
      if (files instanceof Blob) {
        objectUrl = URL.createObjectURL(files);
      } else {
        objectUrl = files;
      }
      const a = document.createElement("a");
      if (typeof a.download === "undefined") {
        window.location = objectUrl;
      } else {
        a.href = objectUrl;
        a.download = fileName;
        document.body.appendChild(a);
        a.click();
        a.remove();
      }
    }
  }
  // 获取网络URL的blob,返回一个promise
  export function getBlob(url) {
    return new Promise((resolve) => {
      resolve(
        service({
          url: url,
          withCredentials: true,
          method: "get",
          responseType: "blob",
        })
      );
    });
  }
d3943e0d   LH_PC   feat:错题打印
612
613
614
615
616
617
618
619
620
621
622
  export function fetchHTML(url) {
    return new Promise((resolve) => {
      resolve(
        service({
          url: url,
          withCredentials: false,
          method: "get"
        })
      );
    });
  }
db11048f   阿宝   设备状态,学校管理
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
  /**
   * 打包压缩下载
   */
  export function compressAndDown(arr, fileName) {
    const zip = new JSZip();
    const promiseArr = [];
    arr.forEach((item) => {
      const promise = getBlob(item.reportPath).then((res) => {
        const fileName = item.testName;
        let sIdx = item.reportPath.lastIndexOf(".");
        const fileType = item.reportPath.substring(sIdx);
        zip.file(`${fileName}${fileType}`, res, { binary: true });
      });
      promiseArr.push(promise);
    });
    Promise.all(promiseArr).then(() => {
      zip
        .generateAsync({
          type: "blob",
          compression: "DEFLATE",
          compressionOptions: {
            level: 9,
          },
        })
        .then((res) => {
          FileSave.saveAs(res, fileName ? fileName : "报表.zip");
        });
    });
  }
  
  /**
   * 班级格式化为三级列表 学段-年级-班级
   * @param {*} data
   * @returns
   */
  function setSectionName(num) {
    let txt = "";
    switch (num) {
      case 1:
        txt = "小学";
        break;
      case 2:
        txt = "中学";
        break;
      case 3:
        txt = "高中";
        break;
      case 4:
        txt = "大学";
        break;
    }
    return txt;
  }
e371f2dc   梁保满   软件下载,学校,班级老师等报表导入...
676
  export function setGradeName(num) {
db11048f   阿宝   设备状态,学校管理
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
    let txt = "";
    switch (num) {
      case 1:
        txt = "一年级";
        break;
      case 2:
        txt = "二年级";
        break;
      case 3:
        txt = "三年级";
        break;
      case 4:
        txt = "四年级";
        break;
      case 5:
        txt = "五年级";
        break;
      case 6:
        txt = "六年级";
        break;
      case 7:
        txt = "初一";
        break;
      case 8:
        txt = "初二";
        break;
      case 9:
        txt = "初三";
        break;
      case 10:
        txt = "高一";
        break;
      case 11:
        txt = "高二";
        break;
      case 12:
        txt = "高三";
        break;
      case 13:
        txt = "大一";
        break;
      case 14:
        txt = "大二";
        break;
      case 15:
        txt = "大三";
        break;
      case 16:
        txt = "大四";
        break;
0ca11cc2   梁保满   学段参数调整,发卡记录类型增加
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
      case 51:
        txt = "一年级";
        break;
      case 52:
        txt = "二年级";
        break;
      case 53:
        txt = "三年级";
        break;
      case 54:
        txt = "四年级";
        break;
      case 55:
        txt = "五年级";
        break;
      case 56:
        txt = "六年级";
        break;
      case 57:
        txt = "七年级";
        break;
      case 58:
        txt = "八年级";
        break;
      case 59:
        txt = "九年级";
        break;
e371f2dc   梁保满   软件下载,学校,班级老师等报表导入...
754
      default:
0ca11cc2   梁保满   学段参数调整,发卡记录类型增加
755
        txt = "其他";
e371f2dc   梁保满   软件下载,学校,班级老师等报表导入...
756
        break;
db11048f   阿宝   设备状态,学校管理
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
    }
    return txt;
  }
  export function formatClass(data) {
    let sectionName = [];
    let sectionNameArr = [];
    data.map((item) => {
      if (!sectionName.includes(item.sectionName)) {
        sectionName.push(item.sectionName);
        sectionNameArr.push({
          value: item.sectionName,
          label: setSectionName(item.sectionName),
          children: [
            {
              value: item.gradeName,
              label: setGradeName(item.gradeName),
              children: [
                {
                  value: item.classId,
                  label: item.className,
                },
              ],
            },
          ],
        });
      } else {
        let hasGrade = false;
        let sectionIndex = 0;
        let gradeIndex = 0;
        sectionNameArr.map((items, index) => {
          items.map((grade, gradeInx) => {
            if (setGradeName(item.gradeName) == grade.value) {
              hasGrade = true;
              sectionIndex = index;
              gradeIndex = gradeInx;
            }
          });
        });
        if (hasGrade) {
          sectionNameArr[sectionIndex].children[gradeIndex].push({
            value: item.classId,
            label: item.className,
          });
        } else {
          sectionNameArr[sectionIndex].children.push({
            value: setGradeName(item.gradeName),
            label: setGradeName(item.gradeName),
            children: [
              {
                value: item.classId,
                label: item.className,
              },
            ],
          });
        }
      }
    });
db11048f   阿宝   设备状态,学校管理
814
815
    return sectionNameArr;
  }
bb4c8454   阿宝   添加,修改教师
816
817
818
819
820
821
822
823
824
825
826
  export function formatGradeClass(data) {
    let gradeName = [];
    let gradeNameArr = [];
    data.map((item) => {
      if (!gradeName.includes(item.gradeName)) {
        gradeName.push(item.gradeName);
        gradeNameArr.push({
          value: item.grade,
          label: item.gradeName,
          children: [
            {
1365ef5e   梁保满   优化
827
              value: item.id,
bb4c8454   阿宝   添加,修改教师
828
829
830
831
832
833
834
835
836
837
838
839
              label: item.className,
            },
          ],
        });
      } else {
        let gradeIndex = 0;
        gradeNameArr.map((items, index) => {
          if (items.value == item.grade) {
            gradeIndex = index;
          }
        });
        gradeNameArr[gradeIndex].children.push({
1365ef5e   梁保满   优化
840
          value: item.id,
bb4c8454   阿宝   添加,修改教师
841
842
843
844
845
846
          label: item.className,
        });
      }
    });
    return gradeNameArr;
  }
255e2506   梁保满   飞书bug及优化
847
848
849
850
851
852
853
854
855
856
857
858
  export function formatGradeNameClass(data) {
    let gradeName = [];
    let gradeNameArr = [];
    data.map((item) => {
      if (!gradeName.includes(item.gradeName)) {
        gradeName.push(item.gradeName);
        gradeNameArr.push({
          value: item.gradeName,
          label: item.gradeName,
          grade: item.grade,
          children: [
            {
1365ef5e   梁保满   优化
859
              value: item.id,
255e2506   梁保满   飞书bug及优化
860
              label: item.className,
e371f2dc   梁保满   软件下载,学校,班级老师等报表导入...
861
              leaf: true
255e2506   梁保满   飞书bug及优化
862
863
864
865
866
867
868
869
870
871
872
            },
          ],
        });
      } else {
        let gradeIndex = 0;
        gradeNameArr.map((items, index) => {
          if (items.value == item.gradeName) {
            gradeIndex = index;
          }
        });
        gradeNameArr[gradeIndex].children.push({
1365ef5e   梁保满   优化
873
          value: item.id,
255e2506   梁保满   飞书bug及优化
874
          label: item.className,
e371f2dc   梁保满   软件下载,学校,班级老师等报表导入...
875
          leaf: true
255e2506   梁保满   飞书bug及优化
876
877
878
879
880
        });
      }
    });
    return gradeNameArr;
  }
ef16e57e   LH_PC   fix:前端版本迭代
881
  
d3943e0d   LH_PC   feat:错题打印
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
  ///试卷定制化打印
  export async function paperPrint(paper) {
    let printWin = window.open("", "_blank", "width=800,height=600,resizable=no"); 
    var browser = getBrowserEngine(printWin);
    var subjectName = paper.subjectName;
    var paperTitle = paper.title;
    var paperQuestions = paper.questionList;
    function getBrowserEngine(windowParams) { 
      if (windowParams.navigator.userAgent.indexOf("Edge") > -1) {
        return "EdgeHTML";
      }
      if (windowParams.navigator.userAgent.indexOf("Edg") > -1) {
        return "Blink"; // Microsoft Edge (Chromium)
      }
      if (windowParams.navigator.userAgent.indexOf("Firefox") > -1) {
        return "Gecko";
      }
      if (windowParams.navigator.userAgent.indexOf("Trident") > -1) {
        return "Trident"; // IE
      }
      if (/Chrome/.test(windowParams.navigator.userAgent) && /Google Inc/.test(windowParams.navigator.vendor)) {
        return 'Google Chrome';
      }
      if (/360/.test(windowParams.navigator.userAgent) || /QIHU/.test(windowParams.navigator.userAgent)) {
        return '360 Browser';
      }
      return "Blink"; // Assume it's Chrome, Safari, or an alternative Blink-based browser
    }
    function numberToChinese(num) {
      const chineseDigits = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
      const chineseUnits = ["", "十", "百", "千", "万", "亿"];
  
      let result = '';
      let unitPos = 0;  // 单位的位置
      let zeroFlag = false;  // 是否出现过零
  
      if (num === 0) {
        return chineseDigits[0];  // 特殊情况,0 返回 "零"
      }
  
      // 处理数字,每次取一位并加上单位
      while (num > 0) {
        const currentDigit = num % 10; // 取最后一位数字
        if (currentDigit === 0) {
          if (!zeroFlag) {
            result = chineseDigits[currentDigit] + result; // 只在出现零时添加
            zeroFlag = true; // 标记零已经出现
          }
        } else {
          result = chineseDigits[currentDigit] + chineseUnits[unitPos] + result;
          zeroFlag = false; // 重置零的标记
        }
77ebf04d   梁保满   个人版
934
  
d3943e0d   LH_PC   feat:错题打印
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
        num = Math.floor(num / 10); // 去掉最后一位数字
        unitPos++;
      }
  
      // 处理 '一十' 和 '一百' 等情况
      if (result.startsWith('一十')) {
        result = result.substring(1); // 去掉 '一',例如 '一十' -> '十'
      }
  
      return result;
    }
    function htmlParseDom(html, getStyleScripts) {
      var tempDom = document.createElement('div');
      tempDom.innerHTML = html;
      var doms = tempDom.querySelectorAll('p');
      if (getStyleScripts == true) {
        var styleDoms = tempDom.querySelectorAll('style');
        var scriptDoms = tempDom.querySelectorAll('script');
        return {
          doms: doms,
          styles: styleDoms,
          scripts: scriptDoms
        }
      }
      return { doms: doms }
    }
    function generatePageParams() {
      const totalHeightPx = Math.max(
        printWin.document.documentElement.scrollHeight, // 整个文档高度
        printWin.document.body.scrollHeight            // Body 的高度
      );
      const totalHeightMM = totalHeightPx * 25.4 / 96;
      // ie浏览器高度
      var A4HeightMM = 287; 
      if (browser == "Google Chrome") {
        A4HeightMM = 297;
      }
      var pages = Math.ceil(totalHeightMM / A4HeightMM) + 1;
      for (var page = 0; page < pages; page++) {
        var pageFooteDiv = printWin.document.createElement('div');
        pageFooteDiv.classList.add('page-footer');
        pageFooteDiv.innerText = `${paperTitle}  ${subjectName}  ${page + 1}页(共${pages}页)`;
        pageFooteDiv.style.top = (page + 1) * A4HeightMM + (page * 5.5) + 'mm';
        printWin.document.body.appendChild(pageFooteDiv);
      }
    }
    // size: A4 portrait; 
    // size: A3 landscape;
  
    printWin.document.title = "中天易教";
    const style = printWin.document.createElement('style');
    style.innerHTML = `
        @media print 
        {
            @page {  
              size: A4 portrait;   
              height: 300mm;
              margin-top:5mm;
              margin-bottom:10mm;
              margin-left:2mm;
              margin-right:2mm;
            }    
            
            body {
              counter-reset: page-number; /* 重置页码计数器 */
            } 
  
            mn {
              padding-top:2px;
            } 
        }    
        table tfoot {
          height: 0px;
          display: table-footer-group;  
        }
        table thead {
          height: 20px;
          display: table-header-group;
        } 
        .student-input {
          text-align:center;
          margin-bottom:10px;
          span
          {
            margin-right:10px;
          }
        } 
        .page-left {
          height: 1100px; 
          width:30px; 
          position:fixed; 
          top:0;  
          left:0;
        }
        .page-right {
          height:1100px; 
          width:30px; 
          position:fixed; 
          top:0;  
          right:0;
        }
        .page-header {
          height:20px;
          width:100%;
          text-align:center;
          position:fixed;
          top:0;  
          left:0;
        }
        .page-footer {
          height:20px;
          width:100%; 
          text-align:center; 
          position: absolute;
        }
        h3,h2
        {
            margin:3px 0px 3px 0px;
        }
        .title-header
        {
          .title-content {
            text-align:center;
          }
        }
        b 
        {
          font-weight:500;
          margin:10px 0px;
        } 
        p,table
        {   
          font-size:16px; 
          margin:0px;
          padding:0px 0px 2px 0px;
         
          margin-block-start:0px;
          margin-block-end: 0px;
          margin-inline-start: 0px;
          margin-inline-end: 0px; 
          span,*,image,img,tr,td
          {  
            font-size:16px; 
            line-height:20px !important;
          }
          img,image
          {
            margin:0px;
            padding:0px;
            transform: scale(0.65);
            transform-origin: center;
          }  
        }`;
  
    printWin.document.head.appendChild(style);
  
    const titleBoxDom = printWin.document.createElement('div');
    titleBoxDom.classList.add('title-header');
    const titleDom = printWin.document.createElement('h3');
    titleDom.innerText = paperTitle;
    titleDom.classList.add('title-content');
    const subjectDom = printWin.document.createElement('h2');
    subjectDom.innerText = subjectName;
    subjectDom.classList.add('title-content');
    titleBoxDom.appendChild(titleDom);
    titleBoxDom.appendChild(subjectDom);
    printWin.document.body.appendChild(titleBoxDom);
  
    const studentInputBoxDom = printWin.document.createElement('div');
    studentInputBoxDom.classList.add('student-input');
    const studentClassInputDom = printWin.document.createElement('span');
    studentClassInputDom.innerHTML = '班级:________________';
    const studentNameInputDom = printWin.document.createElement('span');
    studentNameInputDom.innerHTML = '姓名:________________';
    const studentNoInputDom = printWin.document.createElement('span');
    studentNoInputDom.innerHTML = '学号:________________';
    studentInputBoxDom.appendChild(studentClassInputDom);
    studentInputBoxDom.appendChild(studentNameInputDom);
    studentInputBoxDom.appendChild(studentNoInputDom);
    printWin.document.body.appendChild(studentInputBoxDom);
  
    const tableDom = printWin.document.createElement('table'); 
    const theadDom = printWin.document.createElement('thead');
    const theadTrDom = printWin.document.createElement('tr');
    theadTrDom.appendChild(printWin.document.createElement('th'));
    theadTrDom.appendChild(printWin.document.createElement('th'));
    theadTrDom.appendChild(printWin.document.createElement('th'));
    theadDom.appendChild(theadTrDom);
    tableDom.appendChild(theadDom);
  
    const tbodyDom = printWin.document.createElement('tbody');
  
    for (var iof = 0; iof < paperQuestions.length; iof++) {
      var item = paperQuestions[iof];
      if (!item || !item.subQuestions) continue;
  
      const tbodyTrDom = printWin.document.createElement('tr');
      const tbodyLeftAltTdDom = printWin.document.createElement('td');
      const tbodyContentTdDom = printWin.document.createElement('td');
      const tbodyRightAltTdDom = printWin.document.createElement('td');
  
      const questionTitleDom = printWin.document.createElement('div');
      questionTitleDom.innerText = `${numberToChinese(iof + 1)}${item.questionTitle}(本节共${item.subQuestions.length}小题,共${item.score}分)`;
  
      tbodyContentTdDom.appendChild(questionTitleDom);
      tbodyTrDom.appendChild(tbodyLeftAltTdDom);
      tbodyTrDom.appendChild(tbodyContentTdDom);
      tbodyTrDom.appendChild(tbodyRightAltTdDom);
      tbodyDom.appendChild(tbodyTrDom);
  
      for (var idof = 0; idof < item.subQuestions.length; idof++) {
        const qTbodyTrDom = printWin.document.createElement('tr');
        const qTbodyLeftAltTdDom = printWin.document.createElement('td');
        const qTbodyContentTdDom = printWin.document.createElement('td');
        const qTbodyRightAltTdDom = printWin.document.createElement('td');
  
        const questionDom = printWin.document.createElement('div');
        var subItem = item.subQuestions[idof];
        var screenshotHtml = await fetchHTML(subItem.screenshot);
        var getStyleScripts = iof == 0 && idof == 0;
        var screenshotObject = htmlParseDom(screenshotHtml, getStyleScripts);
        var screenshotDoms = screenshotObject.doms;
        if (screenshotDoms.length <= 0) continue;
        for (var dom = 0; dom < screenshotDoms.length; dom++) {
          var screenshotDom = screenshotDoms[dom];
          questionDom.appendChild(screenshotDom);
        }
        qTbodyContentTdDom.appendChild(questionDom);
        qTbodyTrDom.appendChild(qTbodyLeftAltTdDom);
        qTbodyTrDom.appendChild(qTbodyContentTdDom);
        qTbodyTrDom.appendChild(qTbodyRightAltTdDom); 
        tbodyDom.appendChild(qTbodyTrDom);
      }
    }
    tableDom.appendChild(tbodyDom);
    printWin.document.body.appendChild(tableDom);
  
    const tfootDom = printWin.document.createElement('tfoot');
    const tfootTrDom = printWin.document.createElement('tr');
    tfootTrDom.appendChild(printWin.document.createElement('td'));
    tfootTrDom.appendChild(printWin.document.createElement('td'));
    tfootTrDom.appendChild(printWin.document.createElement('td'));
    tfootDom.appendChild(tfootTrDom);
    tableDom.appendChild(tfootDom);
    // generatePageParams();
    const iamges = printWin.document.querySelectorAll('img');
    if (iamges.length >= 1) {
      iamges[iamges.length - 1].onload = function () {
        printWin.print();
        printWin.close();
      }
    } else {
      printWin.print(); 
      printWin.close();
    } 
  }
  
  export function tablePrint(options) {
ef16e57e   LH_PC   fix:前端版本迭代
1193
1194
1195
1196
1197
1198
1199
1200
    var id = options.id;
    var title = options.title;
    var lindex = options.lindex;
    var splitParam = options.splitParam ?? 20;
    var printType = options.printType;
    var fixedColumn = options.fixedColumn ?? 0;
    var diffNumber = options.diffNumber ?? 0;
    var diffStNumber = options.diffStNumber ?? 0;
77ebf04d   梁保满   个人版
1201
    let divs = document.getElementById(id);
d3943e0d   LH_PC   feat:错题打印
1202
    let awin = window.open("中天易教", "_blank", "width=800,height=600,resizable=no");
77ebf04d   梁保满   个人版
1203
1204
    awin.document.getElementsByTagName(
      "head"
ef16e57e   LH_PC   fix:前端版本迭代
1205
1206
1207
1208
    )[0].innerHTML = `<style>    
       @media print {
          @page {
              size: A4 portrait;
45b98e8e   LH_PC   fix:修复年级组长打印,班主任最...
1209
              margin-top: 4mm;
d3943e0d   LH_PC   feat:错题打印
1210
1211
              margin-left: 2mm;
              margin-right: 2mm;
ef16e57e   LH_PC   fix:前端版本迭代
1212
1213
1214
          }
   
       
45b98e8e   LH_PC   fix:修复年级组长打印,班主任最...
1215
1216
1217
       body { 
            margin: 2mm;
            font-size: 8px;  
d3943e0d   LH_PC   feat:错题打印
1218
        } 
ef16e57e   LH_PC   fix:前端版本迭代
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
      }
    
      * :not(.tit) {
          font-size: 10px;
      }
      
  
      body {
          -webkit-print-color-adjust: exact;
      }
      .el-table__fixed-right{
         display: none;
      }
      .tit {
          text-align: center;
          font-size: 14px;
          color: #333;
          line-height: 24px;
          font-weight: 700;
          /* padding: 10px 0; */
          margin: 0;
      }
  
      .table-box,
      .el-table,
      .el-table__body-wrapper,
      .el-table--border {
          max-height: 99999999px !important;
          height: auto;
          width: auto !important;
          max-width: 1400px;
          margin: 5px auto;
      }
  
      .el-table,table {
          width: 100%;
          margin-bottom:10px;
      }
   
      .print-hidden,.el-tabs__nav {
          display: none;
      }
  
      .el-table,
      .el-table__body-wrapper {
          max-height: auto
      }
  
      .el-table .el-table__cell {
          padding: 2px 0;
          border-right: 1px solid black; 
          min-width:50px;
      }
    
      .el-table thead tr:first-child th.el-table__cell {
          border-top: 1px solid black; 
      }
  
      .el-table thead tr:first-child th.el-table__cell:first-child {
          border-left: 1px solid black;
      }
  
      .el-table thead tr th.el-table__cell {
          background: #ccc
      }  
       .el-table thead tr th{
          height:auto;
          word-wrap:break-word;
          word-break:break-all;
          overflow:hidden;
       }
      .el-table tbody tr td.el-table__cell:first-child {
          border-left: 1px solid black;
      }
   
      .el-table td.el-table__cell {
          border-bottom: 1px solid black;
      }
  
      .el-table--border .el-table__cell {
          border-right: 1px solid black;
      }
  
      .el-table--border th.el-table__cell,
      .el-table__fixed-right-patch {
          border-bottom: 1px solid black;
      }
  
      .el-table .el-table__cell.gutter {
          border: none !important;
      }
  
      .el-table__fixed {
          display: none !important
      }
  
      .el-table .el-table__cell {
          text-align: center !important
      }
  
      .el-table .el-table__cell.is-hidden>* {
          visibility: inherit;
      }
  
      .el-table__cell.gutter {
          display: none
      }
  
      ul,
      li {
          margin: 0;
          padding: 0;
          list-style: none
      }
  
      .hui-box {
          display: flex;
          text-align: center;
      }
  
      .hui-box .s-txt {
          width: 61px;
          line-height: 144px;
          background: #ccc;
          font-size: 16px;
          color: #fff;
          font-weight: 700;
          border: 1px solid #ccc;
          box-sizing: border-box
      }
  
      .hui-li {
          display: flex;
      }
  
      .hui-s {
          height: 48px;
          line-height: 48px;
          border-right: 1px solid #ccc;
          border-bottom: 1px solid #ccc;
          box-sizing: border-box;
      }
  
      .hui-s.s1 {
          width: 100px;
      }
  
      .hui-s.s2 {
          width: 110px;
      }
  
      .hui-s.s3 {
          width: 120px;
      }
  
      .info {
          display: flex;
          flex-wrap: wrap;
          border-left: 1px solid #ccc;
          border-top: 1px solid #ccc;
          margin-bottom: 12px;
      }
  
      .info-item {
          width: 25%;
          height: 50px;
          box-sizing: border-box;
          flex-shrink: 0;
          background: #f8f8f8;
          border-right: 1px solid #ccc;
          border-bottom: 1px solid #ccc;
          line-height: 50px;
          text-align: center;
      }
  
      .row-line {
          width: 33%;
          border: 1px solid #ebeef5;
          background: #f5f7fa;
          display: inline-block;
          height: 30px;
          line-height: 30px;
  
          .line-subfix {
              margin-left: 10px;
          }
      }
          
      .row-line-5 {
          width: 19.5% !important; 
      }
          
      .row-line-4 {
          width: 24.5% !important; 
      }
      .el-table__header,
      .el-table__body {
          width: 100% !important;
      }
  
      #print-table {
          max-width: 1400px;
          margin: 0 auto;
          width: 100%;
      }
  
      .hide {
          max-width: 1400px;
          margin: 0 auto;
          width: 100%;
          border-left: 1px solid #ccc;
          border-spacing: 0;
          box-sizing: border-box
      }
  
      .hide thead th {
          background: #ccc;
          line-height: 48px;
          border-right: 1px solid #ccc;
          box-sizing: border-box
      }
  
      .hide tbody tr td {
          line-height: 48px;
          border-right: 1px solid #ccc;
          text-align: center;
          box-sizing: border-box
      }
  
      .hide td {
          border-bottom: 1px solid #ccc;
      }
77ebf04d   梁保满   个人版
1451
      </style>`;
ef16e57e   LH_PC   fix:前端版本迭代
1452
1453
    var splitNumber = splitParam ? splitParam : 20;
  
77ebf04d   梁保满   个人版
1454
    let aDom = divs.cloneNode(true);
ef16e57e   LH_PC   fix:前端版本迭代
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
  
    let thead = aDom.querySelectorAll('.el-table__header-wrapper thead');
  
    let tbody = aDom.querySelectorAll('.el-table__body-wrapper table');
  
    var lastNotHiddenNumber = 0;
  
    if (tbody.length >= 1) {
  
      for (var tb = 0; tb < tbody.length; tb++) {
  
        var currentTbody = tbody[tb];
  
        var currentThead = thead[tb];
  
        var headTrs = currentThead.querySelectorAll('tr');
  
        var headThs = null;
  
        if (lindex != null && lindex >= 0)
          headThs = headTrs[lindex].querySelectorAll('th');
        else
          headThs = headTrs[headTrs.length - 1].querySelectorAll('th');
  
        if (headThs.length > splitNumber) {
  
          var bodyTrs = currentTbody.querySelectorAll('tr');
  
          var roas = Math.ceil(headThs.length / splitNumber);
  
          if (fixedColumn) {
  
            var thLength = headThs.length;
  
            thLength -= splitNumber;
  
            roas = 1;
  
            splitNumber -= fixedColumn;
  
            roas += Math.ceil(thLength / splitNumber);
  
          } else fixedColumn = 0;
  
          for (var stao = 1; stao < roas; stao++) {
  
            var newThead = currentThead.cloneNode(true);
  
            var newTbody = currentTbody.cloneNode();
  
            var newTrs = newThead.querySelectorAll('tr');
  
            for (var trds = 0; trds < newTrs.length; trds++) {
  
              var newThs = newTrs[trds].querySelectorAll('th');
  
              var index = 0;
  
              for (var lpss = 0; lpss < newThs.length; lpss++) {
  
                var newTh = newThs[lpss];
  
                if (!newTh) continue;
  
                if (stao == roas - 1 && index >= (splitNumber + fixedColumn)) {
                  var currentTh = headTrs[trds].querySelectorAll('th')[lpss];
                  if (currentTh) {
                    currentTh.style.display = "none";
                  }
                }
  
                var min = (stao + 1) * splitNumber;
  
                var max = stao * splitNumber;
  
                if (fixedColumn != 0) {
                  min += fixedColumn;
                  max += fixedColumn;
                }
  
                if (index >= min || index < max) {
                  if (trds == 0 && fixedColumn != 0 && lpss < fixedColumn) {
                    if (stao == roas - 1) lastNotHiddenNumber += 1;
                    continue;
                  }
                  newTh.style.display = "none";
                }
                else if (stao == roas - 1) lastNotHiddenNumber += 1;
  
  
                var colspan = Number(newTh.getAttribute('colspan')) || 0;
  
                index += 1;
  
                if (colspan > 1) {
                  index += colspan - 1;
                }
              }
            }
  
            for (var trd = 0; trd < bodyTrs.length; trd++) {
              var currentTr = bodyTrs[trd];
              var newTr = currentTr.cloneNode(true);
              var currentTds = currentTr.querySelectorAll('td');
              var newTds = newTr.querySelectorAll('td');
              var length = headThs.length + diffNumber;
              for (var lps = 0; lps < length; lps++) {
                var lpsIndex = lps;
                if (lps > diffStNumber) lpsIndex = lps - diffNumber;
                var newTd = newTds[lps];
                if (!newTd) continue;
                if (stao == roas - 1 && lpsIndex >= (splitNumber + fixedColumn)) {
                  var currentTd = currentTds[lps];
                  if (currentTd) {
                    currentTd.style.display = "none";
                  }
                }
                var min = (stao + 1) * splitNumber;
                var max = stao * splitNumber;
                if (fixedColumn != 0) {
                  min += fixedColumn;
                  max += fixedColumn;
                }
                if (lpsIndex >= min || lpsIndex < max) {
                  if (fixedColumn != 0 && lpsIndex < fixedColumn) continue;
                  newTd.style.display = "none";
                }
              }
              newTbody.appendChild(newTr);
            }
  
            if (lastNotHiddenNumber == fixedColumn) continue;
            newTbody.appendChild(newThead);
  
            newTbody.classList.add('_addedList');
  
            currentTbody.parentNode.parentNode.append(newTbody);
          }
        }
  
        currentTbody.appendChild(currentThead);
      }
24f4b248   梁保满   单卷试题分析打印样式
1597
    }
ef16e57e   LH_PC   fix:前端版本迭代
1598
  
e5e4a3e6   梁保满   v1.3
1599
1600
1601
1602
1603
1604
    if (title) {
      let pTit = awin.document.createElement('p')
      pTit.className = "tit"
      pTit.innerHTML = title
      awin.document.body.append(pTit)
    }
ef16e57e   LH_PC   fix:前端版本迭代
1605
  
45b98e8e   LH_PC   fix:修复年级组长打印,班主任最...
1606
    let pagedoc = awin.document.createElement('div')
06869a45   LH_PC   fix:修改测验时长显示不对的逻辑
1607
1608
1609
1610
1611
1612
    pagedoc.className = "page-number"
    awin.document.body.append(pagedoc)
    awin.document.body.append(aDom);
  
    let pagedom = awin.document.querySelectorAll('.page-number');
  
47a01cb6   梁保满   v1.3测试问题
1613
    awin.print();
ef16e57e   LH_PC   fix:前端版本迭代
1614
  
d3943e0d   LH_PC   feat:错题打印
1615
    awin.close();
4c2f99b0   梁保满   修改组卷
1616
1617
1618
1619
1620
1621
1622
1623
1624
  }
  
  export const cNum = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五",
    "十六",
    "十七",
    "十八",
    "十九",
    "二十",
  ];