diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/public.zip b/public.zip deleted file mode 100644 index a61dcf8..0000000 Binary files a/public.zip and /dev/null differ diff --git a/public/aaa.html b/public/aaa.html deleted file mode 100644 index 8d27c30..0000000 --- a/public/aaa.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - 模态框示例 - - - - -
- - - - - -
- - - - diff --git a/public/home .html b/public/home .html new file mode 100644 index 0000000..a0ed2bc --- /dev/null +++ b/public/home .html @@ -0,0 +1,266 @@ + + + + + + 课堂点名系统 + + + + + + +
+

课堂点名系统

+
+
+
+ + + + + + + +
+ + + + + + + diff --git a/public/home.html b/public/home.html deleted file mode 100644 index cd36878..0000000 --- a/public/home.html +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - 课堂点名系统 - - - - -
-

课堂点名系统

- -
- - - - - - - - -
- - - - - diff --git a/public/index.html b/public/index .html similarity index 63% rename from public/index.html rename to public/index .html index 02f3ce9..8a10ab2 100644 --- a/public/index.html +++ b/public/index .html @@ -7,6 +7,16 @@ +
-
-
{{ top3[0] }}
学号
积分
-
{{ top3[1] }}
学号
积分
-
{{ top3[2] }}
学号
积分
-
-
文本内容
+
被抽中的同学
- + +
- + +
+
- - - - - - + + + + + +
- - - - - - + + + + + +
+ +
@@ -270,8 +291,10 @@ }, methods: { uploadFile() { - // 调用外部的 uploadFile 函数 - uploadFile(); + + + uploadFile(); + }, getRandomStudent() { // 调用外部的 getRandomStudent 函数 @@ -284,14 +307,7 @@ this.uploadFile(); } }, - addpoints() - { - - }, - divpoints() - { - - }, + rtoggleButtons() { smallButtons = document.querySelector('.small-buttons'); @@ -301,9 +317,117 @@ { smallButtons = document.querySelector('.lsmall-buttons'); smallButtons.classList.toggle('show'); + }, + + changepoints(chan) + { + console.log(chan); + changepoints(chan); } } - }) + }); + + diff --git a/public/script.js b/public/script.js index 5c79f3c..cba126c 100644 --- a/public/script.js +++ b/public/script.js @@ -1,6 +1,19 @@ +let globalStudent = null; +let globalnumber =0; async function uploadFile() { const fileInput = document.getElementById('fileInput'); // 获取文件输入元素 + const url = window.location.href; + + console.log(fileInput); + // 创建一个 URL 对象 + const urlObj = new URL(url); + + // 使用 URLSearchParams 获取查询参数 + const params = new URLSearchParams(urlObj.search); + // 获取 'number' 参数的值 + globalnumber = params.get('number'); + // 检查是否选中了文件 if (fileInput.files.length === 0) { alert('请先选择一个文件!'); @@ -26,10 +39,8 @@ async function uploadFile() { const formData = new FormData(); formData.append('file', file); - document.getElementById('result').innerText = '上传中...'; - try { - const response = await fetch('http://10.133.39.58:8000/upload', { + const response = await fetch(`http://10.133.39.58:8000/${globalnumber}/upload`, { method: 'POST', body: formData }); @@ -40,34 +51,101 @@ async function uploadFile() { const data = await response.json(); console.log(data); - document.getElementById('result').innerText = '上传成功!'; - } catch (error) { + + } + catch (error) { console.error('错误:', error); alert('上传失败: ' + error.message); } } + + + async function getRandomStudent() { - const response = await fetch('http://10.133.39.58:8000/random-call'); + + console.log('haha'); + const response = await fetch(`http://10.133.39.58:8000/${globalnumber}/random-call`, + { + method: 'POST', + }); const student = await response.json(); - document.getElementById('result').innerText = `Selected: ${student.name} (ID: ${student.id}) (points: ${student.points})`; + globalStudent=student; + console.log(student); + document.getElementById('picked').innerText = `Selected: ${student.name} (ID: ${student.id}) (points: ${student.points})`; } -async function createroom() -{ - const response = await fetch('http://10.133.39.58:8000/random-call'); - const student = await response.json(); - document.getElementById('result').innerText = `Selected: ${student.name} (ID: ${student.id}) (points: ${student.points})`; + + +async function createroom() { + const roomNumber = document.getElementById('roomNumber').value; + if (roomNumber.trim() === '') { + alert('房间号码不能为空!'); + this.isModalVisible = false; + return; + } + + globalnumber = roomNumber; + console.log(roomNumber); + try { + const response = await fetch(`http://10.133.39.58:8000/create-class/${globalnumber}`, { + method: 'POST', + }); + + if (!response.ok) { + throw new Error('文件上传失败。'); + } + + const data = await response.json(); // 解析响应数据(假设返回的是 JSON 格式) + console.log('房间创建成功:', data); // 输出成功消息或处理数据 + alert(data.message); + + } catch (error) { + console.error('发生错误:', error.message); // 输出错误信息 + alert(`连接后端服务器失败: ${error.message}`); // 弹窗显示错误信息 + } + + setTimeout(() => { + window.location.href = `index.html?number=${roomNumber}`; + }, 300); // 等待1秒 } -async function backpoints() + + + + + +async function changepoints(chan) { - const response = await fetch('http://10.133.39.58:8000/random-call'); - const student = await response.json(); - document.getElementById('result').innerText = `Selected: ${student.name} (ID: ${student.id}) (points: ${student.points})`; + const idi = globalStudent.id; + const namei = globalStudent.name; + const pointsi = chan; + globalStudent.points+=chan; + + const response = await fetch(`http://10.133.39.58:8000/${globalnumber}/change-points`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + id: String(idi), + name: String(namei), + points: parseFloat(pointsi) + }), + }); + response.json().then(result => { + console.log(result); // 输出 Promise 的结果 + }).catch(error => { + console.error("发生错误:", error); + }); + + document.getElementById('picked').innerText = `Selected: ${globalStudent.name} (ID: ${globalStudent.id}) (points: ${globalStudent.points})`; } + + diff --git a/server.js b/server.js deleted file mode 100644 index 595c898..0000000 --- a/server.js +++ /dev/null @@ -1,73 +0,0 @@ -const express = require('express'); -const multer = require('multer'); -const XLSX = require('xlsx'); -const path = require('path'); - -const app = express(); -const upload = multer({ dest: 'uploads/' }); - -let students = []; -let scores = {}; - -// Middleware to serve static files -app.use(express.static('public')); - -// Endpoint to upload Excel file -app.post('/upload', upload.single('file'), (req, res) => { - const workbook = XLSX.readFile(req.file.path); - const sheetName = workbook.SheetNames[0]; - const sheet = workbook.Sheets[sheetName]; - students = XLSX.utils.sheet_to_json(sheet); - - // Initialize scores - students.forEach(student => { - scores[student.id] = { name: student.name, points: 0 }; - }); - - res.json(students); -}); - -// Endpoint to randomly select a student -app.get('/random', (req, res) => { - if (students.length === 0) return res.status(400).send('No students available.'); - - // Calculate weights based on scores - const weights = students.map(student => { - return Math.max(1, 10 - scores[student.id].points); // Higher score -> lower weight - }); - - const totalWeight = weights.reduce((sum, weight) => sum + weight, 0); - const randomNum = Math.random() * totalWeight; - let cumulativeWeight = 0; - - for (let i = 0; i < students.length; i++) { - cumulativeWeight += weights[i]; - if (randomNum < cumulativeWeight) { - return res.json(students[i]); - } - } -}); - -// Endpoint to update scores -app.post('/update-score', (req, res) => { - const { id, correctRepeat, correctAnswer } = req.body; - - if (!scores[id]) return res.status(400).send('Invalid student ID.'); - - if (correctRepeat) { - scores[id].points += 0.5; - } else { - scores[id].points -= 1; - } - - if (correctAnswer) { - scores[id].points += 1; // Adjust according to your scoring logic - } - - res.json(scores[id]); -}); - -// Start the server -app.listen(3000, () => { - console.log('Server is running on http://localhost:3000'); -});