QYF-GitLab1
2024-12-23 d71ed79914076dbf7d9a1613402d6dba54f74482
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
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
612
613
614
615
616
617
618
619
620
621
622
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
676
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
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
754
755
756
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
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
// packageBookService/pages/psychologyAnswer/psychologyAnswer.js
import {
  loginInfo
} from '../../../assets/js/login';
const app = getApp();
var pastData = require('./testdata/index')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    questuionName: "", //试卷名称
    dataList: "",
    barHeight: "",
    navBarHeight: "",
    loading: true,
    answerTitle: "", // 导航栏标题
    submitStatus: false, // 提交状态
    currentIndex: 0, // 当前显示的题号
    total: 0, // 题目总数
    totalScore: 0, //题目总分
    scoreDataList: [], // 特殊分数
    cardList: [], // 提交项,
    questionDataList: [], // 显示题目列表
    questionDataTitle: "", //显示题目的提示信息
    jumpQuestionList: [], //存储被删除的题目
    noData: false,
    isNight: false,
    sliderValue: 0, // 字体滑块
    showDialog: false, // 未提交退出拦截弹窗
    showId: '',
    uuid: "",
    isShowDialog: false, // 测试报告弹窗是否显示
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const questuionName = options.listName
    this.setData({
      questuionName: questuionName
    })
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight =
      (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
          this.init();
        } else {
          this.init();
        }
      })
    } else {
      this.init()
    }
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (this.data.answerType != "mock") {
      if (wx.timer) {
        clearInterval(wx.timer);
      }
    }
    if (this.data.answerType == "mock") {
      if (wx.timer) {
        clearInterval(wx.timer);
      }
      wx.timer = setInterval(() => {
        this.setData({
          saveTime: this.data.saveTime - 1,
        });
        if (this.data.saveTime == 0) {
          this.saveMockData();
        }
      }, 1000);
    }
    this.setData({
      startTime: Date.now(),
    });
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    if (wx.timer) {
      clearInterval(wx.timer);
    }
    this.setData({
      pauseTime: Date.now(),
    });
    if (wx.getStorageSync(app.config.tokenKey)) {
      let duration = this.data.pauseTime - this.data.startTime;
      this.count(duration);
    }
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload(e) {
    if (wx.timer) {
      clearInterval(wx.timer);
    }
    if (this.data.countdownInterval !== null) {
      clearInterval(this.data.countdownInterval);
    }
    this.setData({
      pauseTime: Date.now(),
    });
    if (wx.getStorageSync(app.config.tokenKey)) {
      let duration = this.data.pauseTime - this.data.startTime;
      this.count(duration);
    }
  },
 
  count(timeStr) {
    const data = {
      appRefCode: app.config.appRefCode,
      type: "LearningTime", //统计类型--阅读时长
      data: timeStr + "", //统计内容--时长毫秒
      event: "LearningTime",
      sysType: "App",
    };
    //阅读商品的id
    if (this.data.bookId) {
      data.productId = this.data.bookId;
    }
    //阅读资源的id
    // if (product.cmsItemId) {
    //   data.cmsItemId = product.cmsItemId
    // }
    app.MG.job.newJobWithApiNewEvent(data).then((res) => {});
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
  onShareTimeline() {},
 
  // 监听watch
  watch(context, variableName, callback) {
    let value = context.data[variableName]; // 获取被监听属性的当前值
    // 使用 Object.defineProperty 方法在数据对象上定义属性的 getter 和 setter
    Object.defineProperty(context.data, variableName, {
      configurable: true, // 可配置
      enumerable: true, // 可枚举
      get: function () {
        return value; // 返回属性的当前值
      },
      set: function (newVal) {
        const oldVal = value; // 记录属性的旧值
        value = newVal; // 更新属性的值
        callback.call(context, newVal, oldVal); // 调用回调函数,传递新值和旧值
      },
    });
  },
  // 修改nav颜色
  changeNavBarColor(e) {
    if (type == 'night') {
      wx.setNavigationBarColor({
        backgroundColor: '#000000',
        frontColor: '#ffffff',
      })
    } else {
      wx.setNavigationBarColor({
        backgroundColor: '#ffffff',
        frontColor: '#000000',
      })
    }
  },
  // 正则找出听力src
  extractSourceSrc(htmlString) {
    // 正则表达式匹配<source>标签中的src属性值  
    var srcRegex = /<source\s+src="([^"]+)"/i;
    var srcTwo = /<audio\s+src="([^"]+)"/i;
 
    // 执行正则匹配  
    var match = srcRegex.exec(htmlString);
    const local = srcTwo.exec(htmlString)
    // 如果匹配成功,返回第一个捕获组的内容(src属性的值)  
    if (match && match[1]) {
      return match[1].replace('../file', app.config.requestCtx + '/file');
    } else if (local && local[1]) {
      return local[1].replace('../file', app.config.requestCtx + '/file')
    } else {
      // 如果没有匹配到,返回null  
      return null;
    }
  },
 
  // 拿到听力题除audio标签外其他内容
  removeVideoAndAudioTags(htmlString) {
    // 使用正则表达式匹配并移除所有的 <video> 和 <audio> 标签
    var cleanedHtml = htmlString.replace(/<video[^>]*>[\s\S]*?<\/video>|<audio[^>]*>[\s\S]*?<\/audio>/gi, '');
 
    return cleanedHtml;
  },
 
  // 改变loading状态
  changeLoadingState() {
    this.setData({
      loading: true
    })
  },
  // 返回拦截
  beforeleave() {
    if (!this.data.submitStatus) {
      wx.showModal({
        title: "提示",
        content: "未提交,是否退出答题",
        confirmColor: "#ff6c00",
        cancelColor: "#949494",
        complete: (res) => {
          if (res.cancel) {
            this.setData({
              showDialog: true
            })
          }
          if (res.confirm) {
            this.setData({
              submitStatus: true,
              showDialog: false
            });
            wx.navigateBack();
          }
        },
      });
    }
  },
  onChangeSlider(e) {
    this.setData({
      sliderValue: e.detail.value,
    });
    console.log(e.detail.value);
  },
  // 返回
  goBack() {
    console.log(this.data.submitStatus);
    wx.navigateBack();
  },
  //设置背景色
  changeBGColor(e) {
    const flag = e.detail.value
    this.setData({
      isNight: flag,
    });
    if (flag) {
      wx.setNavigationBarColor({
        backgroundColor: '#000000',
        frontColor: '#ffffff',
      })
    } else {
      wx.setNavigationBarColor({
        backgroundColor: '#ffffff',
        frontColor: '#000000',
      })
    }
  },
  // 切换题目
  changeSwiper(e) {
    let index = e.detail.index;
    const lastItem = this.data.questionDataList[index];
    this.setData({
      currentIndex: e.detail.index,
      showId: lastItem.id
    });
  },
 
  // 我的错题,收藏查看解析按钮
  viewParsing() {
    if (
      this.data.answerType == "collectQuestion" ||
      this.data.answerType == "errorQuestion"
    ) {
      const item = this.data.questionDataList[this.data.currentIndex];
      if (!item.isComplete) {
        this.handleQuestion(this.data.currentIndex);
      }
    }
  },
  // 点击答题卡跳转题目
  goQuestion(e) {
    const id = e.detail.id;
    this.data.questionDataList.forEach((item, index) => {
      if (item.id == id) {
        this.setData({
          currentIndex: index,
        });
      }
    });
  },
  handeleOption(e) {
    const id = e.detail.value.currentTarget.dataset.id;
    const radioChecked = e.detail.value.detail.value;
    const questionList = this.data.questionDataList;
    // 我的错题和我的收藏模式下,单选题选择了直接批改
    for (let index = 0; index < questionList.length; index++) {
      const item = questionList[index];
      if (item.id == id && !item.isComplete) {
        if (item.questionType == "linkage") {
          item.questionTab = radioChecked;
          item.userAnswer = "";
        }
      }
    }
    this.setData({
      questionDataList: questionList,
    });
  },
  // 单选 多选 触发
  onChangeRadio(e) {
    const radioData = e.detail.value.currentTarget.dataset.value;
    const id = e.detail.value.currentTarget.dataset.id;
    const radioChecked = e.detail.value.detail.value;
    const questionList = this.data.questionDataList;
    const jumpQuestion = this.data.jumpQuestionList
    const radioChange = (item) => {
      if (!item.jumpData) return false
      if (item.userAnswer == item.jumpData.value) {
        // 选中跳过答题选项 记录并删除跳过的题
        for (let cindex = 0; cindex < item.jumpData.list.length; cindex++) {
          const citem = item.jumpData.list[cindex];
          jumpQuestion.push({
            questionIndex: questionList.findIndex((ditem) => ditem.id == citem),
            data: questionList.find((ditem) => ditem.id == citem),
          })
        }
        this.setData({
          questionDataList: questionList.filter(
            (citem) => !item.jumpData.list.includes(citem.id)
          ),
          jumpQuestionList: jumpQuestion,
        });
        console.log(this.data.questionDataList, "删除后的questionDataList");
      } else {
        // 选中另外的选项,要判断题目列表是否已经删除了题,删除了则加回去
        for (let cindex = 0; cindex < item.jumpData.list.length; cindex++) {
          const citem = item.jumpData.list[cindex]
          if (!questionList.some((ditem) => ditem.id == citem)) {
            const delData = jumpQuestion.find((eitem) => eitem.data.id == citem)
            questionList.splice(delData.questionIndex, 0, delData.data)
          }
        }
        this.setData({
          questionDataList: questionList,
        });
        console.log(this.data.questionDataList, "恢复后的questionDataList");
      }
    }
    for (let index = 0; index < questionList.length; index++) {
      const item = questionList[index];;
      if (item.id == id && !item.isComplete) {
        item.userAnswer = radioChecked;
        item.isUserAnswer = this.isHaveAnswer(radioChecked);
      }
    }
    this.setData({
      questionDataList: questionList,
    });
    // 调用处理方法
    for (let cindex = 0; cindex < questionList.length; cindex++) {
      const citem = questionList[cindex];;
      if (citem.id == id && !citem.isComplete) {
        radioChange(citem)
      }
    }
    const listLength = this.data.questionDataList.length - 1
    if (this.data.currentIndex < listLength) {
      this.setData({
        currentIndex: this.data.currentIndex + 1
      })
    }
  },
  // 输入框触发
  onChangeInput(e) {
    const inputData = e.detail.value.detail.value;
    const id = e.detail.value.currentTarget.dataset.id;
    const index = Number(e.detail.value.currentTarget.dataset.index);
    const questionList = this.data.questionDataList;
    questionList.forEach((item) => {
      if (item.id == id) {
        item.userAnswer[index] = inputData;
        return (item.isUserAnswer = this.isHaveAnswer(inputData));
      }
    });
    const cardListUpdata = this.data.cardList;
    cardListUpdata.forEach((item) => {
      item.infoList.forEach((citem) => {
        if (citem.id == id) {
          citem.userAnswer[index] = inputData;
          return (citem.isUserAnswer = this.isHaveAnswer(inputData));
        }
      });
    });
    this.setData({
      questionDataList: questionList,
      cardList: cardListUpdata,
    });
    if (this.data.answerType == "mock") {
      this.setData({
        saveTime: 20,
      });
    }
  },
  // 数组转为字符串方法
  arrayToString(data) {
    // 检查是否为数组
    if (Array.isArray(data)) {
      // 使用 join 方法将数组转换为字符串,默认使用逗号分隔
      return data.join(",").replace(/<[^>]*>/g, "");
    } else {
      // 如果不是数组,直接返回原始值
      return data.replace(/<[^>]*>/g, "");
    }
  },
  // 判断是否有用户答案
  isHaveAnswer(data) {
    if (typeof data == "string") {
      data = data
        .replace(/<[^>]*>/g, "")
        .replace(/&nbsp;/g, "")
        .trim();
      if (data.length) {
        return true;
      } else {
        return false;
      }
    } else if (typeof data == "object") {
      const answer = data.find((item) => item.length > 0);
      if (answer) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  },
  // 提交逻辑
  submitPaper() {
    this.setData({
      submitStatus: true,
      loading: true,
    });
    // 先遍历所有题目,将未批改的题目批改
    const qustionList = this.data.questionDataList;
    if (qustionList.length) this.handleQuestion();
    // 记录用户答题数据
    let saveData = [];
    for (let index = 0; index < this.data.questionDataList.length; index++) {
      const item = this.data.questionDataList[index];
      saveData.push({
        id: item.id,
        answer: item.userAnswer,
        isRight: item.isRight,
      });
    }
    app.MG.identity.setUserKey({
      setKeyRequests: [{
        domain: "answerData",
        key: this.data.uuid,
        value: JSON.stringify({
          answerData: saveData,
          scoreData: this.data.scoreDataList
        }),
      }, ],
    });
    this.setData({
      loading: false,
      isShowDialog: true,
      submitStatus: true,
    });
  },
  // 初始化函数
  async init(isReset) {
    this.setData({
      isShowDialog: false,
      loading: true,
    });
    const questuionName = this.data.questuionName
    const questuionList = pastData.postData.list
    var listIndex = 0
    for (let index = 0; index < questuionList.length; index++) {
      const item = questuionList[index];
      if (item.name == questuionName) {
        listIndex = index
      }
    }
    const indexof = listIndex;
    this.setData({
      dataList: pastData,
      // questionDataList: pastData.postData.list[indexof].list,
      questionDataTitle: pastData.postData.list[indexof].title,
      questionDataOptions: pastData.postData.list[indexof].optionList,
      // scoreDataList: pastData.postData.list[indexof].scoreData,
      uuid: pastData.postData.list[indexof].name
    });
    wx.setNavigationBarTitle({
      title: pastData.postData.list[indexof].name,
    })
    const list = [...pastData.postData.list[indexof].list]
    const scoreList = [...pastData.postData.list[indexof].scoreData]
    if (isReset) {
      list.forEach(item => item.userAnswer = "")
      scoreList.forEach(item => {
        item.dispatch = "",
          item.score = 0
      })
    }
    this.getAnswerInfo(list, scoreList)
  },
 
  // 获取题库题目
  async getQuestionList(oldData) {
    // 清空正确题数记录
    this.setData({
      noData: false,
      correctNum: 0,
    });
  },
 
  // 批改题目 (练习,我的错题,我的收藏,,组卷)
  handleQuestion() {
    const questionList = this.data.questionDataList;
    const optionList = this.data.questionDataOptions;
    const scoreData = this.data.scoreDataList;
    for (let index = 0; index < questionList.length; index++) {
      const item = questionList[index];
      if (item.questionType == 'judge' && item.userAnswer) {
        if (optionList && optionList.length) {
          const optionData = optionList[item.optionIndex].find(
            (citem) => citem.value == item.userAnswer
          )
          item.score = optionData.score
        }
      }
      if (item.questionType == 'singleChoice' && item.userAnswer) {
        if (optionList && optionList.length) {
          const optionData = optionList[item.optionIndex].find(
            (citem) => citem.value == item.userAnswer
          )
          item.score = optionData.score
        } else {
          item.score = item.option.find((citem) => citem.value == item.userAnswer).score
        }
      }
      if (item.questionType == 'linkage' && item.userAnswer) {
        if (item.optionData) {
          const optionScore = item.optionData[item.questionTab].find(
            (citem) => citem.value == item.userAnswer
          )
          item.score = optionScore.score
        }
      }
      if (!item.userAnswer) item.score = 0
    }
    //计算各项的总分
    for (let cindex = 0; cindex < scoreData.length; cindex++) {
      const scoreItem = scoreData[cindex];
      if (scoreItem.range == 'all') {
        questionList.forEach((item) => {
          if (item.score) {
            scoreItem.score += item.score
          }
        })
      } else {
        questionList.forEach((item, index) => {
          if (scoreItem.range.includes(index)) scoreItem.score += item.score
        })
      }
      if (scoreItem.isAverage) {
        scoreItem.score = Math.floor(scoreItem.score / scoreItem.range.length)
      }
      if (scoreItem.multiply) {
        scoreItem.score = Math.floor(scoreItem.score * scoreItem.multiply)
      }
    }
    //根据总分给出测试结果(文字)
    for (let dindex = 0; dindex < scoreData.length; dindex++) {
      const scoreItem = scoreData[dindex];
      scoreItem.dispatch = scoreItem.result.find((item) => item.score[0] <= scoreItem.score && item.score[1] >= scoreItem.score).desc
    }
    this.setData({
      scoreDataList: scoreData,
      questionDataList: questionList,
      submitStatus: true,
      dialogState: true,
    });
  },
 
  // 处理答题数据
  recordAnswerData() {
    this.data.cardList.push({
      name: "客观题得分",
      score: this.data.subjectiveNum,
      path: this.data.productLinkPath,
      // infoList: [],
      // catalogName: ''
    });
    let setInfoData = {
      currentIndex: this.data.currentIndex,
      dataList: JSON.parse(JSON.stringify(this.data.cardList)),
    };
    for (let i = 0; i < setInfoData.dataList.length; i++) {
      const item = setInfoData.dataList[i];
      if (!item.name && !item.name == "客观题得分") {
        for (let j = 0; j < item.infoList.length; j++) {
          let obj = {
            id: item.infoList[j].id,
            userAnswer: item.infoList[j].userAnswer,
            isComplete: item.infoList[j].isComplete,
            isRight: item.infoList[j].isRight,
            isCollect: item.infoList[j].isCollect,
          };
          item.infoList[j] = obj;
        }
      }
    }
    this.setAnswerInfo(setInfoData);
  },
  // 提交答题数据
  setAnswerInfo(data) {
    app.MG.identity
      .setUserKey({
        setKeyRequests: [{
          domain: "answerData",
          key: this.data.productLinkPath,
          value: JSON.stringify(data),
        }, ],
      })
      .then((res) => {});
  },
  async restart() {
    this.setData({
      isShowDialog: false,
      currentIndex: 0,
      submitStatus: false,
    });
    await app.MG.identity.setUserKey({
      setKeyRequests: [{
        domain: "answerData",
        key: this.data.uuid,
        value: JSON.stringify({
          answerData: [],
        }),
      }, ],
    });
    this.init(true);
  },
  openIsShowDialog() {
    this.setData({
      isShowDialog: true,
    })
  },
  // 获取旧答题数据
  getAnswerInfo(arr, scoreListArr) {
    let newArr = [...arr];
    let scoreArr = [...scoreListArr];
    app.MG.identity
      .getUserKey({
        domain: "answerData",
        keys: [this.data.uuid],
      })
      .then((res) => {
        try {
          const data = JSON.parse(res[0].value)
          if (data.answerData?.length > 0 && newArr.length) {
            this.setData({
              isShowDialog: true,
              submitStatus: true,
            })
            newArr.forEach(item => {
              const obj = data.answerData.find(citem => citem.id == item.id)
              if (obj?.answer) {
                item.userAnswer = obj.answer
              } else {
                item.userAnswer = ""
              }
            })
          }
          if (data.scoreData?.length > 0 && scoreArr.length) {
            scoreArr.forEach(item => {
              const obj = data.scoreData.find(citem => citem.name == item.name)
              if (obj?.score) {
                item.score = obj.score
              } else {
                item.score = 0
              }
              if (obj?.dispatch) {
                item.dispatch = obj.dispatch
              } else {
                item.dispatch = ""
              }
            })
          }
          this.setData({
            questionDataList: newArr,
            scoreDataList: scoreArr,
            loading: false,
          })
        } catch (error) {
          this.setData({
            questionDataList: newArr,
            scoreDataList: scoreArr,
            loading: false,
          })
          console.log(error);
        }
        const e = {
          detail: {
            index: 0
          }
        };
        this.changeSwiper(e)
      });
  },
 
  // 记录模考答题数据
  saveMockData() {
    const data = this.data.mockData.datas.find(
      (itme) => itme.id == this.data.uuid
    );
    if (data.state == "3") return true;
    const saveData = this.data.mockData.answer;
    for (let i = 0; i < this.data.questionDataList.length; i++) {
      const item = this.data.questionDataList[i];
      if (this.isHaveAnswer(item.userAnswer)) {
        const index = saveData.findIndex((saveitem) => saveitem.id == item.id);
        if (index + "" != "-1") {
          saveData[index].answer = item.userAnswer;
        } else {
          saveData.push({
            id: item.id,
            answer: item.userAnswer,
          });
        }
      }
    }
    //
    if (this.data.mockData.state == "1") {
      const datas = this.data.mockData.datas;
      datas.forEach((item) => {
        if (item.id == this.data.uuid) {
          item.state = "2";
        }
      });
      this.setMockInfo(datas);
    }
    //
    app.MG.identity
      .setUserKey({
        setKeyRequests: [{
          domain: "answerData",
          key: this.data.uuid,
          value: JSON.stringify({
            currentIndex: this.data.currentIndex,
            time: this.data.countdownTime,
            answerData: saveData,
          }),
        }, ],
      })
      .then((res) => {
        this.setData({
          saveTime: 20,
        });
        console.log("模考答题数据已记录");
      });
  },
 
  // 富文本处理
  formatRichText(html) {
    console.log(html);
    let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
      match = match
        .replace(/style="[^"]+"/gi, "")
        .replace(/style='[^']+'/gi, "");
      match = match
        .replace(/width="[^"]+"/gi, "")
        .replace(/width='[^']+'/gi, "");
      match = match
        .replace(/height="[^"]+"/gi, "")
        .replace(/height='[^']+'/gi, "");
      return match;
    });
    newContent = newContent.replace(
      /style="[^"]+"/gi,
      function (match, capture) {
        match = match
          .replace(/<p>/gi, '<p class="p_class">')
          .replace(/width:[^;]+;/gi, "max-width:100%;")
          .replace(/width:[^;]+;/gi, "max-width:100%;");
        return match;
      }
    );
    newContent = newContent.replace(/<br[^>]*\/>/gi, "");
    newContent = newContent.replace(/<a>/gi, '<a class="p_class "');
    newContent = newContent.replace(/<li>/gi, '<li class="p_class "');
    newContent = newContent.replace(/\<p/gi, '<p class="p_class "');
    newContent = newContent.replace(/\<span/gi, '<span class="p_class "');
    newContent = newContent.replace(
      /\<img/gi,
      '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
    );
    return newContent;
  },
});