Commit 9e01949a by 冷斌

fix bug

parent 3df94b5e
......@@ -282,10 +282,10 @@
.testPaperAnswer_n {
color: #65C000;
}
.testPaperAnswer_e {
color: red;
}
.testPaperAnswer_e {
color: red;
}
.testPaperAnswer_infoBox {
......@@ -335,15 +335,15 @@
<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 == 1" @click="onCollect(0)" class="testPaperColl" src="__THEME__/img/share_star.png">
</div>
<template v-if="showChoiceQuestion">
<div v-html="currentQuestion.content" class="testPaperInfo"></div>
<ul>
<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>
<div v-html="opt.value" class="testPaperAnswer_desc flex1" style="margin-top: 0.625rem;"></div>
</li>
</ul>
</div>
<template v-if="showChoiceQuestion">
<div v-html="currentQuestion.content" class="testPaperInfo"></div>
<ul>
<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>
<div v-html="opt.value" class="testPaperAnswer_desc flex1" style="margin-top: 0.625rem;"></div>
</li>
</ul>
</template>
</div>
<div v-if="current == 1" class="testPaperBtns boxCn">
......@@ -395,339 +395,339 @@
new Vue({
el: "#app",
data: function() {
return {
info: {},
temp: {},
current: 1,
paperOptions: {},
counting: true,
review: false,
countDown: "00:00:00",
timeConsumed: 0,
expand: false,
showPause: false,
showFinish: false,
//选项
currentOptions: [],
finished: []
return {
info: {},
temp: {},
current: 1,
paperOptions: {},
counting: true,
review: false,
countDown: "00:00:00",
timeConsumed: 0,
expand: false,
showPause: false,
showFinish: false,
//选项
currentOptions: [],
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() {
this.info = {:json_encode($paper)};
this.temp = {:json_encode($tempData)};
this.paperOptions = {:json_encode($paper_options)};
this.review = "{$review}"
this.initAnswerMode()
this.doCountDown()
if(this.review) {
this.countDown = this.computeTime(this.info.reply_time * 60)
this.expand = true
}
console.log("Review = " + this.review)
console.log(this.info)
console.log(this.temp)
created: function() {
this.info = {:json_encode($paper)};
this.temp = {:json_encode($tempData)};
this.paperOptions = {:json_encode($paper_options)};
this.review = "{$review}"
this.initAnswerMode()
this.doCountDown()
if(this.review) {
this.countDown = this.computeTime(this.info.reply_time * 60)
this.expand = true
}
console.log("Review = " + this.review)
console.log(this.info)
console.log(this.temp)
console.log(this.paperOptions)
},
watch: {
current: function(o, n) {
this.initAnswerMode()
}
},
methods: {
initAnswerMode: function() {
let q = this.currentQuestionTypeKey
switch(q) {
case "radio":
this.currentOptions = []
let Q = this.currentQuestion
let old = this.finished.hx_firstOf( r => { return r.qId == Q.exams_question_id })
for(let k in Q.answer_options) {
let value = Q.answer_options[k]
let select = old ? old.option == k : false
this.currentOptions.push({
key: k,
value: value,
selected: select
})
}
break
}
},
recordData: function() {
return {
paperId: this.info.exams_paper_id,
timeConsumed: this.timeConsumed,
questionIndex: this.current,
finished: this.finished
}
},
computeTime: function(time) {
let hours = Math.floor(time / 3600)
let minutes = Math.floor((time % 3600) / 60)
let seconds = Math.round(time % 60)
return (hours < 10 ? '0' + hours : hours) + ":" + (minutes < 10 ? '0' + minutes : minutes) + ":" + (seconds < 10 ? '0' + seconds : seconds)
},
doCountDown: function() {
if(!this.counting || this.review) {
return
}
if(this.info.reply_time) {
let time = this.info.reply_time * 60 - this.timeConsumed
if(time <= 0) {
this.showFinish = true
} else {
this.countDown = this.computeTime(time)
setTimeout(this.doCountDown, 1000)
this.timeConsumed += 1
}
} else {
this.countDown = "不限时"
}
},
onCollect: function(collect) {
let that = this
$.post(U('exams/Index/collect'), {
action: collect,
source_id: that.currentQuestion.exams_question_id
}, function(res) {
let r = JSON.parse(res)
if(r.status == 1) {
that.currentQuestion.is_collect = collect
}
})
},
onChoose: function(opt) {
if(this.currentQuestionTypeKey == 'radio') {
this.currentOptions.forEach( r => {
r.selected = opt.key == r.key
})
}
},
onCounting: function() {
if(this.counting) {
this.counting = false
this.showPause = true
} else {
this.counting = true
this.doCountDown()
}
},
onContinue: function() {
this.showPause = false
this.onCounting()
},
onQuit: function() {
this.showPause = false
this.saveProgress()
},
onCancel: function() {
this.showFinish = false
window.history.back()
},
onSure: function() {
this.showFinish = false
this.submitPaper()
},
onNextQuestion: function() {
if(this.current < this.totalQuestion) {
this.cacheQuestion()
if(!this.review) {
this.expand = false
}
this.current += 1
} else {
if(!this.review) {
this.showFinish = true
} else {
window.history.back()
}
}
},
onPreviousQuestion: function() {
if(this.current > 1) {
this.current -= 1
}
},
cacheQuestion: function() {
if(this.review) {
return
}
let q = this.currentQuestion
let mode = this.finished.hx_firstOf( r => { return r.qId == q.exams_question_id })
if(mode) {
switch(this.currentQuestionTypeKey) {
case "radio":
let my = this.currentMyOptions
if(my.length > 0) {
mode.option = my[0].key
}
break
}
} else {
switch(this.currentQuestionTypeKey) {
case "radio":
let my = this.currentMyOptions
if(my.length > 0) {
this.finished.push({
qId: q.exams_question_id,
option: my[0].key,
key: "radio"
})
}
break
}
}
},
//Request
//Collect Params
collectParam: function() {
let that = this
let time = that.info.reply_time * 60 - that.timeConsumed
let param = {
anser_time: that.timeConsumed,
exams_mode: 1,
paper_id: that.info.exams_paper_id,
ch_id: "{$_GET['s_id']}",
view_url: "{$_GET['view']}",
is_timeout: time <= 0 ? 1 : 0,
paper_options_id: that.paperOptions.exams_paper_options_id,
}
that.finished.forEach( r => {
let key = 'user_answer[' + r.qId + ']'
switch(r.key) {
case "radio":
param[key] = r.option
break
}
})
return param
},
saveProgress: function() {
let that = this
that.cacheQuestion()
let param = this.collectParam()
$.post(
U('exams/Index/doProgressExams'),
param,
function(res) {
if (typeof(res) != 'object') {
try {
let res = JSON.parse(res)
} catch (e) {
ui.error("处理异常,请重新尝试")
}
}
if (res.status == 1) {
ui.success(res.data.info)
window.location.href = res.data.jumpurl
} else {
ui.error(res.message)
}
})
},
submitPaper: function() {
let that = this
that.cacheQuestion()
let param = this.collectParam()
$.post(
U('exams/Index/doHaddleExams'),
param,
function(r) {
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)
}
})
watch: {
current: function(o, n) {
this.initAnswerMode()
}
},
methods: {
initAnswerMode: function() {
let q = this.currentQuestionTypeKey
switch(q) {
case "radio":
this.currentOptions = []
let Q = this.currentQuestion
let old = this.finished.hx_firstOf( r => { return r.qId == Q.exams_question_id })
for(let k in Q.answer_options) {
let value = Q.answer_options[k]
let select = old ? old.option == k : false
this.currentOptions.push({
key: k,
value: value,
selected: select
})
}
break
}
},
recordData: function() {
return {
paperId: this.info.exams_paper_id,
timeConsumed: this.timeConsumed,
questionIndex: this.current,
finished: this.finished
}
},
computeTime: function(time) {
let hours = Math.floor(time / 3600)
let minutes = Math.floor((time % 3600) / 60)
let seconds = Math.round(time % 60)
return (hours < 10 ? '0' + hours : hours) + ":" + (minutes < 10 ? '0' + minutes : minutes) + ":" + (seconds < 10 ? '0' + seconds : seconds)
},
doCountDown: function() {
if(!this.counting || this.review) {
return
}
if(this.info.reply_time) {
let time = this.info.reply_time * 60 - this.timeConsumed
if(time <= 0) {
this.showFinish = true
} else {
this.countDown = this.computeTime(time)
setTimeout(this.doCountDown, 1000)
this.timeConsumed += 1
}
} else {
this.countDown = "不限时"
}
},
onCollect: function(collect) {
let that = this
$.post(U('exams/Index/collect'), {
action: collect,
source_id: that.currentQuestion.exams_question_id
}, function(res) {
let r = JSON.parse(res)
if(r.status == 1) {
that.currentQuestion.is_collect = collect
}
})
},
onChoose: function(opt) {
if(this.currentQuestionTypeKey == 'radio') {
this.currentOptions.forEach( r => {
r.selected = opt.key == r.key
})
}
},
onCounting: function() {
if(this.counting) {
this.counting = false
this.showPause = true
} else {
this.counting = true
this.doCountDown()
}
},
onContinue: function() {
this.showPause = false
this.onCounting()
},
onQuit: function() {
this.showPause = false
this.saveProgress()
},
onCancel: function() {
this.showFinish = false
window.history.back()
},
onSure: function() {
this.showFinish = false
this.submitPaper()
},
onNextQuestion: function() {
if(this.current < this.totalQuestion) {
this.cacheQuestion()
if(!this.review) {
this.expand = false
}
this.current += 1
} else {
if(!this.review) {
this.showFinish = true
} else {
window.history.back()
}
}
},
onPreviousQuestion: function() {
if(this.current > 1) {
this.current -= 1
}
},
cacheQuestion: function() {
if(this.review) {
return
}
let q = this.currentQuestion
let mode = this.finished.hx_firstOf( r => { return r.qId == q.exams_question_id })
if(mode) {
switch(this.currentQuestionTypeKey) {
case "radio":
let my = this.currentMyOptions
if(my.length > 0) {
mode.option = my[0].key
}
break
}
} else {
switch(this.currentQuestionTypeKey) {
case "radio":
let my = this.currentMyOptions
if(my.length > 0) {
this.finished.push({
qId: q.exams_question_id,
option: my[0].key,
key: "radio"
})
}
break
}
}
},
//Request
//Collect Params
collectParam: function() {
let that = this
let time = that.info.reply_time * 60 - that.timeConsumed
let param = {
anser_time: that.timeConsumed,
exams_mode: 1,
paper_id: that.info.exams_paper_id,
ch_id: "{$_GET['s_id']}",
view_url: "{$_GET['view']}",
is_timeout: time <= 0 ? 1 : 0,
paper_options_id: that.paperOptions.exams_paper_options_id,
}
that.finished.forEach( r => {
let key = 'user_answer[' + r.qId + ']'
switch(r.key) {
case "radio":
param[key] = r.option
break
}
})
return param
},
saveProgress: function() {
let that = this
that.cacheQuestion()
let param = this.collectParam()
$.post(
U('exams/Index/doProgressExams'),
param,
function(res) {
if (typeof(res) != 'object') {
try {
// let res = JSON.parse(res)
} catch (e) {
ui.error("处理异常,请重新尝试")
}
}
if (res.status == 1) {
ui.success(res.data.info)
window.location.href = res.data.jumpurl
} else {
ui.error(res.message)
}
}, 'json')
},
submitPaper: function() {
let that = this
that.cacheQuestion()
let param = this.collectParam()
$.post(
U('exams/Index/doHaddleExams'),
param,
function(r) {
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