|
|
async function uploadFile() {
|
|
|
const fileInput = document.getElementById('fileInput'); // 获取文件输入元素
|
|
|
|
|
|
// 检查是否选中了文件
|
|
|
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);
|
|
|
|
|
|
document.getElementById('result').innerText = '上传中...';
|
|
|
|
|
|
try {
|
|
|
const response = await fetch('http://10.133.39.58:8000/upload', {
|
|
|
method: 'POST',
|
|
|
body: formData
|
|
|
});
|
|
|
|
|
|
if (!response.ok) {
|
|
|
throw new Error('文件上传失败。');
|
|
|
}
|
|
|
|
|
|
const data = await response.json();
|
|
|
console.log(data);
|
|
|
document.getElementById('result').innerText = '上传成功!';
|
|
|
} catch (error) {
|
|
|
console.error('错误:', error);
|
|
|
alert('上传失败: ' + error.message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async function getRandomStudent() {
|
|
|
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 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 backpoints()
|
|
|
{
|
|
|
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})`;
|
|
|
|
|
|
}
|