From f90dde2f7bb903016a8b8d12fe49cda9011b3b6b Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期二, 28 五月 2024 16:42:59 +0800 Subject: [PATCH] 优化 --- src/components/examinations/index.vue | 92 +++++++++++++++++++++++++++++---------------- 1 files changed, 59 insertions(+), 33 deletions(-) diff --git a/src/components/examinations/index.vue b/src/components/examinations/index.vue index e1dc40a..393f4cb 100644 --- a/src/components/examinations/index.vue +++ b/src/components/examinations/index.vue @@ -1,7 +1,7 @@ <template> - <div class="examination" v-loading="!cardList.length"> + <div class="examination" v-loading="!cardData.length"> <div - v-for="(item, nindex) in cardList" + v-for="(item, nindex) in cardData" :key="nindex" class="border-box" v-show="item.infoList.length" @@ -421,14 +421,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, @@ -445,9 +443,18 @@ return { type: "option", loading: false, + cardData:[] }; }, - mounted() {}, + inject:['changeQuestionData'], + mounted() { + this.cardData = this.cardList + }, + computed:{ + cardLists() { + return this.props.cardList + } + }, methods: { // 鏁扮粍杞负瀛楃涓叉柟娉� arrayToString(data) { @@ -489,11 +496,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 +562,57 @@ 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 + }, + // 淇濆瓨鎸夐挳 + 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)); } - console.log(oldData); - localStorage.setItem("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); + }, }, }; - </script> <style lang="less" scoped> -- Gitblit v1.9.1