| | |
| | | <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" |
| | |
| | | </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, |
| | |
| | | return { |
| | | type: "option", |
| | | loading: false, |
| | | cardData:[] |
| | | }; |
| | | }, |
| | | mounted() {}, |
| | | mounted() { |
| | | this.cardData = this.cardList |
| | | console.log('this.cardList',this.cardList); |
| | | console.log('this.cardData',this.cardData); |
| | | }, |
| | | methods: { |
| | | // 数组转为字符串方法 |
| | | arrayToString(data) { |
| | |
| | | } |
| | | }, |
| | | redo() { |
| | | for (let index = 0; index < this.cardList.length; index++) { |
| | | const item = this.cardList[index]; |
| | | for (let index = 0; index < this.cardData.length; index++) { |
| | | const item = this.cardData[index]; |
| | | for (let cindex = 0; cindex < item.infoList.length; cindex++) { |
| | | const citem = item.infoList[cindex]; |
| | | citem.userAnswer = ""; |
| | | citem.isComplete = false; |
| | | } |
| | | } |
| | | // for (let index = 0; index < this.questionList.length; index++) { |
| | | // const item = this.questionList[index]; |
| | | // item.userAnswer = ""; |
| | | // item.isComplete = false |
| | | // } |
| | | }, |
| | | openAnswers() { |
| | | this.$data.loading = true; |
| | | for (let index = 0; index < this.cardList.length; index++) { |
| | | const item = this.cardList[index]; |
| | | for (let index = 0; index < this.cardData.length; index++) { |
| | | const item = this.cardData[index]; |
| | | for (let cindex = 0; cindex < item.infoList.length; cindex++) { |
| | | const citem = item.infoList[cindex]; |
| | | citem.isComplete = true; |
| | |
| | | }, |
| | | // 批改题目 (练习,我的做题,我的收藏模式下) |
| | | handleQuestion() { |
| | | const list = this.$props.cardList; |
| | | const list = this.cardData; |
| | | for (let index = 0; index < list.length; index++) { |
| | | const item = list[index]; |
| | | for (let cindex = 0; cindex < item.infoList.length; cindex++) { |
| | |
| | | } |
| | | } |
| | | } |
| | | this.$props.cardList = list; |
| | | console.log(this.$props.cardList); |
| | | this.cardData = list; |
| | | console.log(this.cardData); |
| | | }, |
| | | getParentWithClass(element, className) { |
| | | while (element.parentElement) { |
| | | element = element.parentElement; |
| | | if (element.classList.contains(className)) { |
| | | return element; |
| | | } |
| | | } |
| | | }, |
| | | // 保存按钮 |
| | | 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, |
| | | }); |
| | | 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.cardData.length; index++) { |
| | | const item = this.cardData[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] = oldData[pageNum].filter(citem => asnwerList.findIndex(ditem => ditem.id == citem.id) == -1 ) |
| | | 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); |
| | | 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> |