| | |
| | | v-cloak |
| | | ></p> |
| | | </div> |
| | | <img :src="value.isCollect ? isHeart : heart" alt="" class="collect-png" @click="handleCollect(nindex,index)" v-if="!(hideCollect && value.questionType == 'shortAnswer')" > |
| | | <img |
| | | :src="value.isCollect ? isHeart : heart" |
| | | alt="" |
| | | class="collect-png" |
| | | @click="setCollect(nindex, index)" |
| | | v-if="!(hideCollect && value.questionType == 'shortAnswer')" |
| | | /> |
| | | <!-- 收藏 --> |
| | | </div> |
| | | <div class="questionContent"> |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | import { Message } from 'element-ui'; |
| | | import { Message } from "element-ui"; |
| | | export default { |
| | | name: "examination-option", |
| | | props: { |
| | |
| | | }, |
| | | hideCollect:{ |
| | | type:Boolean, |
| | | default:false |
| | | } |
| | | default: false, |
| | | }, |
| | | sourceType: { |
| | | type: String, |
| | | default: "bits", |
| | | }, |
| | | }, |
| | | data() { |
| | | return { |
| | |
| | | loading: true, |
| | | heart:require("@/assets/images/heart.png"), |
| | | isHeart:require("@/assets/images/heart-check.png"), |
| | | collectList: [], |
| | | allCollect: [ |
| | | { |
| | | type: "bits", |
| | | collectList: [], |
| | | }, |
| | | { |
| | | type: "json", |
| | | collectList: [], |
| | | }, |
| | | ], |
| | | errorList: [], |
| | | allError: [ |
| | | { |
| | | type: "bits", |
| | | errorList: [], |
| | | }, |
| | | { |
| | | type: "json", |
| | | errorList: [], |
| | | }, |
| | | ], |
| | | }; |
| | | }, |
| | | watch: { |
| | |
| | | }, |
| | | }, |
| | | mounted() { |
| | | // this.cardData = this.cardList |
| | | // console.log('this.cardList',this.cardList); |
| | | // console.log('this.cardData',this.cardData); |
| | | this.getCollectIdList(); |
| | | this.getErrorList() |
| | | }, |
| | | methods: { |
| | | // 数组转为字符串方法 |
| | |
| | | }, |
| | | // 批改题目 (练习,我的做题,我的收藏模式下) |
| | | handleQuestion() { |
| | | let errorId = [] |
| | | const list = this.cardData; |
| | | for (let index = 0; index < list.length; index++) { |
| | | const item = list[index]; |
| | |
| | | } |
| | | } |
| | | } |
| | | if(citem.isRight == false) { |
| | | errorId.push(citem.id) |
| | | } |
| | | } |
| | | } |
| | | this.cardData = list; |
| | | console.log(this.cardData); |
| | | let oldErrodId = this.allError.find(item => item.type == this.sourceType).errorList |
| | | for (let index = 0; index < errorId.length; index++) { |
| | | const item = errorId[index]; |
| | | if(oldErrodId.indexOf(item == -1)) { |
| | | oldErrodId.push(item) |
| | | } |
| | | } |
| | | for (let cindex = 0; cindex < this.allError.length; cindex++) { |
| | | const citem = this.allError[cindex]; |
| | | if(citem.type == this.sourceType) citem.errorList = oldErrodId |
| | | } |
| | | this.MG.identity |
| | | .setUserKey({ |
| | | setKeyRequests: [ |
| | | { |
| | | domain: 'errorData', |
| | | key: this.config.activeBook.bookId, |
| | | value: JSON.stringify(this.allError) |
| | | } |
| | | ] |
| | | }) |
| | | .then((res) => { |
| | | console.log('错题已保存',this.allError) |
| | | }) |
| | | }, |
| | | getParentWithClass(element, className) { |
| | | while (element.parentElement) { |
| | |
| | | this.config.activeBook.name + "oldAnswerData", |
| | | JSON.stringify(oldData) |
| | | ); |
| | | Message.success('保存成功') |
| | | Message.success("保存成功"); |
| | | } |
| | | |
| | | // if(oldData[this.chapter]) { |
| | |
| | | // console.log(oldData); |
| | | }, |
| | | handleCollect(infoNum,num) { |
| | | console.log(this.cardData[infoNum].infoList[num] ); |
| | | this.cardData[infoNum].infoList[num].isCollect = !this.cardData[infoNum].infoList[num].isCollect |
| | | this.cardData[infoNum].infoList[num].isCollect = |
| | | !this.cardData[infoNum].infoList[num].isCollect; |
| | | }, |
| | | // 题目收藏按钮,收藏和取消同一接口,取消数组减去该项id |
| | | setCollect(num, number) { |
| | | const item = this.cardData[num].infoList[number]; |
| | | item.isCollect = !item.isCollect; |
| | | if (this.cardData.length == 0) { |
| | | this.collectList.push(item.id); |
| | | } else { |
| | | const isShow = this.collectList.findIndex((citem) => citem == item.id); |
| | | if (isShow == -1) { |
| | | this.collectList.push(item.id); |
| | | } else { |
| | | this.collectList = this.collectList.filter( |
| | | (citem) => citem != item.id |
| | | ); |
| | | } |
| | | } |
| | | const list = this.collectList; |
| | | for (let index = 0; index < this.allCollect.length; index++) { |
| | | const item = this.allCollect[index]; |
| | | if (item.type == this.sourceType) item.collectList = this.collectList; |
| | | } |
| | | // console.log(this.allCollect, this.collectList, list); |
| | | this.MG.identity |
| | | .setUserKey({ |
| | | setKeyRequests: [ |
| | | { |
| | | domain: "collectData", |
| | | key: this.config.activeBook.bookId, |
| | | value: JSON.stringify(this.allCollect), |
| | | }, |
| | | ], |
| | | }) |
| | | .then((res) => { |
| | | console.log("收藏/取消成功"); |
| | | }); |
| | | }, |
| | | // 获取收藏id列表 |
| | | getCollectIdList() { |
| | | this.MG.identity |
| | | .getUserKey({ |
| | | domain: "collectData", |
| | | keys: [this.config.activeBook.bookId], |
| | | }) |
| | | .then((res) => { |
| | | try { |
| | | const collect = JSON.parse(res[0].value); |
| | | if (collect.length) { |
| | | this.collectList = collect.find( |
| | | (citem) => citem.type == this.sourceType |
| | | ).collectList; |
| | | this.allCollect[0].collectList = collect.find( |
| | | (citem) => citem.type == "bits" |
| | | ).collectList; |
| | | this.allCollect[1].collectList = collect.find( |
| | | (citem) => citem.type == "json" |
| | | ).collectList; |
| | | } |
| | | } catch (error) { |
| | | console.log("暂无数据"); |
| | | } |
| | | }) |
| | | .catch((res) => { |
| | | console.log("答题器请求题目收藏id报错"); |
| | | }); |
| | | }, |
| | | // 获取错题id列表 |
| | | getErrorList() { |
| | | this.MG.identity |
| | | .getUserKey({ |
| | | domain: "errorData", |
| | | keys: [this.config.activeBook.bookId], |
| | | }) |
| | | .then((res) => { |
| | | try { |
| | | const error = JSON.parse(res[0].value); |
| | | if (error.length) { |
| | | this.errorList = error.find( |
| | | (citem) => citem.type == this.sourceType |
| | | ).errorList; |
| | | this.allError[0].errorList = error.find( |
| | | (citem) => citem.type == "bits" |
| | | ).errorList; |
| | | this.allError[1].errorList = error.find( |
| | | (citem) => citem.type == "json" |
| | | ).errorList; |
| | | } |
| | | } catch (error) {} |
| | | }); |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |