From 18d886c2f23dc5c032ebcf42bbb39c739d908a4f Mon Sep 17 00:00:00 2001 From: litian <2804272236@qq.com> Date: 星期二, 05 十一月 2024 15:49:51 +0800 Subject: [PATCH] Merge branch 'master' of http://182.92.203.7:2001/r/TextbookReader --- src/views/examination/index.vue | 381 ++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 294 insertions(+), 87 deletions(-) diff --git a/src/views/examination/index.vue b/src/views/examination/index.vue index 5d79051..6499ea5 100644 --- a/src/views/examination/index.vue +++ b/src/views/examination/index.vue @@ -74,8 +74,9 @@ <div class="resolving-btn" @click="showCollaspe('noshow')" v-else>銆愭敹璧疯В鏋愩��</div> </div> <!-- <div @click="clearCollect">娓呯┖鏀惰棌</div> --> + <!-- <div @click="clearError">娓呯┖閿欓</div> --> <div class="redo-btn" @click="restart"> - <img src="@/assets/images/examination/chongzuo.png" alt=""> + <img src="@/assets/images/examination/chongzuo.png" alt="" /> <span>閲嶅仛</span> </div> </div> @@ -95,6 +96,7 @@ <script setup lang="ts"> import { ref, reactive, defineExpose, defineProps, inject } from 'vue' +import axios from 'axios' import { getPublicImage } from '@/assets/js/middleGround/tool.js' import { requestCtx } from '@/assets/js/config.js' import { ElMessageBox } from 'element-plus' @@ -143,15 +145,16 @@ } // 寮圭獥寮圭獥鎸夐挳 const closeDialog = () => { - if(props.type =='option') { - if(!examination.submitStatus) { - ElMessageBox.confirm('鏈彁浜わ紝鏄惁閫�鍑虹瓟棰�', '鎻愮ず', { + if (props.type == 'option') { + if (!examination.submitStatus) { + ElMessageBox.confirm('鏈彁浜わ紝鏄惁閫�鍑虹瓟棰�', '鎻愮ず', { confirmButtonText: '纭', cancelButtonText: '鍙栨秷', autofocus: false, type: 'warning' }).then(() => { examination.dialogVisible = false + saveAnswerData() examination.cardList = [] }) } else { @@ -160,10 +163,12 @@ } } else { examination.dialogVisible = false - handleQuestion() + // handleQuestion() + if(props.type == 'errorQuestion') { + handleQuestion() + } examination.cardList = [] } - } // 寮�鍏冲脊绐楁柟娉� const handleExaminationDialog = (type: boolean) => { @@ -190,6 +195,7 @@ } else if (props.type == 'errorQuestion') { examination.submitStatus = true await getErrorIdList() + getCollectIdList() } } // 閲嶅仛 @@ -204,7 +210,7 @@ examination.loading = true examination.submitStatus = false examination.cardList = [] - examination.collectList = [] + // examination.collectList = [] examination.errorList = [] goTop() if (props.type == 'option') { @@ -286,21 +292,42 @@ const setCollect = (num: number, number: number) => { const item = examination.cardList[num].infoList[number] item.isCollect = !item.isCollect - console.log(item) - if (examination.collectList.length == 0) { - examination.collectList.push(item.id) + if (item.isJson) { + // json棰樼洰鏀惰棌鍙栨秷 + let jsonCollectID = examination.allCollect[1].collectList + if (jsonCollectID.length == 0) { + jsonCollectID.push(item.id) + } else { + const isShow = jsonCollectID.findIndex((citem) => citem == item.id) + if (isShow == -1) { + jsonCollectID.push(item.id) + } else { + jsonCollectID = jsonCollectID.filter((citem) => citem != item.id) + } + } + for (let index = 0; index < examination.allCollect.length; index++) { + const item = examination.allCollect[index] + if (item.type == 'json') item.collectList = jsonCollectID + } } else { - const isShow = examination.collectList.findIndex((citem) => citem == item.id) - if (isShow == -1) { + // bits棰樼洰鏀惰棌/鍙栨秷 + if (examination.collectList.length == 0) { examination.collectList.push(item.id) } else { - examination.collectList = examination.collectList.filter((citem) => citem != item.id) + const isShow = examination.collectList.findIndex((citem) => citem == item.id) + if (isShow == -1) { + examination.collectList.push(item.id) + } else { + examination.collectList = examination.collectList.filter((citem) => citem != item.id) + } + } + for (let index = 0; index < examination.allCollect.length; index++) { + const item = examination.allCollect[index] + if (item.type == 'bits') item.collectList = examination.collectList } } - for (let index = 0; index < examination.allCollect.length; index++) { - const item = examination.allCollect[index] - if (item.type == 'bits') item.collectList = examination.collectList - } + console.log('鏀惰棌杩樻槸鍙栨秷', examination.allCollect) + MG.identity .setUserKey({ setKeyRequests: [ @@ -322,35 +349,39 @@ 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 let value = JSON.parse(res[0].value) if (value) { - console.log('鏃ф暟鎹�', value) // 鏈夌瓟棰樿褰�,鎼哄甫鏃ф暟鎹幏鍙栭鐩� examination.cardList = (await getQuestionList(value)) as any } } else { - examination.cardList = (await getQuestionList([])) as any + const userAnswerList = await getUserAnswer() + if(userAnswerList) { + examination.cardList = (await getQuestionList(userAnswerList)) as any + } else { + examination.cardList = (await getQuestionList([])) as any + } } }) } @@ -437,8 +468,6 @@ Embedded_QuestionBank_Difficulty: [] } } - console.log('璇锋眰鏃ヂ�', examination.collectList) - const res = await MG.store.getProductDetail(query) if (!res.datas) return false res.datas.cmsDatas[0].datas.forEach((item, index) => { @@ -474,7 +503,7 @@ : '', isSubmit: false, // 鏌ョ湅瑙f瀽 isRight: oldObj ? oldObj.isRight : null, // 鏄惁姝g‘ - isComplete: oldObj ? true : false, + isComplete: examination.submitStatus, isCollect: examination.collectList.indexOf(item.id) > -1 ? true : false, isUnfold: '' } @@ -595,37 +624,48 @@ 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) {} - if (examination.collectList && examination.collectList.length > 0) { + if ( + examination.allCollect[0].collectList.length || + examination.allCollect[1].collectList.length + ) { examination.cardList = (await getCollectDataList()) as any + await getJsonCollect() } else { examination.loading = false examination.noData = true + ElMessageBox.confirm('鏀惰棌澶规殏鏃犳暟鎹�!', '鎻愮ず', { + confirmButtonText: '纭畾', + showCancelButton: false, + type: 'warning' + }) + .then(() => { + examination.submitStatus = true + examination.dialogVisible = false + }) + .catch(() => { + examination.dialogVisible = false + }) } }) } // 鑾峰彇鏀惰棌澶� 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: '鍗曢�夐', @@ -648,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] @@ -746,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) }) } @@ -768,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"') @@ -823,7 +863,51 @@ } } examination.loading = false - return cardList.filter((item) => item.infoList.length > 0) + return cardList +} +// 鎴戠殑鏀惰棌妯″紡涓嬶紝鑾峰彇鏀惰棌鐨勫亣棰�(json) +const getJsonCollect = async () => { + if (!props.activeBook.jsonQUestion) { + examination.cardList = examination.cardList.filter((item) => item.infoList.length > 0) + return false + } + let questionArr = [] + let jsonCollectList = [] + for (let index = 0; index < props.activeBook.jsonQUestion.length; index++) { + const item = props.activeBook.jsonQUestion[index] + const res = await axios.get(props.activeBook.resourceUrl + '/question-' + item + '.json') + questionArr.push(...res.data.data) + } + for (let index = 0; index < questionArr.length; index++) { + const item = questionArr[index] + for (let cindex = 0; cindex < examination.allCollect[1].collectList.length; cindex++) { + const citem = examination.allCollect[1].collectList[cindex] + if (item.id == citem) { + item.isCollect = true + item.isJson = true + jsonCollectList.push(item) + } + } + } + + for (let index = 0; index < jsonCollectList.length; index++) { + const item = jsonCollectList[index] + if (item.questionType == 'singleChoice') { + examination.cardList[0].infoList.push(item) + } else if (item.questionType == 'judge') { + examination.cardList[1].infoList.push(item) + } else if (item.questionType == 'multipleChoice') { + examination.cardList[2].infoList.push(item) + } else if (item.questionType == 'completion') { + 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) + console.log('鎷兼帴棰�', examination.cardList) } // 鎴戠殑閿欓妯″紡涓嬭幏鍙栭敊棰榠d鍒楄〃 const getErrorIdList = async () => { @@ -832,22 +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) { - examination.errorList = error.find((citem) => citem.type == 'bits').errorList - examination.allCollect[0].collectList = error.find( - (citem) => citem.type == 'bits' - ).errorList - examination.allCollect[1].collectList = error.find( - (citem) => citem.type == 'json' - ).errorList + console.log('鏈夊悧', error) + 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.errorList && examination.errorList.length) { + 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: '纭畾', @@ -856,21 +939,18 @@ }) .then(() => { examination.submitStatus = true + examination.dialogVisible = false }) - .catch(() => {}) + .catch(() => { + examination.dialogVisible = false + }) } }) } // 鑾峰彇閿欓闆� 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: '鍗曢�夐', @@ -893,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] @@ -923,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, // 棰樺彿 @@ -991,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) }) } @@ -1013,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"') @@ -1068,10 +1148,53 @@ } } examination.loading = false - return cardList.filter((item) => item.infoList.length > 0) + return cardList +} +// 閿欓闆嗘ā寮忎笅锛岃幏鍙栧亣鐨勯敊棰�(json) +const getJsonError = async () => { + if (!props.activeBook.jsonQUestion) { + examination.cardList = examination.cardList.filter((item) => item.infoList.length > 0) + return false + } + let questionArr = [] + let jsonCollectList = [] + for (let index = 0; index < props.activeBook.jsonQUestion.length; index++) { + const item = props.activeBook.jsonQUestion[index] + const res = await axios.get(props.activeBook.resourceUrl + '/question-' + item + '.json') + questionArr.push(...res.data.data) + } + for (let index = 0; index < questionArr.length; index++) { + const item = questionArr[index] + for (let cindex = 0; cindex < examination.allError[1].errorList.length; cindex++) { + const citem = examination.allError[1].errorList[cindex] + if (item.id == citem) { + item.isCollect = examination.allCollect[1].collectList.indexOf(item.id) > -1 ? true :false + item.isJson = true + jsonCollectList.push(item) + } + } + } + + for (let index = 0; index < jsonCollectList.length; index++) { + const item = jsonCollectList[index] + if (item.questionType == 'singleChoice') { + examination.cardList[0].infoList.push(item) + } else if (item.questionType == 'judge') { + examination.cardList[1].infoList.push(item) + } else if (item.questionType == 'multipleChoice') { + examination.cardList[2].infoList.push(item) + } else if (item.questionType == 'completion') { + 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) } // 鎵规敼棰樼洰 (缁冧範,鎴戠殑鍋氶,鎴戠殑鏀惰棌妯″紡涓�) -const handleQuestion = () => { +const handleQuestion = () => { for (let index = 0; index < examination.cardList.length; index++) { const item = examination.cardList[index] for (let cindex = 0; cindex < item.infoList.length; cindex++) { @@ -1108,16 +1231,34 @@ } } if (!citem.isRight && citem.questionType != 'shortAnswer') { + // 瀹㈣棰樺洖绛旈敊璇� 璁板綍閿欓 - if (examination.errorList.findIndex((errorItem) => errorItem == citem.id) == -1) { - examination.errorList.push(citem.id) + if (citem.isJson) { + if ( + examination.allError[1].errorList.findIndex((erroritem) => erroritem == citem.id) == -1 + ) { + examination.allError[1].errorList.push(citem.id) + } + } else { + if (examination.errorList.findIndex((errorItem) => errorItem == citem.id) == -1) { + examination.errorList.push(citem.id) + } } } else { if (props.type == 'errorQuestion' || props.type == 'option') { // 浠庨敊棰橀泦涓Щ闄� - let index = examination.errorList.findIndex((erroritem) => erroritem == citem.id) - if (index > -1) { - examination.errorList.splice(index, 1) + if (citem.isJson) { + let index = examination.allError[1].errorList.findIndex( + (erroritem) => erroritem == citem.id + ) + if (index > -1) { + examination.allError[1].errorList.splice(index, 1) + } + } else { + let index = examination.errorList.findIndex((erroritem) => erroritem == citem.id) + if (index > -1) { + examination.errorList.splice(index, 1) + } } } } @@ -1135,12 +1276,14 @@ } ] }) - .then((res) => { + .then((res:any) => { console.log('閿欓宸蹭繚瀛�', examination.allError) }) if (props.type == 'option') { recordAnswerData() } + console.log('鎻愪氦閿欓',examination.errorList,examination.allError); + } // 澶勭悊绛旈鏁版嵁 const recordAnswerData = () => { @@ -1159,14 +1302,63 @@ console.log('淇濆瓨鐨勬暟鎹�', infoData) setAnswerInfo(infoData) } -// 鑾峰彇鐢ㄦ埛鏃х瓟棰樻暟鎹� -const getAnswerInfo = (callback) => { +// 鏈彁浜や繚瀛樼瓟妗堟柟娉� +const saveAnswerData = () => { + let arr = [] + for (let index = 0; index < examination.cardList.length; index++) { + const item = examination.cardList[index]; + for (let cindex = 0; cindex < item.infoList.length; cindex++) { + const citem = item.infoList[cindex]; + if(citem.userAnswer && citem.userAnswer.length) { + arr.push({ + id:citem.id, + userAnswer:citem.userAnswer + }) + } + } + } + console.log('鐢ㄦ埛绛旀',arr); + setUserAnswer(arr) +} +// 鏈彁浜ら��鍑虹瓟棰橈紝淇濆瓨鐢ㄦ埛绛旀 +const setUserAnswer = (data:any) => { + MG.identity + .setUserKey({ + setKeyRequests: [ + { + domain: 'beforeAnswerData', + key: props.info.id, + value: JSON.stringify(data) + } + ] + }) + .then((res:any) => { + console.log('鎻愪氦鐢ㄦ埛绛旈鏁版嵁鎴愬姛') + }) +} +// 鑾峰彇鏈彁浜ら��鍑虹瓟棰樼殑鐢ㄦ埛绛旀 + const getUserAnswer = async() => { + let data + await MG.identity + .getUserKey({ + domain: 'beforeAnswerData', + keys: [props.info.id] + }) + .then((res:any) => { + if(res.length) { + data = JSON.parse(res[0].value) + } + }) + return data + } +// 鑾峰彇鐢ㄦ埛鏃х瓟棰樻暟鎹�(鎻愪氦鍚�) +const getAnswerInfo = (callback:any) => { MG.identity .getUserKey({ domain: 'answerData', keys: [props.info.id] }) - .then((res) => { + .then((res:any) => { if (callback) callback(res) }) } @@ -1182,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() }) } @@ -1208,10 +1400,25 @@ } ] }) - .then((res) => { + .then((res:any) => { console.log('鏀惰棌/鍙栨秷鎴愬姛') }) } +const clearError = () => { + MG.identity + .setUserKey({ + setKeyRequests: [ + { + domain: 'errorData', + key: props.activeBook.bookId, + value: JSON.stringify([]) + } + ] + }) + .then((res:any) => { + console.log('閿欓宸叉竻绌�') + }) +} defineExpose({ handleExaminationDialog }) </script> -- Gitblit v1.9.1