提交 1740cd8f authored 作者: lihuihui's avatar lihuihui

fix: 修改错题

上级 f4442d0f
<template> <template>
<div> <div>
<div v-for="(questionData, index) in questionData" :key="index">
<!-- 单选多选判断题(题目描述dom结构一样,只那选项区分) --> <!-- 单选多选判断题(题目描述dom结构一样,只那选项区分) -->
<template v-if="questionData.question_item_type == 1 || questionData.question_item_type == 2 || questionData.question_item_type == 6"> <template v-if="questionData.question_item_type == 1 || questionData.question_item_type == 2 || questionData.question_item_type == 6">
<div class="title-type"> <div class="title-type">
...@@ -23,7 +24,7 @@ ...@@ -23,7 +24,7 @@
</ul> </ul>
</template> </template>
<!-- 解析 --> <!-- 解析 -->
<div class="analysis" v-if="!isAnswer && questionData.question_item_type != 5"> <div class="analysis" v-if="!isAnswer && (questionData.question_item_type != 5 || questionData.question_item_type != 7)">
<div class="title">答案解析</div> <div class="title">答案解析</div>
<div class="analy-mian"> <div class="analy-mian">
<div class="txt1">正确答案:{{ questionData.question_answer }}</div> <div class="txt1">正确答案:{{ questionData.question_answer }}</div>
...@@ -35,7 +36,7 @@ ...@@ -35,7 +36,7 @@
</div> </div>
</div> </div>
<!-- 复合题 --> <!-- 复合题 -->
<template v-if="questionData.question_item_type == 5"> <template v-if="questionData.question_item_type == 5 || questionData.question_item_type == 7">
<div class="title-type"> <div class="title-type">
<div class="type">{{ questionData.question_item_title }}</div> <div class="type">{{ questionData.question_item_title }}</div>
<div class="num">{{ questionData.q_order }}/{{ questionData.total_question_count }}</div> <div class="num">{{ questionData.q_order }}/{{ questionData.total_question_count }}</div>
...@@ -79,6 +80,7 @@ ...@@ -79,6 +80,7 @@
</div> </div>
</template> </template>
</div> </div>
</div>
</template> </template>
<script> <script>
export default { export default {
...@@ -88,13 +90,14 @@ export default { ...@@ -88,13 +90,14 @@ export default {
}, },
data() { data() {
return { return {
questionData: {}, questionData: [],
isAnswer: true, isAnswer: true,
currentCheck: {} currentCheck: {}
} }
}, },
created() { created() {
this.questionData = this.questionParams.question this.questionData = this.questionParams.question
console.log(this.questionDatas, 'lhh=1=')
}, },
mounted() { mounted() {
this.isChangeAnswer() this.isChangeAnswer()
......
<template>
<div>
<div class="answer-box">
<div class="head" id="head-h">
<el-button icon="el-icon-arrow-left" circle @click="$router.back()"></el-button>
<div class="title">{{ $route.query.type == 1 ? '我的错题' : $route.query.type == 2 ? '收藏试题' : '已做试题' }}</div>
<div class="right">
<div class="count">{{ questionParams.question.sheet_time }}</div>
</div>
</div>
<div class="exam-main" :style="{height: this.contentHeight + 'px'}">
<div class="left">
<question
v-if="Object.keys(questionParams.question).length"
:contentHeight="contentHeight"
:questionParams="questionParams"
ref="confirmBtn"
></question>
</div>
<div class="right">
<answer-card
:questionParams="questionParams"
@cardChangeQuention="goAppointQuestion"
></answer-card>
</div>
</div>
<div class="foot" id="foot-h">
<div class="exam-btn">
<div class="confirm"
v-if="this.questionParams.question.answer_count > 1 && $route.query.type != 3"
@click="confirmBtn"
>
确认答案
</div>
<div
@click="changeIndex('prev')"
:class="this.questionParams.questionIndex !== 0 ? 'active' : ''"
>上一题</div>
<div
:class="questionParams.questionIndex + 1 !== questionParams.question.total_question_count ? 'active' : ''"
@click="changeIndex('next')"
>下一题</div>
</div>
<div class="rigth-btn">
<div class="sign" @click="collectQuestion" v-if="$route.query.type != 2">
<div :class="questionParams.question.is_collection ? 'icon active' : 'icon'"></div>
<div class="txt">{{ questionParams.question.is_collection ? '已收藏' : '收藏' }}</div>
</div>
<div class="del-btn" @click="deleteQuestion">删除</div>
<div class="end-exam-btn" v-if="$route.query.type != 3">
<div class="btn" @click="clearQuestion">清空记录,重新答题</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import * as api from '@/api/exam.js'
import answerCard from './components/answerCard.vue'
import question from './components/question.vue'
export default {
components: {
question,
answerCard
},
data() {
return {
// 设置页面高
contentHeight: 0,
// 原数据
questionData: [],
// 存题
container: [],
// 过滤后的数据
afterChangeData: {},
questionParams: {
// 用户选择的选项 --- 提交后台的数据
answerRecord: {},
// 所有题 和题的信息
question: {},
questionIndex: 0,
card: {}
// beforeData: {}
}
}
},
mounted() {
// 赋值页面高度
this.setPageHeight()
this.initData()
},
methods: {
setPageHeight() {
this.contentHeight = parseInt(document.documentElement.clientHeight - (this.getDom('head-h').offsetHeight + this.getDom('foot-h').offsetHeight))
},
// 删除试题
deleteQuestion() {
this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
const param = {
question_id: this.questionParams.question.id,
type: this.$route.query.type
}
api
.deleteQuestion(param)
.then(response => {
this.$router.go(0)
})
.finally(() => {
})
},
// 初始化
initData() {
this.getCardAll()
this.goAppointQuestion(this.$route.query.index - 1)
this.questionParams.questionIndex = 0
window.localStorage.answerRecord
? this.questionParams.answerRecord = JSON.parse(window.localStorage.answerRecord)
: this.questionParams.answerRecord = {}
},
confirmBtn() {
this.$refs.confirmBtn.answerConfirm()
},
getDom(id) {
return document.getElementById(id)
},
// 收藏试题
collectQuestion() {
const data = this.questionParams.question
console.log(data)
data.is_collection
? this.removeCall(data.id, () => {
data.is_collection = false
})
: this.addCall(data.id, () => {
data.is_collection = true
})
},
addCall(id, call) {
api
.addCollection({ question_id: id })
.then(response => {
call(response.list)
})
.finally(() => {
})
},
removeCall(id, call) {
api
.deleteCollection({ question_id: id })
.then(response => {
call(response.list)
})
.finally(() => {
})
},
// 改变数据
setData(list) {
return list.map(list => {
const type = {
1: '单选题',
2: '多选题',
5: '案例题',
6: '判断题'
}
const typeTotal = {
3: 'total',
1: 'error_total',
2: 'collection_total'
}
const data = {
q_order: list.num,
question_item_type: list.question_type,
content: list.question_content,
id: list.question_id,
options: list.question_options,
question_item_title: type[parseInt(list.question_type)],
total_question_count: this.questionData[typeTotal[parseInt(this.$route.query.type)]],
question_analysis: list.question_analysis,
user_answer: list.user_answer,
is_collection: list.is_collection,
answer_count: list.answer_count,
common_content: list.common_content,
sheet_time: list.sheet_time,
rightKey: list.question_answer
}
const findAB = data.question_answer = list.question_answer.map(i => {
const findIndex = list.question_options.findIndex(opt => { return opt.id === i })
return this.A_Z()[findIndex]
})
data.question_answer = findAB.sort().toString().replace(new RegExp(',', 'g'), '')
return data
})
},
// 获取考卷
getTopic(page, call) {
const param = {
type: this.$route.query.type,
question_type: this.$route.query.qType,
page: page,
page_size: 20
}
api
.getMyQuestion(param)
.then(response => {
this.questionData = response
call(response.list)
})
.finally(() => {
})
},
// 获取答题卡所有题
getCardAll() {
const param = {
type: parseInt(this.$route.query.type) === 3 ? 0 : this.$route.query.type,
question_type: this.$route.query.qType
}
api
.getAllQuestion(param)
.then(response => {
if (response.list[0].question) {
this.questionParams.card = this.setCardData(response.list)
} else {
this.questionParams.card = response.list
}
})
.finally(() => {
})
},
setCardData(list) {
return list.map(item => {
item.question = JSON.parse(item.question)
return item
})
},
// ABC
A_Z() {
const result = []
for (let i = 0; i < 26; i++) {
result.push(String.fromCharCode(65 + i))
}
return result
},
// 点击上一题下一题 答题卡序号
changeData() {
this.questionData.list.map(list => {
if (list.q_order === this.questionParams.questionIndex + 1) {
this.questionParams.question = list
}
})
},
// 进入指定的题
goAppointQuestion(n) {
this.container = []
this.questionData.list = []
const page = parseInt(n / 20)
if (page === 0) {
this.getTopic(page + 1, data => {
this.container = this.setData(data)
this.questionData.list = this.container
this.questionParams.questionIndex = parseInt(n)
this.changeData()
})
} else {
this.getTopic(page, data => {
this.container = this.setData(data)
this.questionData.list = this.container
})
this.getTopic(page + 1, data => {
this.addCont(data, 1)
this.questionData.list = this.container
this.questionParams.questionIndex = parseInt(n)
this.changeData()
})
}
},
// 改变题序
changeIndex(type) {
if (type === 'prev') {
if (this.questionParams.questionIndex > 0) {
this.questionParams.questionIndex--
const isData = this.questionData.list.findIndex(i => { return i.q_order === this.questionParams.questionIndex + 1 })
!isData && (this.supplyRequest())
}
} else {
if (parseInt(this.questionParams.questionIndex + 1) !== parseInt(this.questionParams.question.total_question_count)) {
this.questionParams.questionIndex++
const isData = this.questionData.list.find(i => { return i.q_order === this.questionParams.questionIndex + 2 })
!isData && (this.supplyRequest(1))
}
}
},
// 加载部分试题
supplyRequest(n) {
// const loading = this.$loading({
// lock: true,
// text: 'Loading',
// spinner: 'el-icon-loading',
// background: 'rgba(0, 0, 0, 0.7)'
// })
this.getTopic(parseInt((n ? this.questionParams.questionIndex + 2 : this.questionParams.questionIndex - 2) / 20) + 1, data => {
if (this.container.length >= 40) {
n ? this.container.splice(0, 20) : this.container.splice(20, 20)
this.addCont(data, n)
} else {
this.addCont(data, n)
}
this.questionData.list = this.container
this.changeData()
// loading.close()
})
},
addCont(data, n) {
const changeData = n ? data : data.reverse()
this.setData(changeData).map(item => {
n ? this.container.push(item) : this.container.unshift(item)
})
},
// 缓存 提交
handlePapers(n) {
const answerData = {}
for (const data in this.questionParams.answerRecord) {
answerData[data] = this.questionParams.answerRecord[data].answer
}
const param = {
type: this.$route.query.type,
question_type: this.$route.query.qType,
answer: JSON.stringify(answerData)
}
window.localStorage.answerRecord = JSON.stringify(this.questionParams.answerRecord)
this.chcheReq(param, () => {})
},
// 清除所有答案 重新答题
clearQuestion() {
const param = {
type: this.$route.query.type,
question_type: this.$route.query.qType,
clear: 1
}
this.chcheReq(param, () => {
this.questionParams.questionIndex = 0
window.localStorage.removeItem('answerRecord')
this.initData()
this.$router.go(0)
})
},
chcheReq(param, call) {
api
.setMyCache(param)
.then(response => {
call()
})
.finally(() => {
})
}
},
computed: {
changeQuestionIndex() {
return this.questionParams.questionIndex
}
},
watch: {
// 监听题的变化
changeQuestionIndex(newV, oldV) {
this.changeData()
parseInt(this.$route.query.type) !== 3 && (this.handlePapers())
}
}
}
</script>
<style lang="scss" scoped>
.answer-box{
width: 100%;
height: 100%;
// background: #f9f9f9;
.head{
border-bottom: 1px solid #ccc;
height: 80px;
background: #FFFFFF;
display: flex;
align-items: center;
padding-left: 40px;
.title{
padding-left: 20px;
font-size: 24px;
font-weight: bold;
color: #222222;
line-height: 80px;
}
.right{
width: 260px;
margin-left: auto;
display: flex;
justify-content: space-around;
align-items: center;
.count{
font-size: 18px;
font-weight: bold;
color: #222222;
}
.time{
display: flex;
.icon{
width: 23px;
height: 23px;
// background: url(../../assets/images/tick.png);
background-size:100% 100%;
}
.mun{
font-size: 18px;
font-weight: bold;
color: #222222;
line-height: 25px;
margin-left: 10px;
}
}
}
}
.exam-main{
display: flex;
.left{
background: #fff;
flex: 1;
padding: 10px 20px 0 53px;
overflow-y: scroll;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
.right{
border-left: 1px solid #ccc;
position: relative;
width: 220px;
background: #fff;
padding: 0 20px;
overflow-y: scroll;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
}
.foot{
border-top: 1px solid #ccc;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 60px;
background: #FFFFFF;
display: flex;
align-items: center;
.exam-btn{
display: flex;
padding-left: 40px;
.confirm{
width: 140px;
height: 40px;
background: #C01540;
border-radius: 4px;
font-size: 14px;
font-weight: bold;
color: #FFFFFF;
line-height: 40px;
text-align: center;
}
cursor: pointer;
div{
width: 100px;
height: 40px;
border-radius: 4px;
border: 1px solid #CCCCCC;
font-size: 14px;
font-weight: bold;
color: #999999;
line-height: 40px;
text-align: center;
margin-right: 20px;
&.active{
background: #C01540;
border-radius: 4px;
color: #fff;
}
}
}
.rigth-btn{
display: flex;
margin-left: auto;
.del-btn{
margin-top: 10px;
width: 100px;
height: 40px;
border-radius: 4px;
border: 1px solid #CCCCCC;
line-height: 40px;
font-size: 14px;
font-weight: bold;
color: #999999;
text-align: center;
margin-right: 30px;
}
.end-exam-btn{
background: #fff;
height: 62px;
margin-top: -2px;
border-left: 1px solid #ccc;
width: 260px;
display: flex;
justify-content: center;
align-items: center;
.btn{
cursor: pointer;
width: 200px;
height: 40px;
background: #c01540;
border-radius: 4px;
font-size: 14px;
font-weight: bold;
color: #fff;
line-height: 40px;
text-align: center;
}
}
.sign{
margin-right: 20px;
margin-top: 8px;
.icon{
margin: 0 auto;
width: 24px;
height: 24px;
background: url(@/assets/images/collection.png);
background-size:100% 100%;
&.active{
background: url(@/assets/images/collection2.png);
background-size:100% 100%;
}
}
.txt{
font-size: 14px;
color: #CCCCCC;
line-height: 20px;
margin-top: 2px;
}
}
}
}
}
</style>
...@@ -161,7 +161,8 @@ export default { ...@@ -161,7 +161,8 @@ export default {
}, },
// 改变数据 // 改变数据
setData(list) { setData(list) {
return list.map(list => { return list.map(pList => {
return pList.map(list => {
const type = { const type = {
1: '单选题', 1: '单选题',
2: '多选题', 2: '多选题',
...@@ -196,6 +197,7 @@ export default { ...@@ -196,6 +197,7 @@ export default {
data.question_answer = findAB.sort().toString().replace(new RegExp(',', 'g'), '') data.question_answer = findAB.sort().toString().replace(new RegExp(',', 'g'), '')
return data return data
}) })
})
}, },
// 获取考卷 // 获取考卷
getTopic(page, call) { getTopic(page, call) {
...@@ -248,11 +250,17 @@ export default { ...@@ -248,11 +250,17 @@ export default {
}, },
// 点击上一题下一题 答题卡序号 // 点击上一题下一题 答题卡序号
changeData() { changeData() {
let datas = []
this.questionData.list.map(list => { this.questionData.list.map(list => {
if (list.q_order === this.questionParams.questionIndex + 1) { const findData = list.find(item => {
this.questionParams.question = list return item.q_order === this.questionParams.questionIndex + 1
})
if (findData) {
datas = list
return false
} }
}) })
this.questionParams.question = datas
}, },
// 进入指定的题 // 进入指定的题
goAppointQuestion(n) { goAppointQuestion(n) {
......
<template> <template>
<div> <div>
<exam-card :hasSubmitBtn="!!(!$route.query.id)" :hasCountDown="!!(!$route.query.id)" v-if="Object.keys(data).length > 1" @submitExam="submitExam" ref="exam" title="模拟考试" :data="data"></exam-card> <exam-card :hasSubmitBtn="!!(!$route.query.id)" :hasCountDown="!!(!$route.query.id)" v-if="Object.keys(data).length" @submitExam="submitExam" ref="exam" title="模拟考试" :data="data"></exam-card>
</div> </div>
</template> </template>
<script> <script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论