From 9f2ac61439c6c8e9a685231bce1fac97d9eea6bb Mon Sep 17 00:00:00 2001 From: shijing Date: Mon, 14 Nov 2022 17:02:58 +0800 Subject: [PATCH] exam_mp --- client_mp/common/http.api.js | 9 +- client_mp/pages.json | 12 +- client_mp/pages/exam/detail.vue | 326 ++++++++++++++++++++++++++ client_mp/pages/exam/main.vue | 389 ++++++++++++++++++++++++++++++- client_mp/pages/exam/preview.vue | 4 + client_mp/pages/exam/record.vue | 34 +-- client_mp/pages/exam/result.vue | 34 +-- client_mp/pages/my/my.vue | 25 +- 8 files changed, 768 insertions(+), 65 deletions(-) create mode 100644 client_mp/pages/exam/detail.vue diff --git a/client_mp/common/http.api.js b/client_mp/common/http.api.js index 0a38d7a..c8225e3 100644 --- a/client_mp/common/http.api.js +++ b/client_mp/common/http.api.js @@ -49,6 +49,10 @@ const install = (Vue, vm) => { //考试有关 let getExamList = (params={})=>vm.$u.get('/exam/exam/', params);//考试列表 let startExam = (id)=>vm.$u.post(`/exam/exam/${id}/start/`);//开始考试 + let submitExam = (id,params={})=>vm.$u.post(`/exam/examrecord/${id}/submit/`,params);//开始考试 + let examRecord = (id,params={})=>vm.$u.get(`/exam/examrecord/self/`,params);//我的考试记录 + let examRecordDetail = (id,params={})=>vm.$u.get(`/exam/examrecord/${id}/`,params);//我的考试记录 + vm.$u.api = {getUserInfo, getCode, codeLogin, @@ -72,7 +76,10 @@ const install = (Vue, vm) => { putMyVideoView, getExamList, - startExam + startExam, + submitExam, + examRecord, + examRecordDetail }; } diff --git a/client_mp/pages.json b/client_mp/pages.json index d388705..047e8a1 100644 --- a/client_mp/pages.json +++ b/client_mp/pages.json @@ -173,6 +173,14 @@ "enablePullDownRefresh": false } + },{ + "path" : "pages/exam/detail", + "style" : + { + "navigationBarTitleText": "答题详情", + "enablePullDownRefresh": false + } + } ], "globalStyle": { @@ -194,8 +202,8 @@ }, { "pagePath": "pages/exam/index", - "iconPath": "static/common/play.png", - "selectedIconPath": "static/common/playc.png", + "iconPath": "static/common/dati.png", + "selectedIconPath": "static/common/datic.png", "text": "答题" }, { diff --git a/client_mp/pages/exam/detail.vue b/client_mp/pages/exam/detail.vue new file mode 100644 index 0000000..058e1ab --- /dev/null +++ b/client_mp/pages/exam/detail.vue @@ -0,0 +1,326 @@ + + + + + \ No newline at end of file diff --git a/client_mp/pages/exam/main.vue b/client_mp/pages/exam/main.vue index 8183fd0..aff9d3c 100644 --- a/client_mp/pages/exam/main.vue +++ b/client_mp/pages/exam/main.vue @@ -1,6 +1,70 @@ @@ -8,15 +72,328 @@ export default { data() { return { - - } + currentExam:{questions_:[]}, + currentIndex:0, + currentOptions:[], + currentQuestion:{type:'单选'}, + showM:false, + keyid:0, + start_time:null, + scollHeight:0 + } + }, + onLoad() { + //#ifdef MP-WEIXIN + uni.hideHomeButton() + //#endif + this.start_time= (new Date()).getTime() + this.currentExam = uni.getStorageSync('currentExam') + let res = uni.getSystemInfoSync(); + let ratio = 750 / res.windowWidth; + this.scollHeight = res.windowHeight*ratio - 230 + this.initQuestion() }, methods: { - + end(){ + var that = this + uni.showModal({ + title: '警告', + content: '时间到,请交卷', + showCancel:false, + success: function (res) { + if (res.confirm) { + that.handIn(); + } + } + }); + + }, + change(){ + + }, + handleSubmit(){ + var that = this + let questions = that.currentExam.questions_; + for(var i=0;i{ + uni.setStorageSync('currentExam',res.data) + uni.hideLoading() + uni.redirectTo({ + url:'/pages/exam/result' + }) + }).catch(e=>{ + if(res.msg){ + uni.showModal({ + title:'提交失败', + content:res.msg, + showCancel:false, + success(res) { + uni.reLaunch({ + url:'/pages/index/index' + }) + } + }) + } + + }) + // let questions = this.currentExam.questions + // let score=0 + // for(var i=0, lenI =questions.length;i=this.currentExam.pass_score){ + // this.currentExam.is_pass=true + // }else{ + // this.currentExam.is_pass=false + // } + // if(this.vuex_user.id){ + + // } + // else{ + // uni.setStorageSync('currentExam',this.currentExam) + // uni.hideLoading() + // uni.redirectTo({ + // url:'/pages/exam/result' + // }) + // } + }, + panTi(tm_current) { + // 返回当前题目是否正确,得分多少 + let is_right = false, score = 0 + if (tm_current.type == '多选') { + if (tm_current.user_answer) { + if (tm_current.user_answer.sort().toString() == tm_current.right.sort().toString()) { + is_right = true + score = tm_current.total_score + } + } + } else { + if(tm_current.right == tm_current.user_answer){ + is_right = true + score = tm_current.total_score + } + } + return {'is_right':is_right,'score':score} + }, + initQuestion(){ + var currentQuestion = this.currentExam.questions_[this.currentIndex]; + this.currentQuestion = currentQuestion; + let options_ = []; + let origin = currentQuestion.options; + this.currentOptions = []; + for (let key in origin) { + let option = { + value:key, + text:origin[key], + id: this.keyid++, + checked:false + } + if (currentQuestion.user_answer) { + if (key == currentQuestion.user_answer || currentQuestion.user_answer.indexOf(key) != -1) { + option.checked = true + } + } else { + option.checked = false + } + options_.push(option) + } + this.currentOptions = options_ + }, + nextQ(){ + let index = this.currentIndex + 1 + if(index= 0){ + this.currentIndex = index + this.initQuestion() + } + }, + checkboxGroupChange(e){ + // debugger; + console.log(e) + this.currentExam.questions_[this.currentIndex].user_answer = e.detail.value + }, + jumpQuestion(index){ + this.currentIndex = index + this.initQuestion() + this.showM = false + } } } - + .header { + width: 750rpx; + text-align: center; + height: 60rpx; + line-height: 60rpx; + font-size: 36rpx; + font-weight: 600; + color: $theme-color; + background-color: #FFFFFF; + + &-button { + position: absolute; + right: 10rpx; + font-size:34rpx; + font-weight: bold; + color: #000; + } + + .scoreText { + color: #00b060; + font-size: 35rpx; + } + } + .sub-header { + padding: 4rpx 20rpx; + color: #000; + font-size: 33rpx; + font-weight: bold; + background-color: #FFFFFF; + } + .submitButton{ + padding: 6rpx 20rpx; + border-radius: 15rpx; + font-weight: bold; + color: #ffffff; + background-color: $u-type-error; + } + .header-card { + padding: 6rpx 20rpx; + border-radius: 15rpx; + color: #FFFFFF; + background-color: $u-type-primary-dark; + } + .footer { + width: 750rpx; + height: 100rpx; + padding: 30rpx 60rpx; + position: fixed; + bottom: 20rpx; + display: flex; + align-items: center; + justify-content: space-between; + font-size: 32rpx; + box-sizing: border-box; + color: #4c8af3; + box-shadow: 0 0 5px 1px #eee; + background-color: #FFFFFF; + + &-card { + padding: 10rpx 20rpx; + border: 1px solid $theme-color; + border-radius: 15rpx; + color: #FFFFFF; + background-color: $theme-color; + } + } + .questionArea { + display: flex; + flex-direction: row; + flex-wrap: wrap; + margin-bottom: 20rpx; + + .questionItem { + width: 80rpx; + height: 80rpx; + margin: 10rpx 22rpx; + line-height: 80rpx; + font-size: 35rpx; + text-align: center; + border-radius: 50%; + color: #ffffff; + } + .questionItem-select { + background-color: $theme-color; + } + + .questionItem-unselect { + background-color: #bbbbbb; + } + } + + + \ No newline at end of file diff --git a/client_mp/pages/exam/preview.vue b/client_mp/pages/exam/preview.vue index ad4097a..440ddc9 100644 --- a/client_mp/pages/exam/preview.vue +++ b/client_mp/pages/exam/preview.vue @@ -37,6 +37,10 @@ methods: { start(){ this.$u.api.startExam(this.currentExam.id).then(res=>{ + let currentExam =uni.getStorageSync('currentExam'); + currentExam.examrecord = res.data.examrecord; + currentExam.questions_ = res.data.questions_; + uni.setStorageSync('currentExam',currentExam) uni.reLaunch({ url:'/pages/exam/main' }) diff --git a/client_mp/pages/exam/record.vue b/client_mp/pages/exam/record.vue index c716c20..ed027df 100644 --- a/client_mp/pages/exam/record.vue +++ b/client_mp/pages/exam/record.vue @@ -2,21 +2,17 @@ - - - - - - {{loadingText}} @@ -63,7 +45,7 @@ methods: { getList() { var that = this - that.$u.api.getMyExamRecord(that.listQuery).then(res => { + that.$u.api.examRecord(that.listQuery).then(res => { uni.stopPullDownRefresh() uni.setNavigationBarTitle({ title: res.data.count + '条答题记录' @@ -90,11 +72,11 @@ uni.showLoading({ title:"正在获取答题详情", }) - this.$u.api.getExamRecordDetail(id).then(res=>{ + this.$u.api.examRecordDetail(id).then(res=>{ uni.hideLoading() uni.setStorageSync('currentExam', res.data) - if (res.data.questions.length>0){ - uni.redirectTo({ + if (res.data.questions_.length>0){ + uni.navigateTo({ url:'/pages/exam/detail?examrecord='+id }) } diff --git a/client_mp/pages/exam/result.vue b/client_mp/pages/exam/result.vue index a79e1e3..6501a9a 100644 --- a/client_mp/pages/exam/result.vue +++ b/client_mp/pages/exam/result.vue @@ -28,15 +28,22 @@ }, methods: { goDetail(){ - uni.showLoading({ - title:"正在获取答题详情", - }) - this.$u.api.getExamRecordDetail(this.currentExam.id).then(res=>{ + this.$u.api.examRecordDetail(this.currentExam.id).then(res=>{ uni.hideLoading() - uni.setStorageSync('currentExam', res.data) - uni.redirectTo({ - url:'/pages/exam/detail?examrecord='+this.currentExam.id - }) + uni.setStorageSync('currentExam', res.data); + debugger; + if (res.data.questions_.length>0){ + uni.redirectTo({ + url:'/pages/exam/detail?examrecord='+res.data.id + }) + } + else{ + uni.showToast({ + title:'获取失败', + icon:'none' + }) + return + } }).catch(e=>{ }) }, @@ -47,7 +54,7 @@ } }, onLoad(options){ - this.currentExam = uni.getStorageSync('currentExam') + this.currentExam = uni.getStorageSync('currentExam'); }, } @@ -55,12 +62,13 @@