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); }); }