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