Commit 9e01949a by 冷斌

fix bug

parent 3df94b5e
...@@ -282,10 +282,10 @@ ...@@ -282,10 +282,10 @@
.testPaperAnswer_n { .testPaperAnswer_n {
color: #65C000; color: #65C000;
} }
.testPaperAnswer_e { .testPaperAnswer_e {
color: red; color: red;
} }
.testPaperAnswer_infoBox { .testPaperAnswer_infoBox {
...@@ -335,15 +335,15 @@ ...@@ -335,15 +335,15 @@
<p class="testPaperLei flex1">({{currentQuestionTypeName}})</p> <p class="testPaperLei flex1">({{currentQuestionTypeName}})</p>
<img v-if="currentQuestion.is_collect == 0" @click="onCollect(1)" class="testPaperColl" src="__THEME__/img/share_unstar.png"> <img v-if="currentQuestion.is_collect == 0" @click="onCollect(1)" class="testPaperColl" src="__THEME__/img/share_unstar.png">
<img v-if="currentQuestion.is_collect == 1" @click="onCollect(0)" class="testPaperColl" src="__THEME__/img/share_star.png"> <img v-if="currentQuestion.is_collect == 1" @click="onCollect(0)" class="testPaperColl" src="__THEME__/img/share_star.png">
</div> </div>
<template v-if="showChoiceQuestion"> <template v-if="showChoiceQuestion">
<div v-html="currentQuestion.content" class="testPaperInfo"></div> <div v-html="currentQuestion.content" class="testPaperInfo"></div>
<ul> <ul>
<li v-for="(opt, index) in currentOptions" :key="index" class="testPaperAnswer box"> <li v-for="(opt, index) in currentOptions" :key="index" class="testPaperAnswer box">
<span @click="onChoose(opt)" class="testPaperAnswer_num" :class="opt.selected ? 'testPaperAnswer_numAt' : ''">{{opt.key}}</span> <span @click="onChoose(opt)" class="testPaperAnswer_num" :class="opt.selected ? 'testPaperAnswer_numAt' : ''">{{opt.key}}</span>
<div v-html="opt.value" class="testPaperAnswer_desc flex1" style="margin-top: 0.625rem;"></div> <div v-html="opt.value" class="testPaperAnswer_desc flex1" style="margin-top: 0.625rem;"></div>
</li> </li>
</ul> </ul>
</template> </template>
</div> </div>
<div v-if="current == 1" class="testPaperBtns boxCn"> <div v-if="current == 1" class="testPaperBtns boxCn">
...@@ -395,339 +395,339 @@ ...@@ -395,339 +395,339 @@
new Vue({ new Vue({
el: "#app", el: "#app",
data: function() { data: function() {
return { return {
info: {}, info: {},
temp: {}, temp: {},
current: 1, current: 1,
paperOptions: {}, paperOptions: {},
counting: true, counting: true,
review: false, review: false,
countDown: "00:00:00", countDown: "00:00:00",
timeConsumed: 0, timeConsumed: 0,
expand: false, expand: false,
showPause: false, showPause: false,
showFinish: false, showFinish: false,
//选项 //选项
currentOptions: [], currentOptions: [],
finished: [] finished: []
}
},
computed: {
//computed
nextButton: function() {
if(this.review) {
return this.current == this.totalQuestion ? '返回' : '下一题'
} else {
return this.current == this.totalQuestion ? '交卷' : '下一题'
}
},
totalQuestion: function() {
let count = 0
let data = this.paperOptions.options_questions_data
this.paperOptions.options_type.forEach( r => {
count += data[r.question_type].length
})
return count
},
currentTypeIndex: function() {
let count = 0
let data = this.paperOptions.options_questions_data
let current = this.current
for(let i = 0; i < this.paperOptions.options_type.length; i++) {
let r = this.paperOptions.options_type[i]
let next = count + data[r.question_type].length
if(current > count && current <= next) {
return i
} else {
count = next
}
}
},
currentQuestions: function() {
let optionType = this.currentQuestionType
let questionType = optionType.question_type
let questionData = this.paperOptions.options_questions_data
let questions = questionData[questionType]
return questions
},
currentQuestionType: function() {
return this.paperOptions.options_type[this.currentTypeIndex]
},
currentQuestionTypeName: function() {
return this.currentQuestionType.type_info.question_type_title
},
currentQuestionTypeKey: function() {
return this.currentQuestionType.question_type_key
},
currentQuestion: function() {
let count = 0
let data = this.paperOptions.options_questions_data
let current = this.current
for(let i = 0; i < this.paperOptions.options_type.length; i++) {
let r = this.paperOptions.options_type[i]
let next = count + data[r.question_type].length
if(current > count && current <= next) {
return data[r.question_type][current - count - 1]
} else {
count = next
}
}
},
//选择题答案
currentRightOptions: function() {
return this.currentQuestion.answer_true_option
},
//我的答案
currentMyOptions: function() {
let cur = this.currentRightOptions
return this.currentOptions.filter( r => { return r.selected }).map( r => {
return {
right: cur.hx_indexOf( k => { return k == r.key }) != -1,
key: r.key
}
})
},
//解析
currentAnalyze: function() {
return this.currentQuestion.analyze
},
//Helper
showChoiceQuestion: function() {
let key = this.currentQuestionTypeKey
return key == 'radio' || key == 'multiselect' || key == 'judge'
} }
},
computed: {
//computed
nextButton: function() {
if(this.review) {
return this.current == this.totalQuestion ? '返回' : '下一题'
} else {
return this.current == this.totalQuestion ? '交卷' : '下一题'
}
},
totalQuestion: function() {
let count = 0
let data = this.paperOptions.options_questions_data
this.paperOptions.options_type.forEach( r => {
count += data[r.question_type].length
})
return count
},
currentTypeIndex: function() {
let count = 0
let data = this.paperOptions.options_questions_data
let current = this.current
for(let i = 0; i < this.paperOptions.options_type.length; i++) {
let r = this.paperOptions.options_type[i]
let next = count + data[r.question_type].length
if(current > count && current <= next) {
return i
} else {
count = next
}
}
},
currentQuestions: function() {
let optionType = this.currentQuestionType
let questionType = optionType.question_type
let questionData = this.paperOptions.options_questions_data
let questions = questionData[questionType]
return questions
},
currentQuestionType: function() {
return this.paperOptions.options_type[this.currentTypeIndex]
},
currentQuestionTypeName: function() {
return this.currentQuestionType.type_info.question_type_title
},
currentQuestionTypeKey: function() {
return this.currentQuestionType.question_type_key
},
currentQuestion: function() {
let count = 0
let data = this.paperOptions.options_questions_data
let current = this.current
for(let i = 0; i < this.paperOptions.options_type.length; i++) {
let r = this.paperOptions.options_type[i]
let next = count + data[r.question_type].length
if(current > count && current <= next) {
return data[r.question_type][current - count - 1]
} else {
count = next
}
}
},
//选择题答案
currentRightOptions: function() {
return this.currentQuestion.answer_true_option
},
//我的答案
currentMyOptions: function() {
let cur = this.currentRightOptions
return this.currentOptions.filter( r => { return r.selected }).map( r => {
return {
right: cur.hx_indexOf( k => { return k == r.key }) != -1,
key: r.key
}
})
},
//解析
currentAnalyze: function() {
return this.currentQuestion.analyze
},
//Helper
showChoiceQuestion: function() {
let key = this.currentQuestionTypeKey
return key == 'radio' || key == 'multiselect' || key == 'judge'
}
}, },
created: function() { created: function() {
this.info = {:json_encode($paper)}; this.info = {:json_encode($paper)};
this.temp = {:json_encode($tempData)}; this.temp = {:json_encode($tempData)};
this.paperOptions = {:json_encode($paper_options)}; this.paperOptions = {:json_encode($paper_options)};
this.review = "{$review}" this.review = "{$review}"
this.initAnswerMode() this.initAnswerMode()
this.doCountDown() this.doCountDown()
if(this.review) { if(this.review) {
this.countDown = this.computeTime(this.info.reply_time * 60) this.countDown = this.computeTime(this.info.reply_time * 60)
this.expand = true this.expand = true
} }
console.log("Review = " + this.review) console.log("Review = " + this.review)
console.log(this.info) console.log(this.info)
console.log(this.temp) console.log(this.temp)
console.log(this.paperOptions) console.log(this.paperOptions)
},
watch: {
current: function(o, n) {
this.initAnswerMode()
}
}, },
methods: { watch: {
initAnswerMode: function() { current: function(o, n) {
let q = this.currentQuestionTypeKey this.initAnswerMode()
switch(q) { }
case "radio": },
this.currentOptions = [] methods: {
let Q = this.currentQuestion initAnswerMode: function() {
let old = this.finished.hx_firstOf( r => { return r.qId == Q.exams_question_id }) let q = this.currentQuestionTypeKey
for(let k in Q.answer_options) { switch(q) {
let value = Q.answer_options[k] case "radio":
let select = old ? old.option == k : false this.currentOptions = []
this.currentOptions.push({ let Q = this.currentQuestion
key: k, let old = this.finished.hx_firstOf( r => { return r.qId == Q.exams_question_id })
value: value, for(let k in Q.answer_options) {
selected: select let value = Q.answer_options[k]
}) let select = old ? old.option == k : false
} this.currentOptions.push({
break key: k,
} value: value,
}, selected: select
recordData: function() { })
return { }
paperId: this.info.exams_paper_id, break
timeConsumed: this.timeConsumed, }
questionIndex: this.current, },
finished: this.finished recordData: function() {
} return {
}, paperId: this.info.exams_paper_id,
computeTime: function(time) { timeConsumed: this.timeConsumed,
let hours = Math.floor(time / 3600) questionIndex: this.current,
let minutes = Math.floor((time % 3600) / 60) finished: this.finished
let seconds = Math.round(time % 60) }
return (hours < 10 ? '0' + hours : hours) + ":" + (minutes < 10 ? '0' + minutes : minutes) + ":" + (seconds < 10 ? '0' + seconds : seconds) },
}, computeTime: function(time) {
doCountDown: function() { let hours = Math.floor(time / 3600)
if(!this.counting || this.review) { let minutes = Math.floor((time % 3600) / 60)
return let seconds = Math.round(time % 60)
} return (hours < 10 ? '0' + hours : hours) + ":" + (minutes < 10 ? '0' + minutes : minutes) + ":" + (seconds < 10 ? '0' + seconds : seconds)
if(this.info.reply_time) { },
let time = this.info.reply_time * 60 - this.timeConsumed doCountDown: function() {
if(time <= 0) { if(!this.counting || this.review) {
this.showFinish = true return
} else { }
this.countDown = this.computeTime(time) if(this.info.reply_time) {
setTimeout(this.doCountDown, 1000) let time = this.info.reply_time * 60 - this.timeConsumed
this.timeConsumed += 1 if(time <= 0) {
} this.showFinish = true
} else { } else {
this.countDown = "不限时" this.countDown = this.computeTime(time)
} setTimeout(this.doCountDown, 1000)
}, this.timeConsumed += 1
onCollect: function(collect) { }
let that = this } else {
$.post(U('exams/Index/collect'), { this.countDown = "不限时"
action: collect, }
source_id: that.currentQuestion.exams_question_id },
}, function(res) { onCollect: function(collect) {
let r = JSON.parse(res) let that = this
if(r.status == 1) { $.post(U('exams/Index/collect'), {
that.currentQuestion.is_collect = collect action: collect,
} source_id: that.currentQuestion.exams_question_id
}) }, function(res) {
}, let r = JSON.parse(res)
onChoose: function(opt) { if(r.status == 1) {
if(this.currentQuestionTypeKey == 'radio') { that.currentQuestion.is_collect = collect
this.currentOptions.forEach( r => { }
r.selected = opt.key == r.key })
}) },
} onChoose: function(opt) {
}, if(this.currentQuestionTypeKey == 'radio') {
onCounting: function() { this.currentOptions.forEach( r => {
if(this.counting) { r.selected = opt.key == r.key
this.counting = false })
this.showPause = true }
} else { },
this.counting = true onCounting: function() {
this.doCountDown() if(this.counting) {
} this.counting = false
}, this.showPause = true
onContinue: function() { } else {
this.showPause = false this.counting = true
this.onCounting() this.doCountDown()
}, }
onQuit: function() { },
this.showPause = false onContinue: function() {
this.saveProgress() this.showPause = false
}, this.onCounting()
onCancel: function() { },
this.showFinish = false onQuit: function() {
window.history.back() this.showPause = false
}, this.saveProgress()
onSure: function() { },
this.showFinish = false onCancel: function() {
this.submitPaper() this.showFinish = false
}, window.history.back()
onNextQuestion: function() { },
if(this.current < this.totalQuestion) { onSure: function() {
this.cacheQuestion() this.showFinish = false
if(!this.review) { this.submitPaper()
this.expand = false },
} onNextQuestion: function() {
this.current += 1 if(this.current < this.totalQuestion) {
} else { this.cacheQuestion()
if(!this.review) { if(!this.review) {
this.showFinish = true this.expand = false
} else { }
window.history.back() this.current += 1
} } else {
} if(!this.review) {
}, this.showFinish = true
onPreviousQuestion: function() { } else {
if(this.current > 1) { window.history.back()
this.current -= 1 }
} }
}, },
cacheQuestion: function() { onPreviousQuestion: function() {
if(this.review) { if(this.current > 1) {
return this.current -= 1
} }
let q = this.currentQuestion },
let mode = this.finished.hx_firstOf( r => { return r.qId == q.exams_question_id }) cacheQuestion: function() {
if(mode) { if(this.review) {
switch(this.currentQuestionTypeKey) { return
case "radio": }
let my = this.currentMyOptions let q = this.currentQuestion
if(my.length > 0) { let mode = this.finished.hx_firstOf( r => { return r.qId == q.exams_question_id })
mode.option = my[0].key if(mode) {
} switch(this.currentQuestionTypeKey) {
break case "radio":
} let my = this.currentMyOptions
} else { if(my.length > 0) {
switch(this.currentQuestionTypeKey) { mode.option = my[0].key
case "radio": }
let my = this.currentMyOptions break
if(my.length > 0) { }
this.finished.push({ } else {
qId: q.exams_question_id, switch(this.currentQuestionTypeKey) {
option: my[0].key, case "radio":
key: "radio" let my = this.currentMyOptions
}) if(my.length > 0) {
} this.finished.push({
break qId: q.exams_question_id,
} option: my[0].key,
} key: "radio"
}, })
//Request }
//Collect Params break
collectParam: function() { }
let that = this }
let time = that.info.reply_time * 60 - that.timeConsumed },
let param = { //Request
anser_time: that.timeConsumed, //Collect Params
exams_mode: 1, collectParam: function() {
paper_id: that.info.exams_paper_id, let that = this
ch_id: "{$_GET['s_id']}", let time = that.info.reply_time * 60 - that.timeConsumed
view_url: "{$_GET['view']}", let param = {
is_timeout: time <= 0 ? 1 : 0, anser_time: that.timeConsumed,
paper_options_id: that.paperOptions.exams_paper_options_id, exams_mode: 1,
} paper_id: that.info.exams_paper_id,
that.finished.forEach( r => { ch_id: "{$_GET['s_id']}",
let key = 'user_answer[' + r.qId + ']' view_url: "{$_GET['view']}",
switch(r.key) { is_timeout: time <= 0 ? 1 : 0,
case "radio": paper_options_id: that.paperOptions.exams_paper_options_id,
param[key] = r.option }
break that.finished.forEach( r => {
} let key = 'user_answer[' + r.qId + ']'
}) switch(r.key) {
return param case "radio":
}, param[key] = r.option
saveProgress: function() { break
let that = this }
that.cacheQuestion() })
let param = this.collectParam() return param
$.post( },
U('exams/Index/doProgressExams'), saveProgress: function() {
param, let that = this
function(res) { that.cacheQuestion()
if (typeof(res) != 'object') { let param = this.collectParam()
try { $.post(
let res = JSON.parse(res) U('exams/Index/doProgressExams'),
} catch (e) { param,
ui.error("处理异常,请重新尝试") function(res) {
} if (typeof(res) != 'object') {
} try {
if (res.status == 1) { // let res = JSON.parse(res)
ui.success(res.data.info) } catch (e) {
window.location.href = res.data.jumpurl ui.error("处理异常,请重新尝试")
} else { }
ui.error(res.message) }
} if (res.status == 1) {
}) ui.success(res.data.info)
}, window.location.href = res.data.jumpurl
submitPaper: function() { } else {
let that = this ui.error(res.message)
that.cacheQuestion() }
let param = this.collectParam() }, 'json')
$.post( },
U('exams/Index/doHaddleExams'), submitPaper: function() {
param, let that = this
function(r) { that.cacheQuestion()
let res = JSON.parse(r) let param = this.collectParam()
if (res.status == 1) { $.post(
ui.success(res.data.info) U('exams/Index/doHaddleExams'),
window.location.href = res.data.jumpurl param,
} else { function(r) {
ui.error(res.message) let res = JSON.parse(r)
} if (res.status == 1) {
}) ui.success(res.data.info)
window.location.href = res.data.jumpurl
} else {
ui.error(res.message)
}
})
} }
} }
}) })
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment