|
|
|
@ -2,10 +2,10 @@
|
|
|
|
|
const db = wx.cloud.database();
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
students: [], // 存储所有学生信息
|
|
|
|
|
currentStudent: null, // 当前选中的学生信息
|
|
|
|
|
score: '', // 用户输入的分数
|
|
|
|
|
effects: [ // 特殊效果数组
|
|
|
|
|
students: [],
|
|
|
|
|
currentStudent: null,
|
|
|
|
|
score: '',
|
|
|
|
|
effects: [
|
|
|
|
|
{ name: '+0分', value: 0, type: 'add' },
|
|
|
|
|
{ name: '+1分', value: 1, type: 'add' },
|
|
|
|
|
{ name: '+2分', value: 2, type: 'add' },
|
|
|
|
@ -16,34 +16,44 @@ Page({
|
|
|
|
|
{ name: '-2分', value: -2, type: 'add' },
|
|
|
|
|
{ name: '积分乘2', value: 2, type: 'multiply' },
|
|
|
|
|
{ name: '积分除2', value: 0.5, type: 'divide' }
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
page: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
hasMore: true
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad: function() {
|
|
|
|
|
this.loadStudents();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 加载学生数据
|
|
|
|
|
loadStudents: function() {
|
|
|
|
|
const studentsCollection = db.collection('users');
|
|
|
|
|
studentsCollection.get({
|
|
|
|
|
success: res => {
|
|
|
|
|
if (res.data.length === 0) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '没有学生数据',
|
|
|
|
|
icon: 'none',
|
|
|
|
|
duration: 2000
|
|
|
|
|
loadAllStudents: function() {
|
|
|
|
|
const that = this;
|
|
|
|
|
const loadNextPage = function() {
|
|
|
|
|
const studentsCollection = db.collection('users');
|
|
|
|
|
studentsCollection.skip((that.data.page - 1) * that.data.pageSize).limit(that.data.pageSize).get({
|
|
|
|
|
success: res => {
|
|
|
|
|
if (res.data.length === 0) {
|
|
|
|
|
that.setData({
|
|
|
|
|
hasMore: false
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let newStudents = that.data.students.concat(res.data);
|
|
|
|
|
that.setData({
|
|
|
|
|
students: newStudents,
|
|
|
|
|
page: that.data.page + 1
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
// 如果还有更多数据,继续加载下一页
|
|
|
|
|
if (that.data.hasMore) {
|
|
|
|
|
loadNextPage();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
fail: err => {
|
|
|
|
|
console.error('学生数据加载失败:', err);
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
students: res.data
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
fail: err => {
|
|
|
|
|
console.error('学生数据加载失败:', err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
loadNextPage();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad: function() {
|
|
|
|
|
this.loadAllStudents();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 按积分加权随机点名
|
|
|
|
@ -127,7 +137,7 @@ Page({
|
|
|
|
|
duration: 2000
|
|
|
|
|
});
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.log('更新失败', err); // 失败提示错误信息
|
|
|
|
|
console.log('更新失败', err);
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
addHalfScore: function() {
|
|
|
|
@ -197,7 +207,7 @@ Page({
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 减少1分
|
|
|
|
|
|
|
|
|
|
subtractOneScore: function() {
|
|
|
|
|
if (this.data.currentStudent) {
|
|
|
|
|
this.updateStudentScore(-1);
|
|
|
|
@ -248,13 +258,13 @@ Page({
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 随机选择一个效果
|
|
|
|
|
|
|
|
|
|
const effect = this.data.effects[Math.floor(Math.random() * this.data.effects.length)];
|
|
|
|
|
this.setData({
|
|
|
|
|
effect: effect // 设置抽取的效果以便显示
|
|
|
|
|
effect: effect
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 根据效果类型更新分数
|
|
|
|
|
|
|
|
|
|
let newScore;
|
|
|
|
|
switch (effect.type) {
|
|
|
|
|
case 'add':
|
|
|
|
@ -323,8 +333,8 @@ Page({
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
students: res.data,
|
|
|
|
|
currentStudent: null, // 清空当前选中的学生信息
|
|
|
|
|
effect: null // 清空效果信息
|
|
|
|
|
currentStudent: null,
|
|
|
|
|
effect: null
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
fail: err => {
|
|
|
|
|