From 96c2e24f915e278e855802f158cf792ac5106c4f Mon Sep 17 00:00:00 2001 From: YM <479443481@qq.com> Date: 星期三, 15 五月 2024 23:09:06 +0800 Subject: [PATCH] 题目 --- src/assets/methods/examination.js | 282 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 141 insertions(+), 141 deletions(-) diff --git a/src/assets/methods/examination.js b/src/assets/methods/examination.js index 53fda61..c993fab 100644 --- a/src/assets/methods/examination.js +++ b/src/assets/methods/examination.js @@ -1,7 +1,7 @@ import { activeBook } from "@/assets/js/config"; import MG from "@/assets/js/middleGround/WebMiddleGroundApi"; import getPublicImage from "@/assets/js/middleGround/tool"; -const getQuestionList = (questionList) => { +const getQuestionList = async (questionList) => { let cardList = [ { catalogName: "鍗曢�夐", @@ -50,147 +50,146 @@ Embedded_QuestionBank_Difficulty: [], }, }; - MG.store.getProductDetail(query).then((res) => { - res.datas.cmsDatas[0].datas.forEach((item, index) => { - 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), // 棰樺共 - answer: item.Embedded_QuestionBank_Answer, // 绛旀 - option: item.Embedded_QuestionBank_Option - ? JSON.parse(item.Embedded_QuestionBank_Option) - : "", // 閫夋嫨棰橀�夐」 - analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽 - 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" - ? [] - : "", - isSubmit: false, // 鏌ョ湅瑙f瀽 - isRight: null, // 鏄惁姝g‘ - isComplete: false, - isCollect: true, - isUnfold: "", - }; - // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 - if ( - questionObj.questionType == "completion" || - questionObj.questionType == "multipleChoice" - ) { - try { - questionObj.answer = JSON.parse(questionObj.answer).toString(); - } catch (error) { - questionObj.answer = item.Embedded_QuestionBank_Answer; + const res = await MG.store.getProductDetail(query); + res.datas.cmsDatas[0].datas.forEach((item, index) => { + 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), // 棰樺共 + answer: item.Embedded_QuestionBank_Answer, // 绛旀 + option: item.Embedded_QuestionBank_Option + ? JSON.parse(item.Embedded_QuestionBank_Option) + : "", // 閫夋嫨棰橀�夐」 + analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽 + 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" + ? [] + : "", + isSubmit: false, // 鏌ョ湅瑙f瀽 + isRight: null, // 鏄惁姝g‘ + isComplete: false, + isCollect: true, + isUnfold: "", + }; + // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡 + if ( + questionObj.questionType == "completion" || + questionObj.questionType == "multipleChoice" + ) { + try { + questionObj.answer = JSON.parse(questionObj.answer).toString(); + } catch (error) { + questionObj.answer = item.Embedded_QuestionBank_Answer; + } + } + // 濉┖棰樻敼閫� + if (questionObj.questionType == "completion") { + let index = 0; + for (let i = 0; i < questionObj.stem.length; i++) { + const item = questionObj.stem[i]; + if (item == "input") { + questionObj.stem[i] = { + num: index, + data: "input", + }; + questionObj.userAnswer[index] = ""; + index++; } } - // 濉┖棰樻敼閫� - if (questionObj.questionType == "completion") { - let index = 0; - for (let i = 0; i < questionObj.stem.length; i++) { - const item = questionObj.stem[i]; - if (item == "input") { - questionObj.stem[i] = { - num: index, - data: "input", - }; - questionObj.userAnswer[index] = ""; - index++; - } - } - } - // 鑾峰彇鍥剧墖 - if ( - questionObj.stemStyle == "Image" || - questionObj.stemStyle == "TxtAndImage" - ) { - questionObj.stem.stemImage = getPublicImage( - questionObj.stem.stemImage, - 150 - ); - } - if ( - questionObj.optionStyle == "Image" || - questionObj.optionStyle == "TxtAndImage" - ) { - questionObj.option.forEach((optionItem) => { - if (optionItem.img) - optionItem.img = getPublicImage(optionItem.img, 150); - }); - } - // 棰樺共瀵屾枃鏈鐞� - 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"') - .replace("../file", app.config.requestCtx + "/file"); - } - // 閫夐」瀵屾枃鏈鐞� - 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"') - .replace("../file", app.config.requestCtx + "/file"); - }); - } - // 瑙f瀽瀵屾枃鏈鐞� - if ( - questionObj.analysisCon && - typeof questionObj.analysisCon == "string" - ) { - questionObj.analysisCon = questionObj.analysisCon.replace( + } + // 鑾峰彇鍥剧墖 + if ( + questionObj.stemStyle == "Image" || + questionObj.stemStyle == "TxtAndImage" + ) { + questionObj.stem.stemImage = getPublicImage( + questionObj.stem.stemImage, + 150 + ); + } + if ( + questionObj.optionStyle == "Image" || + questionObj.optionStyle == "TxtAndImage" + ) { + questionObj.option.forEach((optionItem) => { + if (optionItem.img) + optionItem.img = getPublicImage(optionItem.img, 150); + }); + } + // 棰樺共瀵屾枃鏈鐞� + 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.questionType == 'singleChoice') { - // const src = this.extractSourceSrc(questionObj.stem.stemTxt) - // if (src) { - // questionObj.src = src - // questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt) - // } - // } - 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); - } - }); + ) + .replace(/\<p/gi, '<p class="stem-rich-p"') + .replace("../file", app.config.requestCtx + "/file"); + } + // 閫夐」瀵屾枃鏈鐞� + 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"') + .replace("../file", app.config.requestCtx + "/file"); + }); + } + // 瑙f瀽瀵屾枃鏈鐞� + if ( + questionObj.analysisCon && + typeof questionObj.analysisCon == "string" + ) { + questionObj.analysisCon = questionObj.analysisCon.replace( + /\<img/gi, + '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ' + ); + } + // 鍚姏棰樹慨鏀� + // if (questionObj.questionType == 'singleChoice') { + // const src = this.extractSourceSrc(questionObj.stem.stemTxt) + // if (src) { + // questionObj.src = src + // questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt) + // } + // } + 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); + } }); } cardList[0].infoList = singleChoiceArr, @@ -205,13 +204,14 @@ citem.number = cindex + 1; } } - return cardList; + console.log(cardList.filter(item=>item.infoList.length > 0),"cardList.filter(item=>item.infoList.length > 0)"); + return cardList.filter(item=>item.infoList.length > 0); }; -const getQuestionData = (chapterData) => { +const getQuestionData = async (chapterData) => { const data = { ...chapterData }; for (let key in chapterData) { - data[key] = getQuestionList(chapterData[key]); + data[key] = await getQuestionList(chapterData[key]); } return data; }; -- Gitblit v1.9.1