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 });
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
基于java开发的题库小程序
共33个文件
png:10个
js:9个
wxss:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 147 浏览量
2024-03-29
21:35:29
上传
评论
收藏 57KB ZIP 举报
温馨提示
基于java开发的题库小程序
资源推荐
资源详情
资源评论
收起资源包目录
基于java开发的题库小程序.zip (33个子文件)
基于java开发的题库小程序
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
资源评论
依然风yrlf
- 粉丝: 1531
- 资源: 3116
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- YOLO-yolo资源
- 适用于 Java 项目的 Squash 客户端库 .zip
- 适用于 Java 的 Chef 食谱.zip
- Simulink仿真快速入门与实践基础教程
- js-leetcode题解之179-largest-number.js
- js-leetcode题解之174-dungeon-game.js
- Matlab工具箱使用与实践基础教程
- js-leetcode题解之173-binary-search-tree-iterator.js
- js-leetcode题解之172-factorial-trailing-zeroes.js
- js-leetcode题解之171-excel-sheet-column-number.js
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功