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.

62 lines
1.4 KiB

// pages/mypoint/mypoint.js
Page({
data: {
studentId: '',
name: '',
students: [],
scoreRanking: [],
hasMore: true,
page: 1,
limit: 20
},
onLoad: function(options) {
this.setData({
studentId: decodeURIComponent(options.studentId || ''),
name: decodeURIComponent(options.name || '')
});
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.navigateBack({
delta: 1
});
}
});