const app = getApp(); Page({ data: { students: [], // 学生名单 selectedStudent: {}, // 选中的学生 rankings: [] , currentIndex: 0, isAllspot: 0, showSolidMode: false }, onLoad: function() { // 假设从全局或云端获取学生数据 showSolidMode = false; const studentsWithDetails = app.globalData.array.map(student => { return { ...student, displayText: `${student.student_ID} - ${student.name}` // 格式化学号和姓名 }; }); this.setData({ students: studentsWithDetails // 设置格式化后的学生数据 }); 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 状态 }); }, triggerSelection: function() { if (this.data.isAllSpot) { this.fullSelection(); } else { // 否则执行 fullSelection this.randomSelection(); } }, // 课前点名 - 抽点 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', }) }, beginfull: function(e) { wx.navigateTo({ url: '/pages/card/card', }) }, beginsolid: function() { this.setData({ showSolidMode: true, // 设置为 true 来隐藏当前内容并显示新的内容 }); } // 课中点名 - 指定点名 // 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; this.setData({ selectedStudent: selectedStudent // 更新选中的学生 }); // 进入下一个页面,携带选中学生的信息 wx.navigateTo({ url:'/pages/cardM/cardM', }); }, exportFile: 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 // 更新排行榜数据 }); // 进入排行榜页面,并携带排行榜数据 } });