Files
dvcp_v2_wechat_app/src/project/qujing/AppLegalLearning/testForm.vue

314 lines
9.2 KiB
Vue
Raw Normal View History

2023-01-31 09:49:26 +08:00
<template>
<div class="testForm">
2023-01-31 16:19:20 +08:00
<u-navbar title="法治学习" :background="backgroundNavbar"></u-navbar>
2023-02-14 17:10:40 +08:00
<div class="testForm_info" >
<div v-for="(item,index) in list" :key="index">
<div v-if="activeIndex === index">
<div class="type">
<div class="type_left">{{ item.type==0? '单选题':item.type==1? '多选题': '判断题' }}</div>
<div><span class="col_blue">{{ activeIndex + 1 }}</span>/{{ list.length }}</div>
</div>
<div class="topic">
<div>
<div >
<!-- 题目 -->
2023-02-15 15:00:55 +08:00
<div>{{ item.title }}</div>
2023-02-15 09:50:44 +08:00
<!-- 单选,判断 -->
2023-02-14 18:01:00 +08:00
<div class="answer_list" v-if="item.type==0 || item.type==2">
2023-02-14 17:10:40 +08:00
<div class="answer_item" v-for="(opt,inx) in item.items" :key="inx"
2023-02-14 18:01:00 +08:00
:class="{'Checked': clickIndex === inx, 'Succeed': showAnalysis && opt.checked == 1, 'Error': showAnalysis && clickIndex === inx && opt.checked == 0}"
2023-02-14 17:10:40 +08:00
@click="itemClick(inx)">
{{ opt.sort }}: {{ opt.content}}
</div>
</div>
2023-02-14 18:01:00 +08:00
<!-- 多选 -->
<div class="answer_list" v-if="item.type==1">
2023-02-14 17:10:40 +08:00
<div class="answer_item" v-for="(opt,inx) in item.items" :key="inx"
2023-02-15 09:50:44 +08:00
:class="{'Checked': opt.isChecked,'Succeed': showAnalysis && opt.checked == 1, 'Error': showAnalysis && opt.isChecked && opt.checked == 0}"
2023-02-14 17:10:40 +08:00
@click="itemClick(inx)">
2023-02-15 15:00:55 +08:00
{{ opt.sort }}: {{ opt.content}}
2023-02-14 17:10:40 +08:00
</div>
</div>
2023-02-14 14:06:46 +08:00
</div>
</div>
2023-02-01 18:02:38 +08:00
</div>
2023-02-14 14:06:46 +08:00
2023-02-14 17:10:40 +08:00
<div class="type mar-top" v-if="showAnalysis">
<div class="type_left">答案解析</div>
</div>
<div class="topic mar-top" v-if="showAnalysis">
2023-02-17 11:31:10 +08:00
<div><span>正确答案</span><span>{{ rightOpt }}</span></div>
2023-02-14 17:10:40 +08:00
<div style="margin-top: 8px" v-html="list[activeIndex].analysis"></div>
</div>
</div>
2023-02-10 15:49:13 +08:00
</div>
2023-02-14 14:06:46 +08:00
2023-02-14 17:10:40 +08:00
<div class="btn" @click="nextTopic" v-if="activeIndex < list.length - 1 && showNext">下一题</div>
2023-02-14 14:06:46 +08:00
<div class="btn" v-show="showConfirm" @click="confirm">确定</div>
2023-02-15 09:50:44 +08:00
<div class="btn" v-show="showTiJiao" @click="submit">提交</div>
2023-02-01 18:02:38 +08:00
</div>
2023-02-15 09:50:44 +08:00
2023-01-31 09:49:26 +08:00
</div>
</template>
<script>
2023-02-15 09:50:44 +08:00
import dayjs from "dayjs"
2023-01-31 09:49:26 +08:00
export default {
2023-01-31 16:19:20 +08:00
customNavigation: true,
2023-01-31 09:49:26 +08:00
data() {
return {
2023-01-31 16:19:20 +08:00
backgroundNavbar: {
2023-02-10 15:49:13 +08:00
background: "url('https://cdn.cunwuyun.cn/qujing/navbar.png') no-repeat",
backgroundSize: '100% 100%',
2023-01-31 16:19:20 +08:00
},
2023-02-14 14:06:46 +08:00
list: [],
2023-02-02 12:00:35 +08:00
activeIndex: 0, // 当前第几题
2023-02-15 11:21:37 +08:00
activeAnswer: undefined,
2023-02-06 16:06:45 +08:00
endTime: '', // 结束时间
2023-02-14 14:06:46 +08:00
id: '', // 题库id
showConfirm: false,
showNext: false,
2023-02-15 09:50:44 +08:00
showTiJiao: false,
2023-02-14 14:06:46 +08:00
clickIndex: '',
showAnalysis: false,
2023-02-14 17:10:40 +08:00
subjectConfigs: [],
2023-02-15 09:50:44 +08:00
score: 0,
assessments: [], // 不合格的分数段
2023-02-16 09:28:53 +08:00
status: 1, // 考试结果0未通过、1通过
2023-02-15 09:50:44 +08:00
startTime: '',
nowTime: '', // 时间戳
studyDuration: 0,
2023-02-15 11:21:37 +08:00
assessmentType: '',
examinationId: '',
2023-02-15 15:00:55 +08:00
rightCount: 0,
flag: false,
2023-02-17 11:31:10 +08:00
rightOpt: null,
2023-01-31 09:49:26 +08:00
}
},
methods: {
2023-02-14 14:06:46 +08:00
getList(id) {
this.$instance.post(`/app/appexaminationinfo/queryDetailById?id=${id}`).then(res=> {
if(res?.data) {
2023-02-15 09:50:44 +08:00
res.data.questions.forEach(item => {
item.items.forEach(item1 =>{
item1.isChecked = false
})
});
this.list = res.data.questions
2023-02-14 17:10:40 +08:00
this.subjectConfigs = res.data.subjectConfigs
2023-02-15 09:50:44 +08:00
this.assessments = res.data.assessments
2023-02-15 11:21:37 +08:00
this.examinationId = res.data.id
2023-02-14 14:06:46 +08:00
}
})
2023-02-06 16:06:45 +08:00
},
2023-02-14 14:06:46 +08:00
itemClick(i) {
2023-02-14 17:10:40 +08:00
if (this.showAnalysis) return
2023-02-15 09:50:44 +08:00
this.showConfirm = true
if(this.list[this.activeIndex].type==0 || this.list[this.activeIndex].type==2){ // 单选判断
this.clickIndex = i
}
if(this.list[this.activeIndex].type==1) { // 多选
this.list[this.activeIndex].items[i].isChecked=!this.list[this.activeIndex].items[i].isChecked
2023-02-14 14:06:46 +08:00
}
2023-01-31 09:49:26 +08:00
},
2023-02-14 18:01:00 +08:00
// 下一题
2023-02-06 16:06:45 +08:00
nextTopic() {
2023-01-31 09:49:26 +08:00
this.activeIndex ++;
2023-02-14 17:10:40 +08:00
this.clickIndex = ''
this.showAnalysis = false
2023-02-15 10:20:16 +08:00
this.showNext = false
2023-01-31 16:19:20 +08:00
},
2023-02-14 18:01:00 +08:00
// 确定
2023-02-02 12:00:35 +08:00
confirm() {
2023-02-14 17:10:40 +08:00
this.showAnalysis = true;
2023-02-15 09:50:44 +08:00
// 单选判断
if(this.list[this.activeIndex].type==0 || this.list[this.activeIndex].type==2){
2023-02-17 11:31:10 +08:00
this.rightOpt = this.list[this.activeIndex].items.filter(e=> e.checked==1)[0].sort
2023-02-15 09:50:44 +08:00
if(this.list[this.activeIndex].items[this.clickIndex].checked==1) {
this.score=this.score + this.subjectConfigs[this.list[this.activeIndex].type].eachScore
2023-02-15 15:00:55 +08:00
this.rightCount ++
2023-02-15 09:50:44 +08:00
}
}
if(this.list[this.activeIndex].type==1) { // 多选
2023-02-17 11:31:10 +08:00
this.rightOpt = this.list[this.activeIndex].items.filter(e=> e.checked==1).map(i=> i.sort)
console.log(this.rightOpt);
2023-02-15 09:50:44 +08:00
if(this.list[this.activeIndex].items.every(item=>item.checked===item.isChecked)){
2023-02-15 15:00:55 +08:00
this.score = this.score + this.subjectConfigs[this.list[this.activeIndex].type].eachScore
this.rightCount ++
2023-02-15 09:50:44 +08:00
}
}
2023-02-14 17:10:40 +08:00
if(this.activeIndex < this.list.length - 1) {
this.showNext = true;
this.showConfirm = false;
} else {
2023-02-15 09:50:44 +08:00
this.showTiJiao = true;
}
},
2023-02-15 11:21:37 +08:00
getScoreType(score) {
let conditionMap = [
(a, b) => a - b >= 0,
(a, b) => a - b > 0,
(a, b) => a - b == 0,
(a, b) => a - b <= 0,
(a, b) => a - b < 0
]
let type = ['0','1','2','3']
for (let i = 0; i < this.assessments.length; i++) {
let ret = this.assessments[i].upScore;
let con = this.assessments[i].upCondition;
if (conditionMap[con](score, ret)) {
this.assessmentType = type[i]
2023-02-15 15:00:55 +08:00
break;
2023-02-15 11:21:37 +08:00
}
}
},
2023-02-15 09:50:44 +08:00
// 提交
submit() {
2023-02-15 15:00:55 +08:00
if(this.flag) return
2023-02-15 11:21:37 +08:00
this.getScoreType(this.score)
2023-02-15 15:00:55 +08:00
2023-02-15 11:21:37 +08:00
let endTime = new Date().getTime()
2023-02-15 09:50:44 +08:00
this.studyDuration = Math.ceil((endTime - this.nowTime) / 1000 / 60)
2023-02-15 15:00:55 +08:00
2023-02-15 11:21:37 +08:00
let buhege = this.assessments.filter(e=> e.assessmentType == 3)
if(buhege[0].upCondition == 3) { // 3小于等于、4小于
if(this.score <= buhege[0].upScore) {
2023-02-15 09:50:44 +08:00
this.status = 0
}
2023-02-15 11:21:37 +08:00
}
if(buhege[0].upCondition == 4) {
if(this.score < buhege[0].upScore) {
2023-02-15 09:50:44 +08:00
this.status = 0
}
2023-02-14 17:10:40 +08:00
}
2023-02-15 15:00:55 +08:00
this.flag = true
2023-02-15 11:21:37 +08:00
this.$instance.post(`/app/appexaminationinfo/commit`,{
assessmentType: this.assessmentType,
examinationId: this.examinationId,
startTime: this.startTime,
status: this.status,
studyDuration: this.studyDuration,
score: this.score
}).then(res=> {
if(res?.code == 0) {
2023-02-15 15:00:55 +08:00
this.flag = false
2023-02-17 11:15:40 +08:00
this.$u.toast('提交成功')
2023-02-15 15:00:55 +08:00
setTimeout(()=> {
uni.navigateTo({
url: `./result?status=${this.status}&time=${this.studyDuration}&rightCount=${this.rightCount}&examCount=${this.list.length}&score=${this.score}`
})
}, 600)
2023-02-15 11:21:37 +08:00
}
2023-02-15 15:00:55 +08:00
}).catch(err=> {
this.flag = false
this.$u.toast(err.masg)
})
2023-02-02 12:00:35 +08:00
},
2023-01-31 09:49:26 +08:00
},
onReachBottom() {
this.current ++;
},
2023-02-14 14:06:46 +08:00
onLoad(o) {
this.getList(o.id)
2023-02-15 09:50:44 +08:00
this.startTime = dayjs().format("YYYY-MM-DD HH:mm:ss")
this.nowTime = new Date().getTime()
2023-02-06 16:06:45 +08:00
}
2023-01-31 09:49:26 +08:00
}
</script>
<style lang="scss" scoped>
.testForm {
2023-02-10 15:49:13 +08:00
.testForm_info {
background: url("https://cdn.cunwuyun.cn/qujing/bg.png") no-repeat;
2023-02-10 15:59:38 +08:00
background-size: 100% auto;
2023-02-17 11:31:10 +08:00
padding: 80px 32px 120px 32px;
2023-01-31 16:19:20 +08:00
box-sizing: border-box;
2023-02-10 15:49:13 +08:00
.type {
display: flex;
justify-content: space-between;
font-size: 28px;
color: #333333;
2023-01-31 16:19:20 +08:00
2023-02-10 15:49:13 +08:00
.type_left {
font-weight: 600;
}
2023-01-31 16:19:20 +08:00
2023-02-10 15:49:13 +08:00
.col_blue {
color: #2D7DFF;
}
2023-01-31 09:49:26 +08:00
2023-02-10 15:49:13 +08:00
}
2023-02-06 16:06:45 +08:00
2023-02-10 15:49:13 +08:00
.topic {
background: #FFF;
2023-02-06 16:06:45 +08:00
margin-top: 32px;
2023-02-10 15:49:13 +08:00
padding: 24px;
margin-top: 80px;
border-radius: 16px;
box-shadow: 0 0 8px 0 rgba(0,0,0,0.02);
2023-02-06 16:06:45 +08:00
2023-02-10 15:49:13 +08:00
.answer_list {
margin-top: 32px;
2023-02-06 16:06:45 +08:00
2023-02-10 15:49:13 +08:00
.answer_item {
background: #FBFCFE;
border: 1px solid #CCCCCC;
border-radius: 16px;
padding: 28px 24px;
box-sizing: border-box;
2023-02-14 14:06:46 +08:00
margin-bottom: 24px;
2023-02-10 15:49:13 +08:00
.myChoice {
width: 136px;
height: 48px;
background: #FFFFFF;
border: 1px solid #E23C3C;
border-radius: 8px;
}
2023-02-06 16:06:45 +08:00
}
2023-02-14 14:06:46 +08:00
.Checked {
2023-02-10 15:49:13 +08:00
border: 2px solid #2D7EFE;
color: #2D7DFF;
2023-02-14 14:06:46 +08:00
background: #EAF2FF;
}
.Succeed {
border: 2px solid #3BBC37;
color: #3BBC37;
background: #F5FCF5;
2023-02-10 15:49:13 +08:00
}
2023-02-06 16:06:45 +08:00
2023-02-14 14:06:46 +08:00
.Error {
2023-02-10 15:49:13 +08:00
border: 2px solid #E23C3C;
color: #E23C3C;
2023-02-14 14:06:46 +08:00
background: #FDF4F4;
2023-02-10 15:49:13 +08:00
}
2023-02-06 16:06:45 +08:00
}
}
2023-02-10 15:49:13 +08:00
.mar-top {
margin-top: 32px;
}
2023-02-01 18:02:38 +08:00
2023-02-10 15:49:13 +08:00
.btn {
position: fixed;
left: 50%;
bottom: 0;
transform: translate(-50%, -50%);
width: 320px;
height: 88px;
line-height: 88px;
text-align: center;
background: #2D7DFF;
border-radius: 44px;
font-weight: 500;
font-size: 34px;
color: #FFFFFF;
}
2023-01-31 16:19:20 +08:00
}
2023-01-31 09:49:26 +08:00
}
</style>