"use strict"; const common_vendor = require("../../../common/vendor.js"); const _sfc_main = { __name: "attendance", setup(__props) { const rcallData = common_vendor.ref([]); const selectedStudents = common_vendor.ref([]); const getcall = async () => { try { let res = await common_vendor.index.request({ url: "http://10.133.60.255:3000/api/students", method: "GET" // 明确指定请求方法 }); if (res && res.data) { rcallData.value = res.data.map((student) => ({ name: student.name, signed: false, // 初始化状态 points: student.points || 0 // 初始化积分,若没有则默认为0 })); } } catch (error) { console.error("获取学生数据失败:", error); } }; const randomCall = async () => { if (rcallData.value.length === 0) { console.warn("没有学生数据可供点名"); return; } const studentCount = Math.floor(Math.random() * (30 - 20 + 1)) + 20; const shuffledStudents = rcallData.value.sort(() => 0.5 - Math.random()); const selected = shuffledStudents.slice(0, Math.min(studentCount, rcallData.value.length)); selected.forEach((student) => { student.signed = true; student.points += 3; }); selectedStudents.value = selected; await Promise.all(selected.map((student) => sendAttendance(student))); }; const sendAttendance = async (student) => { try { const response = await common_vendor.index.request({ url: "http://10.133.60.255:3000/api/attendance", method: "POST", data: { name: student.name, signed: student.signed, points: student.points } }); if (response && response.statusCode === 200) { console.log(`签到成功: ${student.name}`); } else { console.error(`签到失败: ${student.name}`); } } catch (error) { console.error("发送签到记录失败:", error); } }; common_vendor.onMounted(() => { getcall(); }); return (_ctx, _cache) => { return { a: common_vendor.o(randomCall), b: common_vendor.f(selectedStudents.value, (student, index, i0) => { return { a: common_vendor.t(student.name), b: common_vendor.t(student.signed ? "✔" : ""), c: common_vendor.t(student.points), d: index }; }) }; }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-5a08be13"]]); wx.createPage(MiniProgramPage);