var request = require('../../utils/request').request;
var attachAns = require('../../utils/util').attachAns;
var WrongRecord = require('../../utils/wrong-record');
var pending = false, submitted = false;
var index = 0, doneMax = 0, answer = [], chapter = {};
var app = getApp();
Page({
data: {
problems: [],
problem: {
problem: "",
images: [],
choices: [],
answer: [],
analysis: ''
},
done: 0,
total: 0,
wrong: 0,
// 答案是否正确
right: false,
// 是否提交题目
submitted: false
},
onLoad: function() {
// var category = app.getCategory();
chapter = app.getChapter();
// console.log(chapter);
wx.setNavigationBarTitle({
title: chapter.name
})
this.setData({ total: chapter.count });
// 获取完成题数
var done = wx.getStorageSync('cnt_done_' + chapter._id);
// console.log(done, chapter.count);
if (done) {
done = parseInt(done);
doneMax = done;
// 全部完成时显示最后一题
if (done >= chapter.count) done = chapter.count-1;
} else {
doneMax = done = 0;
}
this.setData({ done: parseInt(done) });
// 获取错题数
var wrong = wx.getStorageSync('cnt_wrong_' + chapter._id);
if (wrong) {
wrong = parseInt(wrong);
} else {
wrong = 0;
}
this.setData({ wrong: parseInt(wrong) });
// 从完成位置加载题目
var that = this;
request({
url: `api/qbank/problem/${chapter._id}/${done}`,
success: function(res) {
// 选项数据格式处理
res = res.map(item => {
var choices = item.choices;
item.choices = [];
for (var key in choices) {
item.choices.push({ key: key, content: choices[key] });
}
return item;
});
// 存在后续题目
if (res.length > 0) {
that.setData({
problems: res,
problem: attachAns.call(that, res[0])
});
}
}
});
},
onUnload: function() {
// console.log(submitted, doneMax);
// 存入完成题数及错题数
if (submitted) doneMax++;
if (doneMax > this.data.total) doneMax = this.data.total;
wx.setStorageSync('cnt_done_' + chapter._id, doneMax.toString());
wx.setStorageSync('cnt_wrong_' + chapter._id, this.data.wrong.toString());
},
onShow: function() {
// 初始化全局变量
index = 0;
pending = false;
submitted = false;
chapter = app.getChapter();
},
checkboxChange: function(e) {
answer = e.detail.value;
if (this.data.problem.answer.length === 1) this.submit();
},
submit: function() {
if (!this.data.problem._id) return;
if (pending || submitted) return;
submitted = true;
// 答案对比
var answer1 = answer;
var answer2 = this.data.problem.answer;
answer1.sort();
answer2.sort();
if (answer1.toString() === answer2.toString()) {
this.setData({ right: true });
} else {
this.setData({
right: false,
wrong: this.data.wrong + 1
});
// 加入错题本
WrongRecord.add(this.data.problem);
}
wx.setStorageSync('prob_ans_' + this.data.problem._id, JSON.stringify(answer1));
this.setData({ submitted: submitted });
},
// 上一题
prev: function() {
if (pending) return;
var data = this.data;
if (data.done === 0) {
wx.showModal({ title: '提示', content: '已到达第一题' });
return;
}
submitted = false;
if (index > 0) {
this.setData({
problem: attachAns.call(this, data.problems[--index]),
done: data.done - 1
});
} else {
// 获取题目
pending = true;
var that = this;
request({
url: `api/qbank/problem/prev/${chapter._id}/${data.done}`,
success: function(res) {
res = res.map(item => {
var choices = item.choices;
item.choices = [];
for (var key in choices) {
item.choices.push({ key: key, content: choices[key] });
}
return item;
});
if (res.length > 0) {
index = index + res.length - 1,
that.setData({
problems: [...res, ...data.problems],
problem: attachAns.call(that, res[res.length - 1]),
done: data.done - 1
});
} else {
// TODO
}
pending = false;
}
});
}
},
// 下一题
next: function() {
if (pending) return;
var data = this.data;
// 获取题目
if (data.done + 1 >= data.total) {
if (data.done + 1 === data.total) {
doneMax: doneMax > data.done + 1 ? doneMax : data.done + 1;
this.setData({ done: data.done + 1 });
}
wx.showModal({
title: '提示',
content: '已到达最后一题',
complete: function() {
wx.navigateBack({ delta: 1 });
}
});
return;
}
submitted = false;
if (data.problems.length > ++index) {
this.setData({ problem: attachAns.call(this, data.problems[index]) });
} else {
pending = true;
var that = this;
request({
url: `api/qbank/problem/${chapter._id}/${data.done + 1}`,
success: function(res) {
res = res.map(item => {
var choices = item.choices;
item.choices = [];
for (var key in choices) {
item.choices.push({ key: key, content: choices[key] });
}
return item;
});
if (res.length > 0) {
that.setData({
problems: [...data.problems, ...res],
problem: attachAns.call(that, res[0])
});
} else {
// TODO
}
pending = false;
}
});
}
doneMax = doneMax > data.done + 1 ? doneMax : data.done + 1;
this.setData({ done: data.done + 1 });
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
小程序源码 考证通题库.zip
共33个文件
png:10个
js:9个
wxss:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 60 浏览量
2023-03-01
09:43:04
上传
评论
收藏 52KB ZIP 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
小程序源码 考证通题库.zip (33个子文件)
certificate-minapp-master
pages
problems
problems.wxss 1KB
problems.js 6KB
problems.json 2B
problems.wxml 2KB
index
index.wxml 887B
index.js 2KB
index.json 2B
index.wxss 1KB
wrong
wrong.json 2B
wrong.wxml 2KB
wrong.wxss 1KB
wrong.js 2KB
categorys
categorys.wxss 446B
categorys.js 1KB
categorys.json 2B
categorys.wxml 521B
config.js 120B
app.json 353B
app.js 1KB
utils
request.js 816B
wrong-record.js 2KB
util.js 520B
app.wxss 384B
images
check.png 3KB
choice-D.png 4KB
choice-A.png 4KB
problem.png 5KB
wrong.png 4KB
choice-B.png 4KB
next.png 4KB
back.png 2KB
right.png 3KB
choice-C.png 4KB
共 33 条
- 1
资源评论
金枝玉叶9
- 粉丝: 195
- 资源: 7637
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功