| | |
| | | import { activeBook } from "@/assets/js/config"; |
| | | import MG from "@/assets/js/middleGround/WebMiddleGroundApi"; |
| | | import getPublicImage from '@/assets/js/middleGround/tool' |
| | | const getQuestionList = (questionList) => { |
| | | let questionArr = []; |
| | | import {tokenKey} from '@/assets/js/config' |
| | | import getPublicImage from "@/assets/js/middleGround/tool"; |
| | | // 获取题目列表 |
| | | const getQuestionList = async (page, questionList, activeBook) => { |
| | | const token = localStorage.getItem(tokenKey) |
| | | let collectList = [] |
| | | if(token) collectList = await getCollectList(activeBook) |
| | | const oldAnswerData = localStorage.getItem(activeBook.name + "oldAnswerData"); |
| | | let oldData = null; |
| | | let oldList = []; |
| | | if (oldAnswerData) { |
| | | oldData = JSON.parse(oldAnswerData); |
| | | } |
| | | if (oldData && oldData[page]) { |
| | | oldList = oldData[page]; |
| | | } |
| | | let cardList = [ |
| | | { |
| | | catalogName: "单选题", |
| | |
| | | let shortArr = []; // 简答 |
| | | let multipleChoiceArr = []; // 多选 |
| | | let completionArr = []; // 填空 |
| | | // 11 |
| | | for (let qindex = 0; qindex < questionList.length; qindex++) { |
| | | const qitem = questionList[qindex]; |
| | | let query = { |
| | | storeInfo: activeBook.storeRefcode, |
| | | path: "*", |
| | | cmsPath: activeBook.rootCmsItemId, |
| | | cmsType: "*", |
| | |
| | | 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, // 解析 |
| | | 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, // 查看解析 |
| | | isRight: null, // 是否正确 |
| | | 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); |
| | | if (!res.datas) return false; |
| | | res.datas.cmsDatas[0].datas.forEach((item, index) => { |
| | | let oldObj = {}; |
| | | if (oldList) { |
| | | oldObj = oldList.find((item) => item.id == qitem); |
| | | } |
| | | 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, // 解析 |
| | | 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: oldObj |
| | | ? oldObj.userAnswer |
| | | : item.Embedded_QuestionBank_QuestionType == "completion" || |
| | | item.Embedded_QuestionBank_QuestionType == "multipleChoice" |
| | | ? [] |
| | | : "", |
| | | isSubmit: false, // 查看解析 |
| | | isRight: null, // 是否正确 |
| | | isComplete: false, |
| | | isCollect: collectList.indexOf(qitem) > -1 ? true : false, |
| | | 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'); |
| | | }); |
| | | } |
| | | // 解析富文本处理 |
| | | 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", process.env.VUE_APP_API_URL + "/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", process.env.VUE_APP_API_URL + "/file"); |
| | | }); |
| | | } |
| | | // 解析富文本处理 |
| | | 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, |
| | | cardList[1].infoList = judgeArr |
| | | cardList[2].infoList = multipleChoiceArr |
| | | cardList[3].infoList = completionArr |
| | | cardList[4].infoList = shortArr |
| | | // 22 |
| | | cardList[0].infoList = singleChoiceArr; |
| | | cardList[1].infoList = judgeArr; |
| | | cardList[2].infoList = multipleChoiceArr; |
| | | cardList[3].infoList = completionArr; |
| | | cardList[4].infoList = shortArr; |
| | | for (let index = 0; index < cardList.length; index++) { |
| | | const item = cardList[index]; |
| | | for (let cindex = 0; cindex < item.infoList.length; cindex++) { |
| | | const citem = item.infoList[cindex]; |
| | | citem.number = cindex + 1; |
| | | questionArr.push(citem); |
| | | } |
| | | } |
| | | return cardList |
| | | return cardList.filter((item) => item.infoList.length > 0); |
| | | }; |
| | | // 获取收藏列表 |
| | | const getCollectList = async(activeBook) => { |
| | | const allCollect = [ |
| | | { |
| | | type:'bits', |
| | | collectList:[] |
| | | }, |
| | | { |
| | | type:'json', |
| | | collectList:[] |
| | | }, |
| | | ] |
| | | await MG.identity |
| | | .getUserKey({ |
| | | domain: 'collectData', |
| | | keys: [activeBook.bookId] |
| | | }) |
| | | .then((res) => { |
| | | try { |
| | | const collect = JSON.parse(res[0].value) |
| | | if (collect.length) { |
| | | allCollect[0].collectList = collect.find( |
| | | (citem) => citem.type == 'bits' |
| | | ).collectList |
| | | allCollect[1].collectList = collect.find( |
| | | (citem) => citem.type == 'json' |
| | | ).collectList |
| | | } |
| | | } catch (error) { |
| | | console.log('暂无数据') |
| | | } |
| | | }) |
| | | .catch(() => { |
| | | console.log('获取收藏报错'); |
| | | }) |
| | | console.log('收藏数据',allCollect.find(item => item.type == 'bits').collectList) |
| | | return allCollect.find(item => item.type == 'bits').collectList |
| | | } |
| | | const getQuestionData = async (chapter, chapterData, activeBook) => { |
| | | const data = { ...chapterData }; |
| | | const oldAnswerData = localStorage.getItem("oldAnswerData"); |
| | | const oldData = oldAnswerData ? JSON.parse(oldAnswerData) : {}; |
| | | let oldChapterData; |
| | | if (oldData) { |
| | | oldChapterData = oldData[chapter]; |
| | | } |
| | | for (let key in chapterData) { |
| | | let oldList = []; |
| | | if (oldChapterData) { |
| | | oldList = oldChapterData[key]; |
| | | } |
| | | data[key] = await getQuestionList(oldList, chapterData[key], activeBook); |
| | | } |
| | | return data; |
| | | }; |
| | | |
| | | const getQuestionData = (chapterData) => { |
| | | const data = {...chapterData} |
| | | for(let key in chapterData) { |
| | | data[key] = getQuestionList(chapterData[key]) |
| | | } |
| | | return data |
| | | } |
| | | |
| | | export default getQuestionData; |
| | | export default getQuestionList; |