@ -3,13 +3,13 @@
< 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" >
< text class = "title uni-center" > { { question . question } } < / text >
< radio -group >
< label class = "uni-list-cell uni-list-cell-pd" v-for ="(answer,a_index) in question.answers " :key ="a_index" >
< text class = "title uni-center" > { { question . question _title } } < / text >
< radio -group @change ="doChange($event,q_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 >
< radio :value ="a_index" / >
< / view >
< view > { { answer } } < / view >
< view :class ="{true_font:show_answer&&answer['is_true']===1}" > { { answer . answer } } < / view >
< / label >
< / r a d i o - g r o u p >
< / view >
@ -27,23 +27,77 @@
< / template >
< script >
import { config , getInterface } from 'common/config'
export default {
name : "question" ,
data : function ( ) {
return {
title : "垃圾百科测验" ,
questions : [ ] ,
isLoad : false
isLoad : false ,
show _answer : false
}
} ,
methods : {
reset : function ( ) {
this . show _answer = false
uni . reLaunch ( {
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 ( ) {
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 ( ) {
@ -51,27 +105,30 @@
uni . showLoading ( {
title : "加载试题中"
} )
let _this = this
console . info ( _this )
setTimeout ( function ( ) {
_this . questions = [
{
question : "测试问题?" ,
answers : [ "答案1" , "答案2" , "答案3" , "答案4" ]
} ,
{
question : "测试问题?" ,
answers : [ "答案1" , "答案2" , "答案3" , "答案4" ]
} ,
{
question : "测试问题?" ,
answers : [ "答案1" , "答案2" , "答案3" , "答案4" ]
let url = getInterface ( config . interface . create _question )
let that = this
console . info ( "创建试题接口:" + url ) ;
uni . request ( {
url : url ,
success : function ( res ) {
console . info ( res . data )
if ( res . data . status ) {
that . questions = res . data . result ;
}
]
_this . isLoad = true
uni . hideLoading ( )
} , 1000 )
}
} ,
fail : function ( err ) {
console . error ( err )
uni . showToast ( {
title : "创建试题失败,请联系管理员"
} )
} ,
complete : function ( ) {
that . isLoad = true
uni . hideLoading ( )
}
} )
} ,
}
< / script >
@ -88,4 +145,15 @@
. button - group {
justify - content : center ;
}
. true {
/*background-color: #75807f;*/
background - color : lightgrey ;
}
. true _font {
color : green ;
font - size : large ;
}
. false {
color : red ;
}
< / style >