mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-12 12:26:44 +08:00
课程内考试,支持选择试卷
This commit is contained in:
@@ -119,6 +119,7 @@
|
||||
<script>
|
||||
import apiStudy from '@/api/modules/courseStudy.js';
|
||||
import apiCourse from '@/api/modules/course.js';
|
||||
import apiExamPaper from '@/api/modules/paper.js';
|
||||
import {formatDate,formatSeconds} from '@/utils/datetime.js';
|
||||
import {testType,correctJudgment,numberToLetter} from '@/utils/tools.js';
|
||||
export default {
|
||||
@@ -168,7 +169,11 @@ export default {
|
||||
records:[] ,//考试记录
|
||||
allowSubmit:true,//是否允许考试,尝试次数达到后不能再考试,暂时未使用
|
||||
detailShow:false,
|
||||
detailItems:[]
|
||||
detailItems:[],
|
||||
examPaper:{
|
||||
json:{},//试题的json格式
|
||||
items:[],//试题内容
|
||||
}
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
@@ -217,8 +222,6 @@ export default {
|
||||
this.total=paper.items.length;
|
||||
this.paper =paper;
|
||||
//console.log(this.paper);
|
||||
|
||||
|
||||
this.viewTest =paper.items;
|
||||
}
|
||||
if(!this.showTest && this.showRecord){
|
||||
@@ -260,30 +263,78 @@ export default {
|
||||
})
|
||||
}
|
||||
},
|
||||
//独立考试的试题转化为课内考试的试题
|
||||
convertToItems(questions){
|
||||
let qitems=[];
|
||||
questions.forEach(item=>{
|
||||
let q={
|
||||
id:item.id,
|
||||
type:item.type==1? 101:item.type==2? 102:103,
|
||||
score:item.defaultScore,
|
||||
checked:false,
|
||||
userAnswer:'',
|
||||
optShow:true,
|
||||
content:item.title,
|
||||
options:[]
|
||||
}
|
||||
item.optionList.forEach(opt=>{
|
||||
q.options.push({
|
||||
id:opt.id,
|
||||
content:opt.content,
|
||||
answer:opt.isAnswer,
|
||||
checked:false
|
||||
})
|
||||
});
|
||||
if(q.type==102){
|
||||
q.userAnswer=[];
|
||||
}
|
||||
qitems.push(q);
|
||||
});
|
||||
return qitems;
|
||||
},
|
||||
startTest(){
|
||||
let paper= JSON.parse(this.info.paperContent);
|
||||
paper.items.forEach(item=>{
|
||||
//console.log(item);
|
||||
if(item.type==101){
|
||||
item.userAnswer='';
|
||||
}else if(item.type==102){
|
||||
item.userAnswer=[];
|
||||
}else{
|
||||
item.userAnswer=''
|
||||
}
|
||||
item.options.forEach(opt=>{
|
||||
opt.checked=false;
|
||||
if(this.info.paperType==2){
|
||||
apiExamPaper.getPaperContent(this.info.paperId).then(rs=>{
|
||||
if(rs.status=200){
|
||||
this.examPaper.json=JSON.parse(rs.result);
|
||||
//console.log(this.examPaper.json,'this.examPaper.json');
|
||||
let qitems=this.convertToItems(this.examPaper.json);
|
||||
this.paper ={items:qitems};
|
||||
this.total=qitems.length;
|
||||
this.curItem=qitems[this.curIndex];
|
||||
this.startTime=new Date();//记录开始时间
|
||||
this.timerValue=this.info.testDuration;
|
||||
this.timer=setInterval(this.changeTimer,60000);
|
||||
this.testStart=true;
|
||||
}else{
|
||||
this.$message.error('加载试卷内容失败,请与管理员联系,试卷是否已删除');
|
||||
}
|
||||
})
|
||||
});
|
||||
this.total=paper.items.length;
|
||||
this.paper =paper;
|
||||
//console.log(this.paper);
|
||||
}else{
|
||||
let paper= JSON.parse(this.info.paperContent);
|
||||
paper.items.forEach(item=>{
|
||||
//console.log(item);
|
||||
if(item.type==101){
|
||||
item.userAnswer='';
|
||||
}else if(item.type==102){
|
||||
item.userAnswer=[];
|
||||
}else{
|
||||
item.userAnswer=''
|
||||
}
|
||||
item.options.forEach(opt=>{
|
||||
opt.checked=false;
|
||||
})
|
||||
});
|
||||
this.total=paper.items.length;
|
||||
this.paper =paper;
|
||||
//console.log(this.paper);
|
||||
|
||||
this.curItem=paper.items[this.curIndex];
|
||||
this.startTime=new Date();//记录开始时间
|
||||
this.timerValue=this.info.testDuration;
|
||||
this.timer=setInterval(this.changeTimer,60000);
|
||||
this.testStart=true;
|
||||
this.curItem=paper.items[this.curIndex];
|
||||
this.startTime=new Date();//记录开始时间
|
||||
this.timerValue=this.info.testDuration;
|
||||
this.timer=setInterval(this.changeTimer,60000);
|
||||
this.testStart=true;
|
||||
}
|
||||
},
|
||||
chooseOption(opt){
|
||||
if(this.curItem.type==101 || this.curItem.type==103){
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<div v-if="cware.content.contentRefId==''">
|
||||
<div style="padding-top: 0px;">
|
||||
<!-- <div> -->
|
||||
<choose-course-file ref="coursewarePanel" :resType="cware.content.contentType" @choose="chooseFile"></choose-course-file>
|
||||
<choose-course-file :orgId="course.orgId" :orgName="course.orgName" ref="coursewarePanel" :resType="cware.content.contentType" @choose="chooseFile"></choose-course-file>
|
||||
|
||||
<!-- <file-upload
|
||||
:fileType="getFileTypes(cware.content.contentType)"
|
||||
@@ -417,7 +417,11 @@
|
||||
</div>
|
||||
<div style="padding-top: 10px;">
|
||||
<el-form size="small" label-width="80px">
|
||||
<el-form-item label="考试时长">
|
||||
<el-form-item label="试卷类型">
|
||||
{{exam.info.paperType==1? '自定义试卷':'使用考试试卷: '+usePaper.paperName}}
|
||||
|
||||
</el-form-item>
|
||||
<el-form-item label="考试时长">
|
||||
<el-col :span="6">{{exam.info.passScore}}分钟</el-col>
|
||||
<!-- <el-col :span="9">
|
||||
<el-form-item label="尝试次数">{{exam.info.times}}</el-form-item>
|
||||
@@ -890,7 +894,18 @@
|
||||
apiCourse.getExam(this.exam.content.id).then(res=>{
|
||||
if(res.status==200){
|
||||
this.exam.info=res.result;
|
||||
this.exam.paperJson=JSON.parse(res.result.paperContent);
|
||||
if(res.result.paperType==1){
|
||||
this.exam.paperJson=JSON.parse(res.result.paperContent);
|
||||
}else{
|
||||
apiExamPaper.detail(this.exam.info.paperId).then(rs=>{
|
||||
if(rs.status==200){
|
||||
this.usePaper.paperId=rs.result.id;
|
||||
this.usePaper.paperName=rs.result.testName;
|
||||
this.usePaper.counts=rs.result.counts;
|
||||
//this.usePaper.paperJson= rs.result.paperContent;
|
||||
}
|
||||
})
|
||||
}
|
||||
this.exam.show=9;
|
||||
this.examChange = deepClone(this.exam);
|
||||
}else if(res.status==404){
|
||||
@@ -1035,30 +1050,38 @@
|
||||
this.homeworkChange = deepClone(this.homework)
|
||||
}else if(index==3){
|
||||
postData.content=this.exam.content;
|
||||
//检查是不是所有的试题都有了答案
|
||||
if(this.exam.paperJson.items.length==0){
|
||||
this.$message.error("您还没有添加考试的试题");
|
||||
return;
|
||||
}
|
||||
let pass=true;
|
||||
this.exam.paperJson.items.forEach(qitem=>{
|
||||
if(qitem.options.length==0){
|
||||
pass=false;
|
||||
}else{
|
||||
let hasAnswer=qitem.options.some(opt=>{
|
||||
return opt.answer;
|
||||
});
|
||||
if(!hasAnswer){
|
||||
//console.log(this.exam,'this.exam');
|
||||
if(this.exam.info.paperType==2){
|
||||
if(!this.exam.info.paperId){
|
||||
this.$message.error("您还未选择任何试卷");
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
//检查是不是所有的试题都有了答案
|
||||
if(this.exam.paperJson.items.length==0){
|
||||
this.$message.error("您还没有添加考试的试题");
|
||||
return;
|
||||
}
|
||||
let pass=true;
|
||||
this.exam.paperJson.items.forEach(qitem=>{
|
||||
if(qitem.options.length==0){
|
||||
pass=false;
|
||||
}else{
|
||||
let hasAnswer=qitem.options.some(opt=>{
|
||||
return opt.answer;
|
||||
});
|
||||
if(!hasAnswer){
|
||||
pass=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if(!pass){
|
||||
this.$message.error("试卷试题请填写完整,每个试题必须要有答案");
|
||||
this.loading=false;
|
||||
return;
|
||||
});
|
||||
if(!pass){
|
||||
this.$message.error("试卷试题请填写完整,每个试题必须要有答案");
|
||||
this.loading=false;
|
||||
return;
|
||||
}
|
||||
this.exam.info.paperContent=JSON.stringify(this.exam.paperJson);
|
||||
}
|
||||
this.exam.info.paperContent=JSON.stringify(this.exam.paperJson);
|
||||
postData.exam=this.exam.info;
|
||||
this.examChange = deepClone(this.exam);
|
||||
}else if(index==4){
|
||||
@@ -1265,15 +1288,15 @@
|
||||
},
|
||||
openCusExam(){ //自定义考试
|
||||
this.exam.show=3;
|
||||
this.exam.paperType=1;
|
||||
this.exam.paperId='';
|
||||
this.exam.info.paperType=1;
|
||||
this.exam.info.paperId='';
|
||||
this.usePaper.pageIndex=1;
|
||||
this.usePaper.keyword="";
|
||||
},
|
||||
openChoosePaper(){
|
||||
this.exam.show=2;
|
||||
this.exam.paperType=3;
|
||||
this.exam.paperId='';
|
||||
this.exam.info.paperType=2; //选择试卷
|
||||
this.exam.info.paperId='';
|
||||
},
|
||||
findExamPapers(){ //查询已有的考试试卷
|
||||
this.usePaper.pageIndex=1;
|
||||
@@ -1319,6 +1342,7 @@
|
||||
if(rs.status==200){
|
||||
this.usePaper.paperId=rs.result.id;
|
||||
this.usePaper.paperName=rs.result.testName;
|
||||
this.usePaper.counts=rs.result.counts;
|
||||
//this.usePaper.paperJson= rs.result.paperContent;
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user