@ -3,13 +3,13 @@
< view class = "uni-padding-wrap uni-common-mt" v-if ="isLoad" >
< view class = "uni-padding-wrap uni-common-mt" v-if ="isLoad" >
< view v-for ="(question,q_index) in questions" :key="q_index" class="question uni-flex uni-column" >
< view v-for ="(question,q_index) in questions" :key="q_index" class="question uni-flex uni-column" >
< text class = "title uni-center" > { { question . question } } < / text >
< text class = "title uni-center" > { { question . question _title } } < / text >
< radio -group >
< radio -group @change ="doChange($event,q_index)" >
< label class = "uni-list-cell uni-list-cell-pd" v-for ="(answer,a_index) in question.answers " :key ="a_index" >
< label class = "uni-list-cell uni-list-cell-pd" :class ="{true:show_answer&&answer['is_true']===1}" v-for ="(answer,a_index) in question.answer" :key ="a_index" >
< view >
< view >
< radio :value ="a_index" / >
< radio :value ="a_index" / >
< / view >
< / view >
< view > { { answer } } < / view >
< view :class ="{true_font:show_answer&&answer['is_true']===1}" > { { answer . answer } } < / view >
< / label >
< / label >
< / r a d i o - g r o u p >
< / r a d i o - g r o u p >
< / view >
< / view >
@ -27,23 +27,77 @@
< / template >
< / template >
< script >
< script >
import { config , getInterface } from 'common/config'
export default {
export default {
name : "question" ,
name : "question" ,
data : function ( ) {
data : function ( ) {
return {
return {
title : "垃圾百科测验" ,
title : "垃圾百科测验" ,
questions : [ ] ,
questions : [ ] ,
isLoad : false
isLoad : false ,
show _answer : false
}
}
} ,
} ,
methods : {
methods : {
reset : function ( ) {
reset : function ( ) {
this . show _answer = false
uni . reLaunch ( {
uni . reLaunch ( {
url : 'question'
url : 'question'
} ) ;
} ) ;
} ,
} ,
check : function ( true _count ) {
let count = this . questions . length
let that = this
this . show _answer = true
uni . showModal ( {
title : "答题结果" ,
content : "共" + count + "题,对错比:" + true _count + "/" + ( count - true _count ) ,
cancelText : "再来一次" ,
success : function ( res ) {
if ( res . cancel ) {
that . reset ( )
}
}
} )
} ,
submit : function ( ) {
submit : function ( ) {
console . info ( "提交答卷" )
console . info ( "提交答卷" )
let true _count = 0 ;
let that = this
for ( let index in this . questions ) {
if ( this . questions [ index ] [ "is_true" ] ) {
true _count ++
}
if ( ! this . questions [ index ] . hasOwnProperty ( "submit_answer" ) ) {
uni . showModal ( {
title : "提示信息" ,
content : "有题目没有填写答案,确认提交答卷?" ,
confirmText : "提交答卷" ,
cancelText : "继续答卷" ,
success : function ( res ) {
if ( res . confirm ) {
that . check ( true _count )
}
} ,
fail : function ( err ) {
console . error ( err )
uni . showToast ( {
title : "审核答卷异常,请联系管理员"
} )
}
} )
return
}
}
this . check ( true _count )
} ,
doChange : function ( e , q _index ) {
this . questions [ q _index ] [ "submit_answer" ] = parseInt ( e . target . value ) ;
this . questions [ q _index ] [ "is_true" ] = this . questions [ q _index ] [ "submit_answer" ] === this . questions [ q _index ] [ "right_answer" ]
}
}
} ,
} ,
onShow : function ( ) {
onShow : function ( ) {
@ -51,27 +105,30 @@
uni . showLoading ( {
uni . showLoading ( {
title : "加载试题中"
title : "加载试题中"
} )
} )
let _this = this
let url = getInterface ( config . interface . create _question )
console . info ( _this )
let that = this
setTimeout ( function ( ) {
console . info ( "创建试题接口:" + url ) ;
_this . questions = [
uni . request ( {
{
url : url ,
question : "测试问题?" ,
success : function ( res ) {
answers : [ "答案1" , "答案2" , "答案3" , "答案4" ]
console . info ( res . data )
if ( res . data . status ) {
that . questions = res . data . result ;
}
} ,
} ,
{
fail : function ( err ) {
question : "测试问题?" ,
console . error ( err )
answers : [ "答案1" , "答案2" , "答案3" , "答案4" ]
uni . showToast ( {
title : "创建试题失败,请联系管理员"
} )
} ,
} ,
{
complete : function ( ) {
question : "测试问题?" ,
that . isLoad = true
answers : [ "答案1" , "答案2" , "答案3" , "答案4" ]
}
]
_this . isLoad = true
uni . hideLoading ( )
uni . hideLoading ( )
} , 1000 )
}
}
} )
} ,
}
}
< / script >
< / script >
@ -88,4 +145,15 @@
. button - group {
. button - group {
justify - content : center ;
justify - content : center ;
}
}
. true {
/*background-color: #75807f;*/
background - color : lightgrey ;
}
. true _font {
color : green ;
font - size : large ;
}
. false {
color : red ;
}
< / style >
< / style >