From 34f53c3ca69833ddf0649700d26da9ed91c5f1c3 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期一, 01 七月 2024 17:30:06 +0800
Subject: [PATCH] 题库组件优化

---
 src/views/examination/index.vue |   88 +++++++++++++++++++------------------------
 1 files changed, 39 insertions(+), 49 deletions(-)

diff --git a/src/views/examination/index.vue b/src/views/examination/index.vue
index 58082f3..861ab52 100644
--- a/src/views/examination/index.vue
+++ b/src/views/examination/index.vue
@@ -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
@@ -663,11 +663,6 @@
 }
 // 鑾峰彇鏀惰棌澶�
 const getCollectDataList = async () => {
-  if (!examination.collectList.length) {
-    examination.loading = false
-    examination.noData = true
-    return false
-  }
   // 寮�濮嬭姹�
   let oldData = null
   let oldList = []
@@ -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 })

--
Gitblit v1.9.1