From 6016198229e16f20be1bf55df64b9f363e27b698 Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期二, 28 五月 2024 16:27:59 +0800 Subject: [PATCH] 题目优化 --- src/components/examinations/index.vue | 91 ++++++++++++++++++++++++++++++--------------- 1 files changed, 60 insertions(+), 31 deletions(-) diff --git a/src/components/examinations/index.vue b/src/components/examinations/index.vue index e1dc40a..6b36a86 100644 --- a/src/components/examinations/index.vue +++ b/src/components/examinations/index.vue @@ -211,6 +211,7 @@ " ></TEditorVue> --> <el-input + @input="textChange($event,nindex,value.id)" :disabled="value.isComplete" style="width: 94%; margin: 0 auto" v-else-if="value.questionType == 'shortAnswer'" @@ -421,14 +422,12 @@ </template> <script> -import { getPublicImage } from "@/assets/js/middleGround/tool"; export default { name: "examination-option", - // props: ["cardList"], props: { cardList: { type: Array, - default:[] + default: [], }, primaryColor: { type: String, @@ -447,7 +446,13 @@ loading: false, }; }, + inject:['changeQuestionData'], mounted() {}, + computed:{ + cardLists() { + return this.props.cardList + } + }, methods: { // 鏁扮粍杞负瀛楃涓叉柟娉� arrayToString(data) { @@ -489,11 +494,7 @@ citem.isComplete = false; } } - // for (let index = 0; index < this.questionList.length; index++) { - // const item = this.questionList[index]; - // item.userAnswer = ""; - // item.isComplete = false - // } + console.log('閲嶅仛',this.cardList); }, openAnswers() { this.$data.loading = true; @@ -559,34 +560,62 @@ this.$props.cardList = list; console.log(this.$props.cardList); }, - // 淇濆瓨鎸夐挳 - saveAnswer() { - console.log(this.cardList); - const oldAnswerData = localStorage.getItem("oldAnswerData"); - let oldData = oldAnswerData ? JSON.parse(oldAnswerData) : {}; - const asnwerList = []; - for (let index = 0; index < this.$props.cardList.length; index++) { - const item = this.$props.cardList[index]; - for (let cindex = 0; cindex < item.infoList.length; cindex++) { - const citem = item.infoList[cindex]; - asnwerList.push({ - id: citem.id, - userAnswer: citem.userAnswer, - }); + getParentWithClass(element, className) { + while (element.parentElement) { + element = element.parentElement; + if (element.classList.contains(className)) { + return element; } } - if(oldData[this.chapter]) { - oldData[this.chapter][this.page] = asnwerList - } else { - oldData[this.chapter] = {} - oldData[this.chapter][this.page] = asnwerList - } - console.log(oldData); - localStorage.setItem("oldAnswerData", JSON.stringify(oldData)); }, + // 淇濆瓨鎸夐挳 + saveAnswer() { + const element = document.getElementsByClassName("examination")[0]; + if (element) { + const pageNum = this.getParentWithClass( + element, + "page-box" + ).getAttribute("page"); + console.log(this.config.activeBook.name, pageNum); + const oldAnswerData = localStorage.getItem( + this.config.activeBook.name + "oldAnswerData" + ); + let oldData = oldAnswerData ? JSON.parse(oldAnswerData) : {}; + const asnwerList = []; + for (let index = 0; index < this.$props.cardList.length; index++) { + const item = this.$props.cardList[index]; + for (let cindex = 0; cindex < item.infoList.length; cindex++) { + const citem = item.infoList[cindex]; + asnwerList.push({ + id: citem.id, + userAnswer: citem.userAnswer, + }); + } + } + if(oldData[pageNum]) { + oldData[pageNum].push(asnwerList) + } else { + oldData[pageNum] = asnwerList + } + localStorage.setItem(this.config.activeBook.name + "oldAnswerData", JSON.stringify(oldData)); + } + + // if(oldData[this.chapter]) { + // oldData[this.chapter][this.page] = asnwerList + // } else { + // oldData[this.chapter] = {} + // oldData[this.chapter][this.page] = asnwerList + // } + // console.log(oldData); + + }, + textChange(value,a,b) { + console.log('杈撳叆',value,a,b); + console.log(this.cardList); + this.changeQuestionData(9,this.cardList) + } }, }; - </script> <style lang="less" scoped> -- Gitblit v1.9.1