答题模块

master
橙橙楊 5 years ago committed by luffy
parent 88e36bcfe3
commit 601610d187
  1. 2
      package.json
  2. 4
      src/common/config.js
  3. 2
      src/pages/waste_sorting/query.vue
  4. 118
      src/pages/waste_sorting/question.vue
  5. 8
      yarn.lock

@ -40,7 +40,7 @@
"vuex": "^3.0.1"
},
"devDependencies": {
"@dcloudio/uni-cli-shared": "^2.0.0-23320190923002",
"@dcloudio/uni-cli-shared": "2.0.0-23620191020003",
"@dcloudio/uni-template-compiler": "^2.0.0-23320190923002",
"@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.0-23320190923002",
"@dcloudio/vue-cli-plugin-uni": "^2.0.0-23320190923002",

@ -7,7 +7,9 @@ export var config={
//图片解析
image_parse:"/api/BaiduImage.php",
// 文本查询
text_query:"/api/QueryText.php"
text_query:"/api/QueryText.php",
// 生成题库
create_question:"/api/QuestionAPI.php"
}
}

@ -16,7 +16,7 @@
</view>
<view class="uni-flex uni-column">
<text class="title uni-center">点击图标拍照查询</text>
<text class="title uni-center">打开相机拍照查询</text>
<view class="flex-item flex-item-V uni-center">
<image class="photo" @click="chooseImage"></image>
</view>

@ -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>
</radio-group>
</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>

@ -674,10 +674,10 @@
resolved "https://registry.npm.taobao.org/@dcloudio/uni-app-plus/download/@dcloudio/uni-app-plus-2.0.0-23320190923002.tgz?cache=0&sync_timestamp=1569315602364&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40dcloudio%2Funi-app-plus%2Fdownload%2F%40dcloudio%2Funi-app-plus-2.0.0-23320190923002.tgz#219838f5134fdb53e3d596bfd2bf70a5f493027a"
integrity sha1-IZg49RNP21Pj1Za/0r9wpfSTAno=
"@dcloudio/uni-cli-shared@^2.0.0-23320190923002":
version "2.0.0-23320190923002"
resolved "https://registry.npm.taobao.org/@dcloudio/uni-cli-shared/download/@dcloudio/uni-cli-shared-2.0.0-23320190923002.tgz?cache=0&sync_timestamp=1569315600613&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40dcloudio%2Funi-cli-shared%2Fdownload%2F%40dcloudio%2Funi-cli-shared-2.0.0-23320190923002.tgz#36f803aea3aa2ad7181c7083b553722fe0b8a740"
integrity sha1-NvgDrqOqKtcYHHCDtVNyL+C4p0A=
"@dcloudio/uni-cli-shared@2.0.0-23620191020003":
version "2.0.0-23620191020003"
resolved "https://registry.yarnpkg.com/@dcloudio/uni-cli-shared/-/uni-cli-shared-2.0.0-23620191020003.tgz#a0cc4ddc952129fcbb96b2ed3cef5bf179e7f854"
integrity sha512-eqjgFlDhd3OYmUrVBq3canAnIPFf9sZocQpYujMapZz1sLqx9rhP+caixC0IV3xMuB4WaQXeicDb2cPyg4Qvgw==
dependencies:
hash-sum "^1.0.2"
strip-json-comments "^2.0.1"

Loading…
Cancel
Save