// pages/answer/index.js
import { $wuxCountDown } from '../../wux/index'
const { $Message } = require('../../dist/base/index');
Page({
data: {
loading: true, //加载中
result: {}, //题目
total: 0, //题目总总数
menu:'',//套题id
questionMenu:'',//套题名称
percent: 0, //进度条百分比
time: 45, //时间
Countdown: '', //倒计时
s: ['A. ', 'B. ', 'C. ', 'D. ', 'E. '],
index: 1, //第几题
current: '', //单选选中的答案
currentD: [], //多选选中的答案
type: '', //题目类型 1:单选 2:多选
disabled: false, //单选选中不可选
disabled1: false, //多选选中不可选
actionVisible: false, //弹出层
questionErr: 0,//错题个数
questionOk: 0,// 正确个数
percentage: 0,
visible1:false,
visible2:false,
visible3:false,
visible4:false,
action1:[
{
name: '取消'
},
{
name: '确定',
color: '#2db7f5',
loading: false
}
],
action2:[
{
name: '确定',
color: '#2db7f5',
loading: false
}
],
actions3: [
{
name: '重新答题',
color: '#2d8cf0',
},
{
name: '继续答题',
color: '#19be6b'
}
],
action4: [
{
name: '取消'
},
{
name: '确定',
color: '#2db7f5',
loading: false
}
],
showVideo:false
},
onLoad(e) {
var that = this;
var menu = e.id;
var questionMenu = e.questionMenu;
this.setData({
menu: menu,
questionMenu: questionMenu
})
wx.getSystemInfo({
success(res) {
that.setData({
windowWidth: res.windowWidth
})
}
})
wx.u.checkSaveHistory(menu).then(result=>{
//检测到有保存的记录
if(result.result){
this.setData({
visible3: true,
})
}else{
//没有保存的记录
this.fromBegin(menu)
}
})
},
onReady(res) {
this.videoContext = wx.createVideoContext('myVideo')
},
//记录提醒对话框
handleClick2({ detail }) {
const index = detail.index;
if (index === 0) {
//重新学习
this.fromBegin(this.data.menu)
} else if (index === 1) {
//继续答题
wx.u.checkSaveHistory(this.data.menu).then(result => {
var data = result.data
console.log(data)
var start = 1;
var questionOk = 0;
var questionErr = 0;
for (let object of data.questionList) {
if (object.judge == undefined) {
break;
}else{
if(object.judge == 1){
questionOk++
} else if (object.judge == 0){
questionErr++
}
}
start++
}
//计算百分比
let percentage = questionOk / (start-1) * 100
percentage = percentage.toFixed(2)
//进度条
let percent = start / data.questionList.length
percent = (percent * 100).toFixed(2);
percent = percent < 1 ? 1 : percent
this.setData({
loading: false,
result: data.questionList,
total: data.questionList.length,
index:start,
questionOk: questionOk,
questionErr: questionErr,
percentage: percentage,
percent: percent
})
var time = (parseInt(data.minute) * 60000 + parseInt(data.second) * 1000)
this.Countdown(time)
this.setThisData(start-1)
})
}
this.setData({
visible3: false
});
},
Countdown(time) {
//倒计时
this.Countdown = new $wuxCountDown({
date: +(new Date) + parseInt(time),
render(date) {
const min = this.leadingZeros(date.min, 2) + ':'
const sec = this.leadingZeros(date.sec, 2) + ''
console.log(date)
console.log(date.sec)
//答题时间结束
if (date.min === 0 && date.sec === 0) {
console.log("时间结束")
that.handleClick1();
}
this.setData({
Countdown: min + sec,
min:min,
sec:sec
})
}
})
},
//重头开始答题
fromBegin(menu){
wx.u.getMenuById(menu).then(res1 => {
var time = res1.result.time
var questionNum = res1.result.questionNum
//获取题目
wx.u.getQuestions(menu, questionNum).then(res => {
console.log(res.result);
this.setData({
loading: false,
result: res.result,
total: res.result.length,
})
this.Countdown(parseInt(time) * 60000)
this.setThisData(0)
})
});
},
//设置当前题目
setThisData(i) {
const r = this.data.result
const that = this;
console.log(r.length)
if (r.length == 0) {
wx.redirectTo({
url: '/pages/answerErr/index',
})
return
}
//const current = r[i].choseList[0].item
const answer = [];
//获取正确答案
for (var j = 0; j < r[i].choseList.length; j++) {
if (r[i].choseList[j].isChose) {
answer.push(r[i].choseList[j].item);
}
}
console.log(answer);
this.setData({
questionInfo: r[i],
answer: answer,
type: r[i].type
})
},
//统计答题
statistical() {
if ((this.data.questionErr + this.data.questionOk) == this.data.result.length){
return
}
//记录选择的答案
if (this.data.type == 1) {
//单选
var choose = this.data.current;
this.data.result[this.data.index - 1].choose = [choose];
} else {
//多选
var choose = this.data.currentD;
this.data.result[this.data.index - 1].choose = [choose];
}
let questionErr = this.data.questionErr //错题个数
let questionOk = this.data.questionOk //错题个数
let questionInfo = this.data.questionInfo
let result = this.data.result
let index = this.data.index
if (questionInfo.isOk === 1) {
questionOk = questionOk + 1
result[index - 1].judge = 1
}else{
questionErr = questionErr + 1
result[index - 1].judge = 0
}
//计算百分比
let percentage = questionOk / (index) * 100
percentage = percentage.toFixed(2)
//进度条
let percent = this.data.index / this.data.total
percent = (percent * 100).toFixed(2);
percent = percent < 1 ? 1 : percent
this.setData({
result: result,
questionOk: questionOk,
questionErr: questionErr,
percentage: percentage,
percent: percent
})
},
//单选
handleChange({
detail = {},
target = {}
}) {
let questionInfo = this.data.questionInfo
//判断答案
if (target.dataset.id) {
console.log('ok')
questionInfo.isOk = 1
} else {
questionInfo.isOk = 0
}
this.setData({
questionInfo: questionInfo,
current: detail.value
});
},
//多选
handleChangeD({detail = {},target = {}}) {
let questionInfo = this.data.questionInfo
const index = this.data.currentD.indexOf(detail.value);
index === -1 ? this.data.currentD.push(detail.value) : this.data.currentD.splice(index, 1);
console.log(this.data.currentD)
this.setData({
currentD: this.data.currentD,
});
var answer = this.data.answer;
var currentD = this.data.currentD;
var rightNum = 0;
for (var i = 0; i < currentD.length; i++) {
var indexs = currentD[i].indexOf(" ");
console.log(indexs)
var indexOf = answer.indexOf(currentD[i].substring(indexs + 1));
console.log(indexOf)
if(indexOf >= 0){
rightNum += 1;
}
}
console.log(answer)
console.log(rightNum)
console.log(currentD)
//判断答案
if(rightNum == answer.length){
questionInfo.isOk = 1
}else{
questionInfo.isOk = 0
}
this.setData({
questionIn
没有合适的资源?快使用搜索试试~ 我知道了~
Mamba微信答题小程序项目.rar
共322个文件
js:81个
json:75个
wxss:73个
需积分: 5 0 下载量 81 浏览量
2023-05-27
12:20:45
上传
评论
收藏 293KB RAR 举报
温馨提示
Mamba微信答题小程序项目
资源推荐
资源详情
资源评论
收起资源包目录
Mamba微信答题小程序项目.rar (322个子文件)
index.js 13KB
index.js 13KB
index.js 7KB
index.js 5KB
index.js 5KB
index.js 4KB
index.js 3KB
index.js 3KB
index.js 3KB
index.js 3KB
index.js 2KB
index.js 2KB
index.js 2KB
baseBehavior.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1019B
index.js 999B
index.js 996B
index.js 982B
index.js 981B
index.js 971B
index.js 954B
index.js 935B
index.js 924B
gestures.js 923B
index.js 875B
index.js 844B
index.js 804B
index.js 781B
index.js 776B
index.js 769B
index.js 768B
index.js 715B
index.js 714B
index.js 699B
index.js 648B
index.js 646B
index.js 616B
index.js 614B
index.js 481B
index.js 447B
index.js 437B
colors.js 387B
index.js 377B
index.js 377B
mergeOptionsToData.js 370B
index.js 362B
index.js 347B
index.js 333B
index.js 312B
index.js 300B
index.js 251B
index.js 230B
index.js 145B
index.js 145B
index.js 136B
app.json 1KB
project.config.json 903B
index.json 787B
index.json 568B
index.json 502B
index.json 329B
index.json 209B
index.json 209B
index.json 197B
index.json 189B
index.json 119B
index.json 119B
index.json 117B
index.json 117B
index.json 117B
index.json 115B
index.json 112B
index.json 111B
index.json 108B
共 322 条
- 1
- 2
- 3
- 4
资源评论
YOLO数据集工作室
- 粉丝: 471
- 资源: 1567
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功