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.

204 lines
5.9 KiB

4 months ago
let globalStudent = null;
let globalnumber =0;
4 months ago
let houduan = "10.133.48.140:8000";
const generatedStrings = [];
async function uploadFile() {
const fileInput = document.getElementById('fileInput'); // 获取文件输入元素
4 months ago
const url = window.location.href;
console.log(fileInput);
// 创建一个 URL 对象
const urlObj = new URL(url);
// 使用 URLSearchParams 获取查询参数
const params = new URLSearchParams(urlObj.search);
4 months ago
// 获取 'number' 参数的值
globalnumber = params.get('number');
// 检查是否选中了文件
if (fileInput.files.length === 0) {
alert('请先选择一个文件!');
return;
}
const file = fileInput.files[0]; // 获取第一个文件
// 检查文件类型
const allowedTypes = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel']; // 允许的文件类型
if (!allowedTypes.includes(file.type)) {
alert('请上传有效的 Excel 文件!');
return;
}
// 检查文件大小(例如:限制为 5MB
const maxSize = 5 * 1024 * 1024; // 5MB
if (file.size > maxSize) {
alert('文件大小不能超过 5MB');
return;
}
const formData = new FormData();
formData.append('file', file);
try {
4 months ago
const response = await fetch(`http://10.133.48.140:8000/${globalnumber}/upload`, {
method: 'POST',
body: formData
});
if (!response.ok) {
throw new Error('文件上传失败。');
}
const data = await response.json();
4 months ago
alert(data.message);
4 months ago
}
catch (error) {
console.error('错误:', error);
alert('上传失败: ' + error.message);
}
}
async function getRandomStudent() {
4 months ago
const urlObj = new URL(url);
4 months ago
4 months ago
// 使用 URLSearchParams 获取查询参数
const params = new URLSearchParams(urlObj.search);
// 获取 'number' 参数的值
globalnumber = params.get('number');
4 months ago
console.log('haha');
4 months ago
const response = await fetch(`http://10.133.48.140:8000/${globalnumber}/random-call`,
4 months ago
{
method: 'POST',
});
const student = await response.json();
4 months ago
globalStudent=student;
console.log(student);
4 months ago
if(!generatedStrings.includes(student.id))
{
generatedStrings.push(student.id);
changepoints(1);
}
document.getElementById('picked').innerText = `${student.name} \n 学号:${student.id} \n积分:${student.points}`;
}
4 months ago
async function createroom() {
const roomNumber = document.getElementById('roomNumber').value;
if (roomNumber.trim() === '') {
alert('房间号码不能为空!');
this.isModalVisible = false;
return;
}
globalnumber = roomNumber;
console.log(roomNumber);
try {
4 months ago
const response = await fetch(`http://10.133.48.140:8000/create-class/${globalnumber}`, {
4 months ago
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秒
}
4 months ago
async function charoom() {
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.48.140:8000/${globalnumber}/search-room`, {
method: 'POST',
});
4 months ago
4 months ago
if (!response.ok) {
throw new Error('连接失败。');
}
4 months ago
4 months ago
const data = await response.json(); // 解析响应数据(假设返回的是 JSON 格式)
alert(data.message);
if(data.message=="班级存在")
{
return 1;
}
4 months ago
4 months ago
else
{
return 2;
}
} catch (error) {
console.error('发生错误:', error.message); // 输出错误信息
alert(`连接后端服务器失败: ${error.message}`); // 弹窗显示错误信息
}
4 months ago
4 months ago
}
4 months ago
async function changepoints(chan)
{
4 months ago
const idi = globalStudent.id;
const namei = globalStudent.name;
const pointsi = chan;
globalStudent.points+=chan;
4 months ago
const response = await fetch(`http://10.133.48.140:8000/${globalnumber}/change-points`,
4 months ago
{
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);
});
4 months ago
document.getElementById('picked').innerText = `${globalStudent.name} \n 学号:${globalStudent.id} \n积分:${globalStudent.points}`;
}
4 months ago
function animateImage() {
const imageContainer = document.querySelector('.image-container');
// Step 1: 从右边弹出
imageContainer.style.right = '50%'; // 中间位置
imageContainer.style.transform = 'translate(50%, 0) rotate(360deg)'; // 转动
4 months ago
// Step 2: 等待旋转后从左边出去
setTimeout(() => {
imageContainer.style.right = '100%'; // 从左边出去
imageContainer.style.transform = 'translate(0, 0)'; // 重置旋转
}, 2000); // 旋转时间与动画匹配
}
4 months ago