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.

199 lines
5.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const app = getApp();
Page({
data: {
students: [], // 学生名单
selectedStudent: {}, // 选中的学生
rankings: [] ,
currentIndex: 0,
isAllspot: 0,
showSolidMode: false,
indexstudent:0
},
onLoad: function() {
// 假设从全局或云端获取学生数据
const studentsWithDetails = app.globalData.array.map(student => {
return {
...student,
displayText: `${student.student_ID} - ${student.name}` // 格式化学号和姓名
};
});
this.setData({
students: studentsWithDetails, // 设置格式化后的学生数据
showSolidMode: false
});
app.globalData.currentId = 0;
app.globalData.front = 0;
const randomNumber = Math.floor(Math.random()*10) + 1;
app.globalData.rcount = randomNumber;
},
titleClick: function (e) {
const index = e.currentTarget.dataset.idx;
this.setData({
//拿到当前索引并动态改变
currentIndex: e.currentTarget.dataset.idx
})
if (index == 2) {
this.showRankings();
}
},
switch1Change: function(e) {
const isAllSpot = e.detail.value;
this.setData({
isAllSpot: isAllSpot // 更新 switch 状态
});
},
beginfront: function() {
if (this.data.isAllSpot) {
this.fullSelection();
// console.log("执行全点");
} else {
// 否则执行 fullSelection
this.randomSelection();
// console.log("执行抽点");
}
wx.navigateTo({
url: '/pages/card/card',
})
},
// 课前点名 - 抽点
randomSelection: function() {
app.globalData.currentId = 0;
app.globalData.front = 0;
const randomNumber = Math.floor(Math.random()*10) + 1;
app.globalData.rcount = randomNumber;
},
// 课前点名 - 全点
fullSelection: function() {
app.globalData.front = 1;
app.globalData.rcount = 1;
app.globalData.currentId = 0;
},
// 课中点名 - 随机点名
beginrandom: function(e) {
app.globalData.part = 0;
wx.navigateTo({
url: '/pages/cardM/cardM',
})
},
beginsolid: function() {
this.setData({
showSolidMode: true, // 设置为 true 来隐藏当前内容并显示新的内容
});
},
retrun1: function() {
this.setData({
showSolidMode:false,
})
},
beginsolidgo: function() {
// console.log(this.data.indexstudent);
app.globalData.part = 1;
app.globalData.currentId = this.data.indexstudent;
wx.navigateTo({
url:'/pages/cardM/cardM',
});
},
// 课中点名 - 指定点名
// specifiedRollCall: function() {
// app.globalData.part = 1;
// this.setData({
// showStudentPicker: true
// });
// },
// 选择学生
selectStudent: function(e) {
const index = e.detail.value; // 获取选择的学生索引
const selectedStudent = this.data.students[index]; // 获取选择的学生对象
app.globalData.currentId = index;
// console.log(index);
this.setData({
selectedStudent: selectedStudent // 更新选中的学生
});
this.setData({
indexstudent: index
});
// console.log(this.data.indexstudent);
// 进入下一个页面,携带选中学生的信息
// wx.navigateTo({
// url:'/pages/cardM/cardM',
// });
},
handleTap: function () {
var app = getApp();
// console.log(app.globalData.fileID);
wx.showLoading({
title: '加载中',
})
wx.cloud.callFunction({
name : "generate_excel",
data : {
filename : app.globalData.filename,
fileID : app.globalData.fileID,
course : app.globalData.course,
teacher : app.globalData.teacher,
date : app.globalData.date,
weekday : app.globalData.weekday,
start : app.globalData.start,
end : app.globalData.end
},
success(res) {
console.log(res);
wx.cloud.downloadFile({
fileID: res.result.fileID,
success(res) {
wx.hideLoading(),
wx.openDocument({
filePath: res.tempFilePath,
showMenu: true,
success: function (res) {
console.log(res);
}
})
},
fail(res) {
console.log(res);
}
})
}
})
},
showRankings: function() {
// 处理学生没有积分的情况将没有积分的学生默认积分设为0
const studentsWithScores = this.data.students.map(student => ({
...student,
score: student.score || 0 // 如果没有 score设为 0
}));
// 按积分降序排序
const sortedStudents = studentsWithScores.sort((a, b) => b.score - a.score);
// 创建排行榜数据,包括排名、学号、姓名、积分
const rankings = sortedStudents.map((student, index) => ({
rank: index + 1,
student_ID: student.student_ID,
name: student.name,
score: student.score
}));
// 更新排行榜数据
this.setData({
rankings: rankings // 更新排行榜数据
});
// 进入排行榜页面,并携带排行榜数据
}
});