You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
56 lines
1.2 KiB
// pages/test4/test4.js
|
|
Page({
|
|
data: {
|
|
students: [],
|
|
scoreRanking: [],
|
|
hasMore: true,
|
|
page: 1,
|
|
limit: 20
|
|
},
|
|
onLoad: function() {
|
|
this.fetchStudents();
|
|
},
|
|
fetchStudents: function() {
|
|
const db = wx.cloud.database();
|
|
db.collection('users')
|
|
.orderBy('score', 'desc')
|
|
.skip((this.data.page - 1) * this.data.limit)
|
|
.limit(this.data.limit)
|
|
.get()
|
|
.then(res => {
|
|
if (res.data.length < this.data.limit) {
|
|
this.setData({ hasMore: false });
|
|
}
|
|
const newStudents = this.data.students.concat(res.data);
|
|
this.setData({
|
|
students: newStudents,
|
|
scoreRanking: newStudents
|
|
});
|
|
})
|
|
.catch(err => {
|
|
console.error('数据库读取失败:', err);
|
|
});
|
|
},
|
|
loadMore: function() {
|
|
if (this.data.hasMore) {
|
|
this.setData({ page: this.data.page + 1 }, () => {
|
|
this.fetchStudents();
|
|
});
|
|
}
|
|
},
|
|
refreshData: function() {
|
|
this.setData({
|
|
students: [],
|
|
scoreRanking: [],
|
|
page: 1,
|
|
hasMore: true
|
|
}, () => {
|
|
this.fetchStudents();
|
|
});
|
|
},
|
|
goBack: function() {
|
|
wx.navigateTo({
|
|
url: '/pages/teacherHomePage/teacherHomePage'
|
|
});
|
|
}
|
|
}); |