闫增涛
2024-11-22 cf4bbfabdd5da60ac78cc43a4febbb7e7d559f92
src/views/examination/index.vue
@@ -85,6 +85,7 @@
              :cardList="examination.cardList"
              @setCollect="setCollect"
              @onChangeRadio="onChangeRadio"
              @onChangeInput="onChangeInput"
            />
          </div>
        </li>
@@ -190,7 +191,7 @@
    getErrorList()
  } else if (props.type == 'collectQuestion') {
    examination.submitStatus = true
    await getcollectId() // 获取收藏题目
    await getcollectId() // 获取收藏题目id
    // 收藏夹
  } else if (props.type == 'errorQuestion') {
    examination.submitStatus = true
@@ -210,7 +211,7 @@
      examination.loading = true
      examination.submitStatus = false
      examination.cardList = []
      examination.collectList = []
      // examination.collectList = []
      examination.errorList = []
      goTop()
      if (props.type == 'option') {
@@ -244,7 +245,7 @@
  } else if (item.questionType == 'singleChoice' || item.questionType == 'judge') {
    // 单选 判断
    item.isRight = item.answer == item.userAnswer
  } else if (item.questionType == 'shortAnswer') {
  } else if (item.questionType == 'shortAnswer' || item.questionType == 'formula') {
    // 简答 翻译
    item.isRight = null
  } else if (item.questionType == 'completion') {
@@ -275,7 +276,7 @@
        citem.isUnfold = ''
        examination.isCollapse = false
      } else {
        citem.questionType == 'shortAnswer' ? (citem.isUnfold = true) : (citem.isUnfold = citem.id)
        citem.questionType == 'shortAnswer' || citem.questionType == 'formula' ? (citem.isUnfold = true) : (citem.isUnfold = citem.id)
        examination.isCollapse = true
      }
    }
@@ -289,8 +290,13 @@
  examination.submitStatus = true
}
// 题目收藏按钮,收藏和取消同一接口,取消数组减去该项id
const setCollect = (num: number, number: number) => {
  const item = examination.cardList[num].infoList[number]
const setCollect = (num: number, number?: number) => {
  let item = null
  if(number) {
   item = examination.cardList[num].infoList[number]
  } else {
    item = examination.cardList[num]
  }
  item.isCollect = !item.isCollect
  if (item.isJson) {
    // json题目收藏取消
@@ -624,16 +630,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 +669,10 @@
}
// 获取收藏夹
const getCollectDataList = async () => {
  if (!examination.collectList.length) {
    examination.loading = false
    examination.noData = true
    return false
  }
  console.log('收藏id',examination.allCollect)
  // 开始请求
  let oldData = null
  let oldList = []
  let oldList:any = []
  let cardList = [
    {
      catalogName: '单选题',
@@ -693,11 +695,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]
@@ -757,7 +759,7 @@
        isSubmit: false, // 查看解析
        isRight: null, // 是否正确
        isComplete: false,
        isCollect: examination.collectList.indexOf(item.id) > -1 ? true : false,
        isCollect: true,
        isUnfold: ''
      }
      // 多选和填空答案肯为数组,要转换JSON格式
@@ -791,7 +793,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 +815,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"')
@@ -894,12 +896,10 @@
      }
    }
  }
  console.log('收藏json',jsonCollectList);
  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)
@@ -907,9 +907,11 @@
      examination.cardList[2].infoList.push(item)
    } else if (item.questionType == 'completion') {
      examination.cardList[3].infoList.push(item)
    } else if (item.questionType == 'shortAnswer') {
    } else if (item.questionType == 'shortAnswer' || item.questionType == 'formula') {
      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)
  console.log('拼接题', examination.cardList)
@@ -935,6 +937,7 @@
        examination.cardList = (await getErrorDataList()) as any
        await getJsonError()
      } else {
        examination.noData = true
        examination.loading = false
        ElMessageBox.confirm('错题集暂无数据!', '提示', {
          confirmButtonText: '确定',
@@ -953,12 +956,6 @@
}
// 获取错题集
const getErrorDataList = async () => {
  if (!examination.errorList.length) {
    examination.loading = false
    examination.noData = true
    return false
  }
  // 开始请求
  let oldData = null
  let oldList:any = []
  let cardList = [
@@ -1138,7 +1135,7 @@
      } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
        questionObj.type = '填空题'
        completionArr.push(questionObj)
      } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
      } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer' ) {
        questionObj.type = '简答题'
        shortArr.push(questionObj)
      }
@@ -1187,9 +1184,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)
@@ -1197,8 +1192,10 @@
      examination.cardList[2].infoList.push(item)
    } else if (item.questionType == 'completion') {
      examination.cardList[3].infoList.push(item)
    } else if (item.questionType == 'shortAnswer') {
    } else if (item.questionType == 'shortAnswer' || item.questionType == 'formula') {
      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)
@@ -1225,7 +1222,7 @@
      } else if (citem.questionType == 'singleChoice' || citem.questionType == 'judge') {
        if (citem.id == '63825') console.log('i', item)
        citem.isRight = citem.answer == citem.userAnswer
      } else if (citem.questionType == 'shortAnswer') {
      } else if (citem.questionType == 'shortAnswer' || item.questionType == 'formula') {
        // 简答 翻译
        citem.isRight = null
      } else if (citem.questionType == 'completion') {
@@ -1240,7 +1237,7 @@
          }
        }
      }
      if (!citem.isRight && citem.questionType != 'shortAnswer') {
      if (!citem.isRight && citem.questionType != 'shortAnswer' && citem.questionType != 'formula') {
        
        // 客观题回答错误 记录错题
        if (citem.isJson) {
@@ -1355,7 +1352,7 @@
      keys: [props.info.id]
    })
    .then((res:any) => {
      if(res) {
      if(res.length) {
        data = JSON.parse(res[0].value)
      }
    })
@@ -1426,9 +1423,12 @@
      ]
    })
    .then((res:any) => {
      console.log('错题已保存', examination.allError)
      console.log('错题已清空')
    })
}
const onChangeInput = (value:any,index:number,cindex:number,dindex:number) => {
  examination.cardList[index].infoList[cindex].userAnswer[dindex] = value
}
defineExpose({ handleExaminationDialog })
</script>