litian
2024-11-20 621b71bb1cc0dc383db1e4b89c9413bb9925b231
src/views/examination/index.vue
@@ -210,7 +210,7 @@
      examination.loading = true
      examination.submitStatus = false
      examination.cardList = []
      examination.collectList = []
      // examination.collectList = []
      examination.errorList = []
      goTop()
      if (props.type == 'option') {
@@ -349,24 +349,24 @@
      domain: 'collectData',
      keys: [props.activeBook.bookId]
    })
    .then((res) => {
    .then((res:any) => {
      console.log('收藏数据', res)
      try {
        const collect = JSON.parse(res[0].value)
        if (collect.length) {
          examination.collectList = collect.find((citem) => citem.type == 'bits').collectList
          examination.collectList = collect.find((citem:any) => citem.type == 'bits').collectList
          examination.allCollect[0].collectList = collect.find(
            (citem) => citem.type == 'bits'
            (citem:any) => citem.type == 'bits'
          ).collectList
          examination.allCollect[1].collectList = collect.find(
            (citem) => citem.type == 'json'
            (citem:any) => citem.type == 'json'
          ).collectList
        }
      } catch (error) {
        console.log('暂无数据')
      }
      if (props.type == 'option') {
        getAnswerInfo(async (res) => {
        getAnswerInfo(async (res:any) => {
          if (res.length) {
            // 有记录,不能答题,状态设为已提交
            examination.submitStatus = true
@@ -624,16 +624,16 @@
      domain: 'collectData',
      keys: [props.activeBook.bookId]
    })
    .then(async (res) => {
    .then(async (res:any) => {
      try {
        const collect = JSON.parse(res[0].value)
        if (collect.length) {
          examination.collectList = collect.find((citem) => citem.type == 'bits').collectList
          examination.collectList = collect.find((citem:any) => citem.type == 'bits').collectList
          examination.allCollect[0].collectList = collect.find(
            (citem) => citem.type == 'bits'
            (citem:any) => citem.type == 'bits'
          ).collectList
          examination.allCollect[1].collectList = collect.find(
            (citem) => citem.type == 'json'
            (citem:any) => citem.type == 'json'
          ).collectList
        }
      } catch (error) {}
@@ -663,14 +663,9 @@
}
// 获取收藏夹
const getCollectDataList = async () => {
  if (!examination.collectList.length) {
    examination.loading = false
    examination.noData = true
    return false
  }
  // 开始请求
  let oldData = null
  let oldList = []
  let oldList:any = []
  let cardList = [
    {
      catalogName: '单选题',
@@ -693,11 +688,11 @@
      infoList: []
    }
  ]
  let singleChoiceArr = [] // 单选
  let judgeArr = [] // 判断
  let shortArr = [] // 简答
  let multipleChoiceArr = [] // 多选
  let completionArr = [] // 填空
  let singleChoiceArr:any = [] // 单选
  let judgeArr:any = [] // 判断
  let shortArr:any = [] // 简答
  let multipleChoiceArr:any = [] // 多选
  let completionArr:any = [] // 填空
  // 11
  for (let qindex = 0; qindex < examination.collectList.length; qindex++) {
    const qitem = examination.collectList[qindex]
@@ -791,7 +786,7 @@
        questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
      }
      if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') {
        questionObj.option.forEach((optionItem) => {
        questionObj.option.forEach((optionItem:any) => {
          if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
        })
      }
@@ -813,7 +808,7 @@
          questionObj.questionType == 'judge' ||
          questionObj.questionType == 'multipleChoice')
      ) {
        questionObj.option.forEach((item) => {
        questionObj.option.forEach((item:any) => {
          if (item.txt)
            item.txt = item.txt
              .replace(/\<img/gi, '<img class="option-rich-img"')
@@ -897,9 +892,7 @@
  for (let index = 0; index < jsonCollectList.length; index++) {
    const item = jsonCollectList[index]
    if (item.type && item.type == 'material') {
      examination.cardList.push(item)
    } else if (item.questionType == 'singleChoice') {
  if (item.questionType == 'singleChoice') {
      examination.cardList[0].infoList.push(item)
    } else if (item.questionType == 'judge') {
      examination.cardList[1].infoList.push(item)
@@ -909,6 +902,8 @@
      examination.cardList[3].infoList.push(item)
    } else if (item.questionType == 'shortAnswer') {
      examination.cardList[4].infoList.push(item)
    } else if (item.type && item.type == 'material') {
      examination.cardList[examination.cardList.length] = item
    }
  }
  examination.cardList = examination.cardList.filter((item) => item.infoList.length > 0)
@@ -921,20 +916,21 @@
      domain: 'errorData',
      keys: [props.activeBook.bookId]
    })
    .then(async (res) => {
    .then(async (res:any) => {
      try {
        const error = JSON.parse(res[0].value)
        if (error.length) {
          console.log('有吗', error)
          examination.errorList = error.find((citem) => citem.type == 'bits').errorList
          examination.allError[0].errorList = error.find((citem) => citem.type == 'bits').errorList
          examination.allError[1].errorList = error.find((citem) => citem.type == 'json').errorList
          examination.errorList = error.find((citem:any) => citem.type == 'bits').errorList
          examination.allError[0].errorList = error.find((citem:any) => citem.type == 'bits').errorList
          examination.allError[1].errorList = error.find((citem:any) => citem.type == 'json').errorList
        }
      } catch (error) {}
      if (examination.allError[0].errorList || examination.allError[1].errorList) {
        examination.cardList = (await getErrorDataList()) as any
        await getJsonError()
      } else {
        examination.noData = true
        examination.loading = false
        ElMessageBox.confirm('错题集暂无数据!', '提示', {
          confirmButtonText: '确定',
@@ -953,14 +949,8 @@
}
// 获取错题集
const getErrorDataList = async () => {
  if (!examination.errorList.length) {
    examination.loading = false
    examination.noData = true
    return false
  }
  // 开始请求
  let oldData = null
  let oldList = []
  let oldList:any = []
  let cardList = [
    {
      catalogName: '单选题',
@@ -983,11 +973,11 @@
      infoList: []
    }
  ]
  let singleChoiceArr = [] // 单选
  let judgeArr = [] // 判断
  let shortArr = [] // 简答
  let multipleChoiceArr = [] // 多选
  let completionArr = [] // 填空
  let singleChoiceArr:any = [] // 单选
  let judgeArr:any = [] // 判断
  let shortArr:any = [] // 简答
  let multipleChoiceArr:any = [] // 多选
  let completionArr:any = [] // 填空
  // 11
  for (let qindex = 0; qindex < examination.errorList.length; qindex++) {
    const qitem = examination.errorList[qindex]
@@ -1013,10 +1003,10 @@
    }
    const res = await MG.store.getProductDetail(query)
    if (!res.datas) return false
    res.datas.cmsDatas[0].datas.forEach((item, index) => {
    res.datas.cmsDatas[0].datas.forEach((item:any, index:number) => {
      let oldObj = {}
      if (oldList) {
        oldObj = oldList.find((item) => item.id == qitem)
        oldObj = oldList.find((item:any) => item.id == qitem)
      }
      const questionObj = {
        number: index + 1, // 题号
@@ -1081,7 +1071,7 @@
        questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
      }
      if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') {
        questionObj.option.forEach((optionItem) => {
        questionObj.option.forEach((optionItem:any) => {
          if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
        })
      }
@@ -1103,7 +1093,7 @@
          questionObj.questionType == 'judge' ||
          questionObj.questionType == 'multipleChoice')
      ) {
        questionObj.option.forEach((item) => {
        questionObj.option.forEach((item:any) => {
          if (item.txt)
            item.txt = item.txt
              .replace(/\<img/gi, '<img class="option-rich-img"')
@@ -1187,9 +1177,7 @@
  for (let index = 0; index < jsonCollectList.length; index++) {
    const item = jsonCollectList[index]
    if (item.type && item.type == 'material') {
      examination.cardList.push(item)
    } else if (item.questionType == 'singleChoice') {
    if (item.questionType == 'singleChoice') {
      examination.cardList[0].infoList.push(item)
    } else if (item.questionType == 'judge') {
      examination.cardList[1].infoList.push(item)
@@ -1199,6 +1187,8 @@
      examination.cardList[3].infoList.push(item)
    } else if (item.questionType == 'shortAnswer') {
      examination.cardList[4].infoList.push(item)
    } else if (item.type && item.type == 'material') {
      examination.cardList[examination.cardList.length] = item
    }
  }
  examination.cardList = examination.cardList.filter((item) => item.infoList.length > 0)
@@ -1286,7 +1276,7 @@
        }
      ]
    })
    .then((res) => {
    .then((res:any) => {
      console.log('错题已保存', examination.allError)
    })
  if (props.type == 'option') {
@@ -1331,7 +1321,7 @@
  setUserAnswer(arr)
}
// 未提交退出答题,保存用户答案
const setUserAnswer = (data) => {
const setUserAnswer = (data:any) => {
  MG.identity
    .setUserKey({
      setKeyRequests: [
@@ -1342,7 +1332,7 @@
        }
      ]
    })
    .then((res) => {
    .then((res:any) => {
      console.log('提交用户答题数据成功')
    })
}
@@ -1354,21 +1344,21 @@
      domain: 'beforeAnswerData',
      keys: [props.info.id]
    })
    .then((res) => {
      if(res) {
    .then((res:any) => {
      if(res.length) {
        data = JSON.parse(res[0].value)
      }
    })
    return data
 }
// 获取用户旧答题数据(提交后)
const getAnswerInfo = (callback) => {
const getAnswerInfo = (callback:any) => {
  MG.identity
    .getUserKey({
      domain: 'answerData',
      keys: [props.info.id]
    })
    .then((res) => {
    .then((res:any) => {
      if (callback) callback(res)
    })
}
@@ -1384,18 +1374,18 @@
        }
      ]
    })
    .then((res) => {
    .then((res:any) => {
      console.log('提交用户答题数据成功')
    })
}
// 删除用户答题数据
const deleteAnswerInfo = (callback) => {
const deleteAnswerInfo = (callback:any) => {
  MG.identity
    .delUserKey({
      domain: 'answerData',
      keys: [props.info.id]
    })
    .then((res) => {
    .then((res:any) => {
      if (callback) callback()
    })
}
@@ -1410,7 +1400,7 @@
        }
      ]
    })
    .then((res) => {
    .then((res:any) => {
      console.log('收藏/取消成功')
    })
}
@@ -1425,8 +1415,8 @@
        }
      ]
    })
    .then((res) => {
      console.log('错题已保存', examination.allError)
    .then((res:any) => {
      console.log('错题已清空')
    })
}
defineExpose({ handleExaminationDialog })