superlishunqin 68b99755ec ALL
2024-11-14 15:46:37 +08:00

61 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function editAssignment(assignmentId, currentDeadline) {
const newDeadline = prompt("请输入新的截止日期格式YYYY-MM-DD:", currentDeadline);
if (newDeadline) {
fetch(`/teacher/edit_assignment/${assignmentId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ deadline: newDeadline })
})
.then(response => {
if (response.ok) {
alert('截止日期已更新');
location.reload();
} else {
alert('更新失败');
}
})
.catch(error => console.error('Error:', error));
}
}
function deleteAssignment(assignmentId) {
if (confirm("您确定要删除这个作业吗?")) {
fetch(`/teacher/delete_assignment/${assignmentId}`, {
method: 'DELETE'
})
.then(response => {
if (response.ok) {
alert('作业已删除');
location.reload();
} else {
alert('删除失败');
}
})
.catch(error => console.error('Error:', error));
}
}
function downloadAssignment(assignmentValue) {
fetch(`/teacher/download-assignment/${assignmentValue}`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.blob(); // 将响应体转换为 Blob 对象
})
.then(blob => {
const url = window.URL.createObjectURL(blob); // 为 Blob 对象生成临时的 Object URL
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = `${assignmentValue}.zip`; // 动态设置文件名
document.body.appendChild(a);
a.click(); // 触发下载
window.URL.revokeObjectURL(url); // 释放 Object URL
})
.catch(error => {
console.error('Download failed:', error);
});
}