packageBookService/pages/bookServices/examination/examination.js
@@ -1,4 +1,6 @@
import { getPublicImage } from '../../../../assets/js/middleGround/tool'
import {
  getPublicImage
} from '../../../../assets/js/middleGround/tool'
const app = getApp()
Page({
@@ -9,26 +11,26 @@
    barHeight: "",
    navBarHeight: "",
    loading: false,
    answerTitle: "",  // 导航栏标题
    countdownInterval: null,   // 计时器
    answerTitle: "", // 导航栏标题
    countdownInterval: null, // 计时器
    isCountdownRunning: true, // 是否倒计时
    countdownTime: 0,  // 倒计时时间
    countdownTime: 0, // 倒计时时间
    bookId: "",
    productLinkPath: "",
    rootCmsItemId: "",
    idPathList: [],  // 题目列表
    answerType: "",  // 答题模式
    submitStatus: false,  // 提交状态
    idPathList: [], // 题目列表
    answerType: "", // 答题模式
    submitStatus: false, // 提交状态
    currentIndex: 0, // 当前显示的题号
    collectList: [],   //  收藏题目列表
    errorList: [],  // 错题列表
    subjectiveTotal: 0,  // 客观题总数
    collectList: [], //  收藏题目列表
    errorList: [], // 错题列表
    subjectiveTotal: 0, // 客观题总数
    subjectiveNum: 0, // 客观题得分
    subjectiveGrade: 0, // 客观题总分
    correctNum: 0,  // 正确题目数量
    total: 0,   // 题目总数
    cardList: [],  // 提交项,
    questionDataList: [],  // 显示题目列表
    correctNum: 0, // 正确题目数量
    total: 0, // 题目总数
    cardList: [], // 提交项,
    questionDataList: [], // 显示题目列表
    mockid: 0,
    uuid: 0,
    mockData: {
@@ -41,13 +43,23 @@
      answer: []
    },
    saveTime: 20,
    isNight: false
    isNight: false,
    sliderValue: 0, // 字体滑块
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // wx.enableAlertBeforeUnload({
    //   message: "未提交,是否退出答题?",
    //   success: function (res) {
    //     console.log('确定', res);
    //   },
    //   fail: function (err) {
    //     console.log("失败:", err);
    //   },
    // });
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
@@ -74,14 +86,17 @@
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  onReady() {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (this.data.answerType != 'mock') {
      if (wx.timer) {
        clearInterval(wx.timer)
      }
    }
    if (this.data.answerType == 'mock') {
      if (wx.timer) {
        clearInterval(wx.timer)
@@ -101,13 +116,18 @@
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    if (wx.timer) {
      clearInterval(wx.timer)
    }
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  onUnload(e) {
    if (wx.timer) {
      clearInterval(wx.timer)
    }
    if (this.data.countdownInterval !== null) {
      clearInterval(this.data.countdownInterval)
    }
@@ -130,10 +150,35 @@
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  onShareAppMessage() {},
  // 监听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); // 调用回调函数,传递新值和旧值
      }
    });
  },
  onChangeSlider(e) {
    this.setData({
      sliderValue: e.detail.value
    })
    console.log(e.detail.value);
  },
  // 返回
  goBack() {
    console.log(this.data.submitStatus);
    wx.navigateBack();
  },
  //设置背景色
@@ -202,9 +247,18 @@
      currentIndex: e.detail.index
    })
    let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0
    let flag = this.isHaveAnswer(this.data.questionDataList[index].userAnswer)
    if (flag) this.handleQuestion(e.detail.index)
    const item = this.data.questionDataList[index]
    if ((this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
      let flag = this.isHaveAnswer(item.userAnswer)
      if (flag) this.handleQuestion(index)
    }
  },
  // 我的错题,收藏查看解析按钮
  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) {
@@ -223,14 +277,48 @@
    const id = e.detail.value.currentTarget.dataset.id
    const radioChecked = e.detail.value.detail.value
    const questionList = this.data.questionDataList
    questionList.forEach(item => {
      if (item.id == id) {
    // 我的错题和我的收藏模式下,单选题选择了直接批改
    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)
        if ((item.questionType == 'singleChoice' || item.questionType == 'judge') && (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
          this.handleQuestion(this.data.currentIndex)
        }
      }
    })
    }
    // questionList.forEach(item => {
    //   if (item.id == id && !item.isComplete) {
    //     item.userAnswer = radioChecked
    //     item.isUserAnswer = this.isHaveAnswer(radioChecked)
    //     if ((item.questionType == 'singleChoice' || item.questionType == 'judge') && (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
    //       this.handleQuestion(this.data.currentIndex)
    //     }
    //   }
    // })
    const cardListUpdata = this.data.cardList
    for (let index = 0; index < cardListUpdata.length; index++) {
      const item = cardListUpdata[index];
      for (let cindex = 0; cindex < item.infoList.length; cindex++) {
        const citem = item.infoList[cindex];
        if (citem.id == id && !citem.isComplete) {
          citem.userAnswer = radioChecked
          citem.isUserAnswer = this.isHaveAnswer(radioChecked)
        }
      }
    }
    // cardListUpdata.forEach(item => {
    //   item.infoList.forEach(citem => {
    //     if (citem.id == id && !citem.isComplete) {
    //       citem.userAnswer = radioChecked
    //       citem.isUserAnswer = this.isHaveAnswer(radioChecked)
    //     }
    //   })
    // })
    this.setData({
      questionDataList: questionList
      questionDataList: questionList,
      cardList: cardListUpdata
    })
    if (this.data.answerType == 'mock') {
      this.setData({
@@ -242,16 +330,27 @@
  onChangeInput(e) {
    const inputData = e.detail.value.detail.value
    const id = e.detail.value.currentTarget.dataset.id
    const index = e.detail.value.currentTarget.dataset.index
    const index = Number(e.detail.value.currentTarget.dataset.index)
    console.log(index);
    const questionList = this.data.questionDataList
    questionList.forEach(item => {
      if (item.id == id) {
        item.userAnswer[index] = inputData,
          item.isUserAnswer = this.isHaveAnswer(item.userAnswer)
        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
      questionDataList: questionList,
      cardList: cardListUpdata,
    })
    if (this.data.answerType == 'mock') {
      this.setData({
@@ -282,19 +381,24 @@
      } else {
        return false
      }
    } else {
    } else if (typeof data == 'object') {
      const answer = data.find((item) => item.length > 0)
      if (answer) {
        return true
      } else {
        return false
      }
    } else {
      return false
    }
  },
  // 提交逻辑
  submitPaper() {
    // 关闭退出页面监听
    wx.disableAlertBeforeUnload()
    this.setData({
      submitStatus: true
      submitStatus: true,
      loading: true
    })
    const child = this.selectComponent('#question-options')
    if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion' || this.data.answerType == 'mock') {
@@ -302,7 +406,7 @@
      const qustionList = this.data.questionDataList
      for (let index = 0; index < qustionList.length; index++) {
        const item = qustionList[index];
        if (!item.isComplete) this.handleQuestion(index + 1)
        if (!item.isComplete) this.handleQuestion(index)
      }
    }
    if (this.data.answerType == 'option') {
@@ -339,20 +443,20 @@
        })
      }
      app.MG.identity.setUserKey({
        setKeyRequests: [
          {
            domain: 'mockAnswerData',
            key: this.data.uuid,
            value: JSON.stringify({
              time: this.data.countdownTime,
              answerData: saveData
            })
          }
        ]
        setKeyRequests: [{
          domain: 'mockAnswerData',
          key: this.data.uuid,
          value: JSON.stringify({
            time: this.data.countdownTime,
            answerData: saveData
          })
        }]
      })
      child.openTestReportDialog()
    }
    this.setData({
      loading: false
    })
  },
  // 初始化函数
  async init() {
@@ -364,17 +468,23 @@
    })
    if (this.data.answerType == 'option') {
      if (this.data)
        this.startCountdown()
      this.setData({
        countdownTime: 2 * 60 * 60 * 1000
      })
        // this.startCountdown()
        this.setData({
          countdownTime: 2 * 60 * 60 * 1000
        })
      // 测试答题
      await this.getCollectIdList() // 获取收藏id列表
      await this.getErrorList()   // 获取错题id列表
      await this.getErrorList() // 获取错题id列表
    } else if (this.data.answerType == 'collectQuestion') {
      this.setData({
        submitStatus: true
      })
      // 我的收藏
      await this.getcollectId() // 获取收藏题目
    } else if (this.data.answerType == 'errorQuestion') {
      this.setData({
        submitStatus: true
      })
      // 我的错题
      // loadings.value = true
      await this.getErrorIdList()
@@ -404,18 +514,19 @@
            let oldQuestionList = []
            oldQuestionList = await this.getMockQuestionList()
            const userAnswerList = await this.getMockAnswer()
            await this.getMockDataList(oldQuestionList, userAnswerList)
            this.setData({
              'mockData.sumTime': oldMockData.time,
              cardList: oldQuestionList
            })
            await this.getMockDataList(oldQuestionList, userAnswerList)
          }
          if (oldMockData.state == '0' || oldMockData.state == '1' || oldMockData.state == '2') {
            this.startCountdown()
          }
          if (oldMockData.state == '3') {
            this.setData({
              submitStatus: true
              submitStatus: true,
              subjectiveNum: oldMockData.report.userScore
            })
          }
        }
@@ -448,16 +559,14 @@
      // 组卷模式
      // 清空答题记录
      await app.MG.identity.setUserKey({
        setKeyRequests: [
          {
            domain: 'mockAnswerData',
            key: this.data.uuid,
            value: JSON.stringify({
              time: this.data.countdownTime,
              answerData: []
            })
          }
        ]
        setKeyRequests: [{
          domain: 'mockAnswerData',
          key: this.data.uuid,
          value: JSON.stringify({
            time: this.data.countdownTime,
            answerData: []
          })
        }]
      })
      this.init()
    } else {
@@ -480,8 +589,7 @@
          this.setData({
            collectList: JSON.parse(res[0].value)
          })
        } catch (error) {
        }
        } catch (error) {}
        if (this.data.answerType == 'option') {
          // 先获取用户答题记录
          this.getAnswerInfo(async (res) => {
@@ -493,6 +601,7 @@
              let value = JSON.parse(res[0].value)
              // 有答题记录,得分赋值
              if (value) {
                wx.disableAlertBeforeUnload()
                this.setData({
                  submitStatus: true
                })
@@ -506,6 +615,7 @@
              this.setData({
                currentIndex: value.currentIndex
              })
              console.log(this.data.submitStatus);
              // 携带答题记录 获取题目
              await this.getQuestionList(value.dataList)
            } else {
@@ -527,20 +637,19 @@
          this.setData({
            errorList: JSON.parse(res[0].value)
          })
        } catch (error) {
        }
        } catch (error) {}
      })
  },
  // 获取题库题目
  getQuestionList(oldData) {
  async getQuestionList(oldData) {
    // 清空正确题数记录
    this.setData({
      cardList: [],
      correctNum: 0,
    })
    let flag = 0
    this.data.idPathList.forEach((pathitem) => {
    for (let index = 0; index < this.data.idPathList.length; index++) {
      const pathitem = this.data.idPathList[index];
      const pathList = this.data.cardList
      pathList.push({
        path: pathitem.productLinkPath,
@@ -573,7 +682,7 @@
          size: 999
        }
      }
      app.MG.store.getProductDetail(query).then((res) => {
      await app.MG.store.getProductDetail(query).then((res) => {
        this.setData({
          total: res.datas.cmsDatas[0].datas.length
        })
@@ -593,29 +702,22 @@
            // num: index, // 题号
            id: item.id,
            type: pathitem.name,
            stem:
              item.Embedded_QuestionBank_QuestionType == 'completion'
                ? JSON.parse(item.Embedded_QuestionBank_Stem)
                  .stemTxt.replaceAll('<vacancy>', ',input,')
                  .split(',')
                : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
            stem: item.Embedded_QuestionBank_QuestionType == 'completion' ?
              JSON.parse(item.Embedded_QuestionBank_Stem)
              .stemTxt.replaceAll('<vacancy>', ',input,')
              .split(',') : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
            answer: item.Embedded_QuestionBank_Answer, // 答案
            option: item.Embedded_QuestionBank_Option
              ? JSON.parse(item.Embedded_QuestionBank_Option)
              : '', // 选择题选项
            option: item.Embedded_QuestionBank_Option ?
              JSON.parse(item.Embedded_QuestionBank_Option) : '', // 选择题选项
            analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 解析
            questionType: item.Embedded_QuestionBank_QuestionType, // 题型
            optionStyle: item.Embedded_QuestionBank_OptionStyle, // 选项显示类型
            stemStyle: item.Embedded_QuestionBank_StemStyle, // 题干显示类型
            difficulty: item.Embedded_QuestionBank_Difficulty
              ? 4 - item.Embedded_QuestionBank_Difficulty
              : 0, // 难度等级
            userAnswer: oldObj
              ? oldObj.userAnswer
              : item.Embedded_QuestionBank_QuestionType == 'completion' ||
                item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
                ? []
                : '',
            difficulty: item.Embedded_QuestionBank_Difficulty ?
              4 - item.Embedded_QuestionBank_Difficulty : 0, // 难度等级
            userAnswer: oldObj ?
              oldObj.userAnswer : item.Embedded_QuestionBank_QuestionType == 'completion' ||
              item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '',
            isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false,
            isRight: oldObj ? oldObj.isRight : null,
            isComplete: oldObj ? oldObj.isComplete : false,
@@ -649,6 +751,18 @@
                index++
              }
            }
          }
          // 题干富文本处理
          if (questionObj.stemStyle == 'RichText') {
            // questionObj.option.txt = ''
            questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ').replace(/\<p/gi, '<p class="stem-rich-p"')
          }
          // 选项富文本处理
          if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) {
            questionObj.option.forEach(item => {
              if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"').replace(/\<p/gi, '<p class="stem-rich-p"')
            })
          }
          // 获取图片
          if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') {
@@ -703,19 +817,20 @@
          })
          this.setData({
            questionDataList: questionList,
            cardList: cardUpdatedList
            cardList: cardUpdatedList,
          })
        })
      })
    })
    }
    // 有题目再开始倒计时
    if (this.data.questionDataList.length) this.startCountdown()
    this.setData({
      loading: false,
      loading: false
    })
  },
  // 批改题目 (练习,我的错题,我的收藏)
  handleQuestion(num) {
  // 批改题目 (练习,我的错题,我的收藏,,组卷)
  handleQuestion(index) {
    const questionList = this.data.questionDataList
    const index = num - 1 >= 0 ? num - 1 : 0
    if (questionList[index].isComplete) {
      // 题目已完成,跳过
      return true
@@ -743,7 +858,17 @@
      // 简答 翻译
      questionList[index].isRight = null
    } else if (item.questionType == 'completion') {
      // 填空
      if (item.answer == 'string') {
        item.isRight = item.answer == item.userAnswer[0]
      } else {
        if (item.answer.length != item.userAnswer.length) {
          item.isRight = false
        } else {
          item.isRight = item.answer.every(
            (value, index) => value === item.userAnswer[index]
          )
        }
      }
      // subjectiveGrade.value += item.score
      if (typeof item.answer == 'string') {
        questionList[index].isRight = item.answer == item.userAnswer[0]
@@ -788,13 +913,11 @@
      // 记录错题
      app.MG.identity
        .setUserKey({
          setKeyRequests: [
            {
              domain: 'errorData',
              key: this.data.rootCmsItemId,
              value: JSON.stringify(this.data.errorList)
            }
          ]
          setKeyRequests: [{
            domain: 'errorData',
            key: this.data.rootCmsItemId,
            value: JSON.stringify(this.data.errorList)
          }]
        })
        .then((res) => {
          console.log(res)
@@ -850,27 +973,23 @@
    }
    app.MG.identity
      .setUserKey({
        setKeyRequests: [
          {
            domain: 'collectData',
            key: this.data.rootCmsItemId,
            value: JSON.stringify(this.data.collectList)
          }
        ]
        setKeyRequests: [{
          domain: 'collectData',
          key: this.data.rootCmsItemId,
          value: JSON.stringify(this.data.collectList)
        }]
      })
      .then((res) => { })
      .then((res) => {})
  },
  // 处理答题数据
  recordAnswerData() {
    this.data.cardList.push(
      {
        name: '客观题得分',
        score: this.data.subjectiveNum,
        path: this.data.productLinkPath,
        // infoList: [],
        // catalogName: ''
      }
    )
    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))
@@ -897,15 +1016,13 @@
  setAnswerInfo(data) {
    app.MG.identity
      .setUserKey({
        setKeyRequests: [
          {
            domain: 'answerData',
            key: this.data.productLinkPath,
            value: JSON.stringify(data)
          }
        ]
        setKeyRequests: [{
          domain: 'answerData',
          key: this.data.productLinkPath,
          value: JSON.stringify(data)
        }]
      })
      .then((res) => { })
      .then((res) => {})
  },
  // 获取答题数据
  getAnswerInfo(callback) {
@@ -942,8 +1059,7 @@
            collectList: JSON.parse(res[0].value)
          })
          // total.value = collectList.value.length
        } catch (error) {
        }
        } catch (error) {}
        if (this.data.collectList && this.data.collectList.length) {
          await this.getCollectDataList()
        } else {
@@ -952,8 +1068,8 @@
          })
          wx.showModal({
            title: '提示',
            content: '收藏夹暂无数据',//editable如果为true,这就是输入框的内容
            editable: false,//是否显示输入框
            content: '收藏夹暂无数据', //editable如果为true,这就是输入框的内容
            editable: false, //是否显示输入框
            showCancel: false,
            success: (res) => {
              if (res.confirm) {
@@ -971,14 +1087,35 @@
  // 获取收藏夹
  async getCollectDataList() {
    let questionArr = []
    // this.setData({
    //   cardList: [{
    //     catalogName: '收藏夹',
    //     infoList: []
    //   }]
    // })
    this.setData({
      cardList: [
        {
          catalogName: '收藏夹',
          infoList: []
        }
      ]
      cardList: [{
        catalogName: '单选题',
        infoList: []
      }, {
        catalogName: '判断题',
        infoList: []
      }, {
        catalogName: '多选题',
        infoList: []
      }, {
        catalogName: '填空题',
        infoList: []
      }, {
        catalogName: '简答题',
        infoList: []
      }]
    })
    let singleChoiceArr = [] // 单选
    let judgeArr = [] // 判断
    let shortArr = [] // 简答
    let multipleChoiceArr = [] // 多选
    let completionArr = [] // 填空
    let query = {
      path: '*',
      cmsPath: this.data.rootCmsItemId,
@@ -1004,28 +1141,21 @@
        const questionObj = {
          number: index + 1, // 题号
          id: item.id,
          stem:
            item.Embedded_QuestionBank_QuestionType == 'completion'
              ? JSON.parse(item.Embedded_QuestionBank_Stem)
                .stemTxt.replaceAll('<vacancy>', ',input,')
                .split(',')
              : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
          stem: item.Embedded_QuestionBank_QuestionType == 'completion' ?
            JSON.parse(item.Embedded_QuestionBank_Stem)
            .stemTxt.replaceAll('<vacancy>', ',input,')
            .split(',') : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
          answer: item.Embedded_QuestionBank_Answer, // 答案
          option: item.Embedded_QuestionBank_Option
            ? JSON.parse(item.Embedded_QuestionBank_Option)
            : '', // 选择题选项
          option: item.Embedded_QuestionBank_Option ?
            JSON.parse(item.Embedded_QuestionBank_Option) : '', // 选择题选项
          analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 解析
          questionType: item.Embedded_QuestionBank_QuestionType, // 题型
          optionStyle: item.Embedded_QuestionBank_OptionStyle, // 选项显示类型
          stemStyle: item.Embedded_QuestionBank_StemStyle, // 题干显示类型
          difficulty: item.Embedded_QuestionBank_Difficulty
            ? 4 - item.Embedded_QuestionBank_Difficulty
            : 0, // 难度等级
          userAnswer:
            item.Embedded_QuestionBank_QuestionType == 'completion' ||
              item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
              ? []
              : '',
          difficulty: item.Embedded_QuestionBank_Difficulty ?
            4 - item.Embedded_QuestionBank_Difficulty : 0, // 难度等级
          userAnswer: item.Embedded_QuestionBank_QuestionType == 'completion' ||
            item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '',
          isSubmit: false, // 查看解析
          isRight: null, // 是否正确
          isComplete: false,
@@ -1066,25 +1196,61 @@
            if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
          })
        }
        // if (item.Embedded_QuestionBank_QuestionType == 'judge') {
        //   topicList.value.judge.data.push(questionObj)
        // } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
        //   topicList.value.radio.data.push(questionObj)
        // } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
        //   topicList.value.check.data.push(questionObj)
        // } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
        //   topicList.value.gap.data.push(questionObj)
        // } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
        //   topicList.value.short.data.push(questionObj)
        // }
        questionArr.push(questionObj)
        // cardList.value[0].infoList.push(questionObj)
        // 题干富文本处理
        if (questionObj.stemStyle == 'RichText') {
          // questionObj.option.txt = ''
          questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ').replace(/\<p/gi, '<p class="stem-rich-p"')
        }
        // 选项富文本处理
        if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) {
          questionObj.option.forEach(item => {
            if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"').replace(/\<p/gi, '<p class="stem-rich-p"')
          })
        }
        if (item.Embedded_QuestionBank_QuestionType == 'judge') {
          questionObj.type = '判断题'
          judgeArr.push(questionObj)
        } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
          questionObj.type = '单选题'
          singleChoiceArr.push(questionObj)
        } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
          questionObj.type = '多选题'
          multipleChoiceArr.push(questionObj)
        } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
          questionObj.type = '填空题'
          completionArr.push(questionObj)
        } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
          questionObj.type = '简答题'
          shortArr.push(questionObj)
        }
        // questionArr.push(questionObj)
      })
      // loadings.value = false
      // this.setData({
      //   questionDataList: questionArr,
      //   ['cardList[0].infoList']: questionArr,
      //   loading: false,
      // })
      this.setData({
        ['cardList[0].infoList']: singleChoiceArr,
        ['cardList[1].infoList']: judgeArr,
        ['cardList[2].infoList']: multipleChoiceArr,
        ['cardList[3].infoList']: completionArr,
        ['cardList[3].infoList']: shortArr,
      })
      const cardList = this.data.cardList
      for (let index = 0; index < cardList.length; index++) {
        const item = cardList[index];
        for (let cindex = 0; cindex < item.infoList.length; cindex++) {
          const citem = item.infoList[cindex]
          citem.number = cindex + 1
          questionArr.push(citem)
        }
      }
      this.setData({
        questionDataList: questionArr,
        ['cardList[0].infoList']: questionArr,
        loading: false,
        cardList: cardList,
        loading: false
      })
    })
  },
@@ -1100,8 +1266,7 @@
          this.setData({
            errorList: JSON.parse(res[0].value)
          })
        } catch (error) {
        }
        } catch (error) {}
        if (this.data.errorList && this.data.errorList.length) {
          this.getErrorDataList()
        } else {
@@ -1110,8 +1275,8 @@
          })
          wx.showModal({
            title: '提示',
            content: '错题集暂无数据',//editable如果为true,这就是输入框的内容
            editable: false,//是否显示输入框
            content: '错题集暂无数据', //editable如果为true,这就是输入框的内容
            editable: false, //是否显示输入框
            showCancel: false,
            success: (res) => {
              if (res.confirm) {
@@ -1127,14 +1292,35 @@
  },
  // 获取错题集
  async getErrorDataList() {
    // this.setData({
    //   cardList: [{
    //     catalogName: '错题集',
    //     infoList: []
    //   }]
    // })
    this.setData({
      cardList: [
        {
          catalogName: '错题集',
          infoList: []
        }
      ]
      cardList: [{
        catalogName: '单选题',
        infoList: []
      }, {
        catalogName: '判断题',
        infoList: []
      }, {
        catalogName: '多选题',
        infoList: []
      }, {
        catalogName: '填空题',
        infoList: []
      }, {
        catalogName: '简答题',
        infoList: []
      }]
    })
    let singleChoiceArr = [] // 单选
    let judgeArr = [] // 判断
    let shortArr = [] // 简答
    let multipleChoiceArr = [] // 多选
    let completionArr = [] // 填空
    let query = {
      path: '*',
      cmsPath: this.data.rootCmsItemId,
@@ -1160,28 +1346,21 @@
        const questionObj = {
          number: index + 1, // 题号
          id: item.id,
          stem:
            item.Embedded_QuestionBank_QuestionType == 'completion'
              ? JSON.parse(item.Embedded_QuestionBank_Stem)
                .stemTxt.replaceAll('<vacancy>', ',input,')
                .split(',')
              : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
          stem: item.Embedded_QuestionBank_QuestionType == 'completion' ?
            JSON.parse(item.Embedded_QuestionBank_Stem)
            .stemTxt.replaceAll('<vacancy>', ',input,')
            .split(',') : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
          answer: item.Embedded_QuestionBank_Answer, // 答案
          option: item.Embedded_QuestionBank_Option
            ? JSON.parse(item.Embedded_QuestionBank_Option)
            : '', // 选择题选项
          option: item.Embedded_QuestionBank_Option ?
            JSON.parse(item.Embedded_QuestionBank_Option) : '', // 选择题选项
          analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 解析
          questionType: item.Embedded_QuestionBank_QuestionType, // 题型
          optionStyle: item.Embedded_QuestionBank_OptionStyle, // 选项显示类型
          stemStyle: item.Embedded_QuestionBank_StemStyle, // 题干显示类型
          difficulty: item.Embedded_QuestionBank_Difficulty
            ? 4 - item.Embedded_QuestionBank_Difficulty
            : 0, // 难度等级
          userAnswer:
            item.Embedded_QuestionBank_QuestionType == 'completion' ||
              item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
              ? []
              : '',
          difficulty: item.Embedded_QuestionBank_Difficulty ?
            4 - item.Embedded_QuestionBank_Difficulty : 0, // 难度等级
          userAnswer: item.Embedded_QuestionBank_QuestionType == 'completion' ||
            item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '',
          isSubmit: false, // 查看解析
          isRight: null, // 是否正确
          isComplete: false,
@@ -1222,22 +1401,57 @@
            if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
          })
        }
        // if (item.Embedded_QuestionBank_QuestionType == 'judge') {
        //   topicList.value.judge.data.push(questionObj)
        // } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
        //   topicList.value.radio.data.push(questionObj)
        // } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
        //   topicList.value.check.data.push(questionObj)
        // } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
        //   topicList.value.gap.data.push(questionObj)
        // } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
        //   topicList.value.short.data.push(questionObj)
        // }
        questionArr.push(questionObj)
        // 题干富文本处理
        if (questionObj.stemStyle == 'RichText') {
          // questionObj.option.txt = ''
          questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ').replace(/\<p/gi, '<p class="stem-rich-p"')
        }
        // 选项富文本处理
        if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) {
          questionObj.option.forEach(item => {
            if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"').replace(/\<p/gi, '<p class="stem-rich-p"')
          })
        }
        if (item.Embedded_QuestionBank_QuestionType == 'judge') {
          questionObj.type = '判断题'
          judgeArr.push(questionObj)
        } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
          questionObj.type = '单选题'
          singleChoiceArr.push(questionObj)
        } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
          questionObj.type = '多选题'
          multipleChoiceArr.push(questionObj)
        } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
          questionObj.type = '填空题'
          completionArr.push(questionObj)
        } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
          questionObj.type = '简答题'
          shortArr.push(questionObj)
        }
        // questionArr.push(questionObj)
      })
      this.setData({
        // questionDataList: questionArr,
        ['cardList[0].infoList']: singleChoiceArr,
        ['cardList[1].infoList']: judgeArr,
        ['cardList[2].infoList']: multipleChoiceArr,
        ['cardList[3].infoList']: completionArr,
        ['cardList[3].infoList']: shortArr,
        // loading: false
      })
      const cardList = this.data.cardList
      for (let index = 0; index < cardList.length; index++) {
        const item = cardList[index];
        for (let cindex = 0; cindex < item.infoList.length; cindex++) {
          const citem = item.infoList[cindex]
          citem.number = cindex + 1
          questionArr.push(citem)
        }
      }
      this.setData({
        questionDataList: questionArr,
        ['cardList[0].infoList']: questionArr,
        cardList: cardList,
        loading: false
      })
    })
@@ -1276,7 +1490,10 @@
          // 获取必含题目
          let list = item.cmsItemList.map((idItem) => {
            itemIds.push(idItem.id + '')
            questionIds.push({ id: idItem.id + '', score: idItem.score })
            questionIds.push({
              id: idItem.id + '',
              score: idItem.score
            })
            numberIndex++
            return {
              number: numberIndex,
@@ -1290,7 +1507,10 @@
            const extractItem = item.generatorResultList[i]
            let extractItemList = extractItem.cmsItemList.map((extractCmsItem) => {
              itemIds.push(extractCmsItem.id + '')
              questionIds.push({ id: extractCmsItem.id + '', score: extractCmsItem.score })
              questionIds.push({
                id: extractCmsItem.id + '',
                score: extractCmsItem.score
              })
              numberIndex++
              return {
                number: numberIndex,
@@ -1332,9 +1552,9 @@
  },
  // 获取组卷题目列表
  async getMockDataList(questionList, oldList) {
    console.log(questionList, oldList);
    const questionDataList = this.data.questionDataList
    questionList.forEach(async (pathitem, pathindex) => {
    for (let pathindex = 0; pathindex < questionList.length; pathindex++) {
      const pathitem = questionList[pathindex];
      let itemIds = []
      pathitem.infoList.forEach(item => {
        itemIds.push(item.id + '')
@@ -1367,33 +1587,26 @@
            // number: pathitem.infoList.find(infoItem => infoItem.itemId == item.id).number,
            id: item.id,
            score: pathitem.infoList.find(infoItem => infoItem.id == item.id).score,
            stem:
              item.Embedded_QuestionBank_QuestionType == 'completion'
                ? JSON.parse(item.Embedded_QuestionBank_Stem)
                  .stemTxt.replaceAll('<vacancy>', ',input,')
                  .split(',')
                : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
            stem: item.Embedded_QuestionBank_QuestionType == 'completion' ?
              JSON.parse(item.Embedded_QuestionBank_Stem)
              .stemTxt.replaceAll('<vacancy>', ',input,')
              .split(',') : JSON.parse(item.Embedded_QuestionBank_Stem), // 题干
            answer: item.Embedded_QuestionBank_Answer, // 答案
            option: item.Embedded_QuestionBank_Option
              ? JSON.parse(item.Embedded_QuestionBank_Option)
              : '', // 选择题选项
            option: item.Embedded_QuestionBank_Option ?
              JSON.parse(item.Embedded_QuestionBank_Option) : '', // 选择题选项
            analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 解析
            questionType: item.Embedded_QuestionBank_QuestionType, // 题型
            optionStyle: item.Embedded_QuestionBank_OptionStyle, // 选项显示类型
            stemStyle: item.Embedded_QuestionBank_StemStyle, // 题干显示类型
            difficulty: item.Embedded_QuestionBank_Difficulty
              ? 4 - item.Embedded_QuestionBank_Difficulty
              : 0, // 难度等级
            userAnswer: oldObj
              ? oldObj.answer
              : item.Embedded_QuestionBank_QuestionType == 'completion' ||
                item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
                ? []
                : '',
            difficulty: item.Embedded_QuestionBank_Difficulty ?
              4 - item.Embedded_QuestionBank_Difficulty : 0, // 难度等级
            userAnswer: oldObj ?
              oldObj.answer : item.Embedded_QuestionBank_QuestionType == 'completion' ||
              item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '',
            isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false,
            isRight: oldObj ? oldObj.isRight : null,
            // isComplete: oldObj ? oldObj.isComplete : false,
            isComplete: this.data.mockData.state == '3' ? true : oldObj ? this.isHaveAnswer(oldObj.answer) : false,
            isComplete: this.data.mockData.state == '3' ? true : false,
            isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false,
            isUnfold: '' // 控制解析的折叠面板是否展开
          }
@@ -1423,6 +1636,17 @@
              }
            }
          }
          // 题干富文本处理
          if (questionObj.stemStyle == 'RichText') {
            // questionObj.option.txt = ''
            questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img"')
          }
          // 选项富文本处理
          if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) {
            questionObj.option.forEach(item => {
              if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"')
            })
          }
          // 获取图片
          if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') {
            questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
@@ -1451,7 +1675,6 @@
          })
          let questionList = []
          const cardUpdatedList = this.data.cardList
          // if (flag == this.data.idPathList.length) {
          cardUpdatedList.forEach(aitem => {
            aitem.infoList.forEach((bitem, bindex) => {
              questionList.push(bitem)
@@ -1464,9 +1687,8 @@
          })
        })
      })
    })
    }
    this.setData({
      // questionDataList: questionDataList,
      loading: false
    })
  },
@@ -1484,26 +1706,22 @@
  // 记录购买组卷时间
  setMockInfo(data) {
    app.MG.identity.setUserKey({
      setKeyRequests: [
        {
          domain: 'mockData',
          key: this.data.bookId + '',
          value: JSON.stringify(data)
        }
      ]
      setKeyRequests: [{
        domain: 'mockData',
        key: this.data.bookId + '',
        value: JSON.stringify(data)
      }]
    })
  },
  // 记录组卷题目列表
  saveMockQuestionList(data) {
    app.MG.identity
      .setUserKey({
        setKeyRequests: [
          {
            domain: 'mockQuestionData',
            key: this.data.uuid,
            value: JSON.stringify(data)
          }
        ]
        setKeyRequests: [{
          domain: 'mockQuestionData',
          key: this.data.uuid,
          value: JSON.stringify(data)
        }]
      })
      .then((res) => {
        console.log('模考题目列表已记录')
@@ -1577,17 +1795,15 @@
    // 
    app.MG.identity
      .setUserKey({
        setKeyRequests: [
          {
            domain: 'mockAnswerData',
            key: this.data.uuid,
            value: JSON.stringify({
              currentIndex: this.data.currentIndex,
              time: this.data.countdownTime,
              answerData: saveData
            })
          }
        ]
        setKeyRequests: [{
          domain: 'mockAnswerData',
          key: this.data.uuid,
          value: JSON.stringify({
            currentIndex: this.data.currentIndex,
            time: this.data.countdownTime,
            answerData: saveData
          })
        }]
      })
      .then((res) => {
        this.setData({
@@ -1595,5 +1811,30 @@
        })
        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;
  }
})