const app = getApp()
const db = wx.cloud.database()
const dbQuestions = db.collection('tiku_exams')
const util = require("../../utils/util");
const _ = db.command
let titles = [] //题库
Page({
data: {
hour:'00',
minute:'00',
second:'00',
showScore:false,//是否展示成绩
testTime:0,//考试用时
errorOptions:[],
showAnswer:false,
percent: 0,
total: 0,
isSelect: false,
subject: null,
userSelect: '',
userScore: 0, //用户答对了几道题
totalScore: 0, //用户总得分
totalError: 0, //用户答错几道题
current: 1 //从第一道题开始
},
onUnload(){
console.log('执行了')
titles = []
},
getQuestionsList(type1,type2){
wx.setNavigationBarTitle({
title: type2 + '答题',
})
dbQuestions.where({
type: type1,
type2: type2
}).skip(titles.length).get()
.then(res => {
console.log("题库", res)
if(res.data.length!=0){
titles = titles.concat(res.data)
this.getQuestionsList(type1,type2)
}else{
let subject = titles[0]
console.log('subject', subject)
this.setData({
subject,
total: titles.length
})
//生成考试id
this.setData({
testId: util.formatTime(new Date()) + this.data.subject.type + '考试'
})
}
})
},
//一进入页面就会执行的生命周期
onLoad(e) {
//开始计时
this.time60()
console.log('答题页', e)
if (e.type1 && e.type2) { //按类型答题
this.getQuestionsList(e.type1,e.type2)
} else { //随机题库
wx.setNavigationBarTitle({
title: '随机答题',
})
dbQuestions.aggregate()
.sample({
size: app.globalData.randomNum //随机获取几道题,比如这里随机返回5道题
})
.end()
.then(res => {
console.log("随机题库", res)
titles = res.list
let subject = titles[0]
this.setData({
subject,
total: titles.length
})
//生成考试id
this.setData({
testId: util.formatTime(new Date()) + this.data.subject.type + '考试'
})
})
}
// 答题时提示用需要登陆注册才可以参加排名
// 发布之前先判断是否登录和注册
if (!app.globalData.userInfo || !app.globalData.userInfo.name) {
wx.showModal({
title: "需要参加积分排名吗?",
content: '只有授权登陆并注册用户后才可以参与积分排名,取消后本次答题不计入积分排行里',
success: res => {
if (res.confirm) {
wx.switchTab({
url: '/pages/me/me',
})
}
}
})
}
},
//用户选择
selectClick(e) {
console.log(e.detail.value)
this.setData({
userSelect: e.detail.value
})
},
//提交答题,并切换到下一题
submit() {
this.setData({
showAnswer:false
})
//1,获取用户选项并判空
let userSelect = this.data.userSelect
if (!userSelect || userSelect.length < 1) {
wx.showToast({
icon: 'none',
title: '请做选择',
})
return
}
//2,如果用户有选择,就更新进度条
let currentNum = this.data.current
//更新进度条
this.setData({
percent: (currentNum / titles.length * 100).toFixed(1)
})
//3,判断用户是否答对
console.log('用户选项', userSelect)
console.log('正确答案', this.data.subject.answer)
if (userSelect instanceof Array) { //多选的时候,把选项转字符串
console.log('是数组')
userSelect = userSelect.sort().toString()
}
if (this.data.subject.answer.sort().toString() == userSelect) {
console.log('用户答对了第' + currentNum + "道题")
this.setData({
userScore: this.data.userScore + 1
})
} else {
//4,记录用户答错的题,方便用户查漏补缺
let subjectNow = this.data.subject
subjectNow.userSelect = userSelect
this.data.errorOptions.push(subjectNow)
let temp = {}
Object.assign(temp, subjectNow)
delete temp._id
let userInfo = wx.getStorageSync('user') || {}
temp.nickName = userInfo && userInfo.nickName ? userInfo.nickName : '未登陆用户'
console.log('临时错题', temp)
//设置考试id
temp.testId = this.data.testId
// 添加用户错题到数据库
db.collection('tiku_test_errors').add({
data: temp
}).then(res => {
console.log('添加错题到数据库', res)
})
console.log('错题', subjectNow)
}
// 5,在答完最后一道题的时候,对用户进行打分
if (currentNum + 1 > titles.length) {
let totalScore = this.data.userScore
console.log('用户一共答对了' + totalScore + "道题")
console.log('用户错题集', this.data.errorOptions)
this.setData({
totalScore: totalScore,
totalError: this.data.errorOptions.length,
hideButton: true //最后一题时隐藏按钮
})
wx.showToast({
icon: 'none',
title: '已经最后一道啦',
})
// this.addScore(totalScore)
return
}
let subject = titles[currentNum]
this.setData({
userSelect: '',
subject,
current: currentNum + 1,
isSelect: false,
})
},
//去查看错题集
seeError() {
console.log('点击了查看错题集')
//跳页
wx.switchTab({
url: '/pages/errorList/errorList'
})
},
//添加积分
addScore(score) {
// 发布之前先判断是否登录和注册,如果没有就不计分
if (!app.globalData.userInfo || !app.globalData.userInfo.name) {
return
}
db.collection('tiku_users').doc(app.globalData.openid).update({
data: {
score: _.inc(score)
}
}).then(res => {
wx.showToast({
title: '积分生效',
})
})
},
//查看答案
ok(){
//1,获取用户选项并判空
let userSelect = this.data.userSelect
if (!userSelect || userSelect.length < 1) {
wx.showToast({
icon: 'none',
title: '请做选择',
})
return
}
this.setData({
showAnswer:true
})
},
//提交考试
testEnd(){
//1,获取用户选项并判空
let userSelect = this.data.userSelect
if (!userSelect || userSelect.length < 1) {
wx.showToast({
icon: 'none',
title: '请做选择',
})
return
}
wx.showLoading({
title: '提交中',
mask:true
})
this.setData({
showScore: true, //最后一题时隐藏按钮
testTimeMin: this.data.testTimeMin,
testTimeSec: this.data.testTimeSec,
})
//添加积分
this.addScore(this.data.totalScore)
//停止倒计时
clearInterval(this.data.timeInterval)
wx.cloud.database().collection('tiku_test_results').add({
data:{
faceImg:app.globalData.userInfo.avatarUrl,
nickName:app.globalData.userInfo.nickName,
testId:this.data.testId,
time:this.data.testTimeMin + '分' + this.data.testTimeSec + '秒',
totalError:this.data.totalError,//答错xx道
total:this.data.total//答错xx道
}
}).then(res=>{
wx.hideLoading({
success: (res) => {
wx.showToast({
title: '提交成功',
})
wx.redirectTo({
url: '/pages/test/testResult/testResult?totalError=' + this.data.totalError + '&testTimeMin=' + this.data.testTimeMin + '&testTimeSec=' + this.data.testTimeSec + '&totalScore=' + this.data.totalScore,
})
},
})
})
},
//倒计时1小时
time60(){
var that
没有合适的资源?快使用搜索试试~ 我知道了~
微信在线答题小程序,基于云开发搭建
共275个文件
json:29个
js:25个
wxss:23个
需积分: 47 8 下载量 44 浏览量
2022-09-12
17:13:40
上传
评论 6
收藏 1.51MB RAR 举报
温馨提示
微信在线答题小程序,基于云开发搭建 const db = wx.cloud.database() const app = getApp() Page({ data: { }, //获取所有题目类型 onLoad() { this.getCurrentDate() this.getBannerList() const $ = db.command.aggregate db.collection('tiku_questions').aggregate() .group({ _id: '$type', num: $.sum(1) }).end().then(res => { console.log('题目类型', res) this.setData({ list: res.list }) }) }, getCurrentDate(){ var now = new Dat
资源详情
资源评论
资源推荐
收起资源包目录
微信在线答题小程序,基于云开发搭建 (275个子文件)
02add20b581be471b8d17f887b8e8337070546 194B
02b91b45482381139694f9d84032d1a199573a 2KB
0bbe5503a6dc03dceb084984b64edc752c6429 10KB
0c0f7ab1bdc3d26aba39fe19bb1d3173c9562f 570B
0c533b7b5aaec1711fa14ad762761600cf1292 270B
0c7cdf4d4cb792e6fa602d06b5e5a2fbb48878 8KB
0c94109b8d3a0d598deae57e494b9022a580d5 52B
0cf0dad5c3e62babdbc0fbc7a10d6563e721cf 128B
122a19c2972cb6aa171bcfb06dbb1406c17244 2KB
166b31f4437d6b0f997817d2a351ea72d0261d 440KB
17c6dd22444e77740919d15b878194935460ad 139B
18f0d94e2660a74d87f02cca0927de647ca7a9 728B
1966014999cb6b45adf5cb902864085532c949 1004B
1bc6530fe26acc5fc01dae7feadcbc28e515c9 139B
1c004a8f0d8c58532b2fe7cb0de9593808bfcf 134B
1d4f38ff68a8870d1b64ad65549d3ffca34c8b 139B
217f3f5f1b8d7707172cfffcca480a80db5608 144B
21f8c492998898e02dced8c5745dfde11f04b5 535B
230dd04090739926eb37f8bd53ee893d1a4540 88B
23d11bf5012b6ff26062d64cc748a50d792bd5 186B
23da1bb27f4281496d831dfc109ff57d598f95 89B
2466b9799dfb2795753e087f58d5a70a44a3bd 147B
247038ba7fe68ce87a3ee284373e97aef5b66e 850B
2540ec399c15ff070f08c65a7de372113755dd 325B
26dfeeb6e641a33dae4961196235bdb965b21b 17B
27aa59889a71a6c12e99853dc6549a740b74e7 114B
2b79710db5db015c8c24ebe524ee6351b4c1ca 167B
2c7668a9587b39e6b5e5cd4783ef8c66a06fd9 63B
322f31e36f3453dbbe5c0339d7aca377c18539 63B
332a5c107a073978db03bcfdc21dd2c9ea3e51 323B
3382ade83b5b5ab792f0415de7733f123190bb 137B
344d0c6e74ae6d0b4512ebb4cf88d2ad630089 257B
35691c18d9fc6c548b76cc5e6634c8c2b12a5f 81B
3589bccc16eb6283c3257edf6cda1bfa53c05b 194B
3589eab2fbc8a56f7c3d0bb50b69a23d436ad3 199B
35af0699ccec004cbe685ef938cd2d63ea7037 43B
399e253572fb6474ac11439a484774e6f7bbbf 218B
3b6b60d610e0f6bcfcaea8522d4a494e0a139a 201B
3e6eb72e71ec0b18b684b0577dca7c99f2efb4 1KB
3fd8f360a1c31af657285f7d7210d770f3d79a 3KB
3ffe3dd8392fa6dfa53e3f7fe68d6f7787cbba 134B
40c45562155a04a2a47a8608d8536d8c47433c 458B
431a7bcb9f0b8e5d3f80706e062b1282ce88e1 764B
439cad7dddd455acc48bab908f906efb3e6d03 137B
44cb4e89cd3b5bfc921ab90196f05ae8d1cedb 141B
46c74d2c0b1b00c489a5eda6f361e0e61fb543 406B
471a118f3a01cb7e3cac6f9cbc5f6a0b0d0a42 161B
491fe7b366e42c21d7ef188ce601ee61dd3c40 658B
4a89f02a504f0536510be276b53c61ef063347 56B
4bb22198402103acb83290671f95c1297d2ced 466B
4bc2ce26ab9b55a21cbb069dcf084a8418dffd 261B
4d515e45070fc6c4dce4d05ee1239c642e8de0 136B
4db6ffcc80a89ee095f9b9749a8682cfe0cff8 560B
4df92006b706595ee009753d58327e3a3b3fe9 82B
4e2d6654cf9fa0992aed902280bd156b2a5a31 2KB
4e965f1f48383775301bf44104b2440c934ce9 200B
4ece44aa220af10f3b17243e8549a9c25d70a7 203B
4f6ede34b7755e1afd3f1c562f347db584fec4 12KB
52ea326c41510334e6754ceaeba3bdc8bd9812 9KB
558ba63b723f596d99521ff9b5db8ed8896f56 276B
5c0449827359bb46053247b6d8e70b359a93aa 3KB
5cf7613163b00278b1035f4ae2d4593ffc670f 935B
5d33df0ed214ebf9fd165f53675c1acffc1f41 1KB
5d36f495b24840c6a7813a99a270cecfb74327 247B
5e4798a2c9ed05bf6585f66cfa28edceeb86b8 120B
616dd5346895721e6c3696823938bfc0296567 52B
61b422514b11f1569858828f9312b586763ec0 505B
62f583a9c0d315e0532fb77c2f6d9482b13d1d 656B
639ca29eab81e0b1112a261d513689669ae354 2KB
6500a2a77f6f4e8a72c15e678a6ced3e4d1f1b 63B
68867b17d45c037dbf805408335bbc15d6e24d 6KB
6a9eac844332bf48999cb664a5a6d9233f52c7 269B
6d025f1b899389bda91ffcbca3ac05f5591336 1KB
6e72750dd433fd5acbfc1403da52ee800bc34e 1KB
6f96edaf179b66f5b8fe188f0efa4a29c4f7d6 646B
7223aa5d36b00cc2e2065564f7b4319dcef3ab 552B
7812c281618453a8f1884027428b7b8bbd56ee 2KB
79993c3ce0456a59a57ad7a5bc12ca03428977 305B
7b1ce6a5ef2d9bb0e1d827ab24922e907fdaaf 17KB
7d21eba396cad0c7b88516bbb75fe06254bb30 82B
80487f5466e5982e96063c3501f815cb0253f0 194B
80de8c1786e61eb8e60af186ced85d4ef7fa11 635B
827e5c577315c04f44226e393e78a37b8c3df7 110KB
82966b0262bacec957f14a7ea498d6a2a436e2 141B
85a2a33309850e1299681d44c1d9a0f5adb66b 442B
87c94a301c6fd72ec0ccf677bafacc129945e3 257B
887f21978e6a4cfa1c81c8023ed815fd3d10e2 7KB
889e0fc76b18cb96093a8a5ffe09d610ff9435 232B
89d9de7027323f6b52bb2d0fcfebeec6ba68e2 386B
8a049b30bdeb46f8971591510dadac959265c6 1KB
92de91ed1a7eb7bcbebc5244c0fb3d96f54fa7 327B
932cd8d848ebafbb84bace7ec1efb1f91039b8 56B
9344190af750442dc79e6b22e6e760384ae323 391B
97a93bd10e4cedc3f54bb6134f401cb049933a 651B
97dd54b6912125f49d5f71ca7b98cdd8c38e3e 3KB
9b49d0fb99c32d7679217f5a896d513881c8f1 706B
a0b975048beeece9ee73ee209fd95bb91dbf99 923B
a12d46344ea7cec8f1abce8f24e864e423e4be 394B
a316451ba03b031db1519d856e32def01c7b2a 214B
a66fcd35e4384b81f59a13cbd9e1ba44a7abea 1KB
共 275 条
- 1
- 2
- 3
wujiequ
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- LabVIEW实现LoRa通信【LabVIEW物联网实战】
- CS-TY4-4WCN-转-公版-XP1-8B4WF-wifi8188
- 计算机网络期末复习资料(课后题答案+往年考试题+复习提纲+知识点总结)
- 从零学习自动驾驶Lattice规划算法(下) 轨迹采样 轨迹评估 碰撞检测 包含matlab代码实现和cpp代码实现,方便对照学习 cpp代码用vs2019编译 依赖qt5.15做可视化 更新:
- 风光储、风光储并网直流微电网simulink仿真模型 系统由光伏发电系统、风力发电系统、混合储能系统(可单独储能系统)、逆变器VSR+大电网构成 光伏系统采用扰动观察法实现mppt控
- (180014016)pycairo-1.18.2-cp35-cp35m-win32.whl.rar
- (180014046)pycairo-1.21.0-cp311-cp311-win32.whl.rar
- DS-7808-HS-HF / DS-7808-HW-E1
- (180014004)pycairo-1.20.0-cp36-cp36m-win32.whl.rar
- (178330212)基于Springboot+VUE的校园图书管理系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0