数据管理页面的完善
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>填写班级信息</title>
|
||||
<style>
|
||||
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: #f5f6fa; }
|
||||
.container { max-width: 400px; margin: 15vh auto; padding: 24px; background: #fff; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.08); }
|
||||
h1 { font-size: 20px; margin: 0 0 16px; text-align: center; }
|
||||
label { display:block; margin: 12px 0 6px; color:#333; }
|
||||
input { width:100%; padding:10px 0px; border:1px solid #dcdde1; border-radius:6px; box-sizing: border-box; }
|
||||
button { width:100%; margin-top:16px; padding:10px 12px; background:#2d8cf0; color:#fff; border:none; border-radius:6px; cursor:pointer; }
|
||||
button:disabled { background:#9bbcf0; cursor:not-allowed; }
|
||||
.error { color:#d93025; margin-top:10px; min-height:20px; font-size: 14px; }
|
||||
.hint { color:#888; font-size:12px; margin-top:10px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>完善班级信息</h1>
|
||||
<form id="classForm">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" id="user_id" value="{{ user_id }}">
|
||||
<label for="class_name">所在班级</label>
|
||||
<input id="class_name" name="class_name" type="text" placeholder="例:2024级计算机专业1班" required />
|
||||
<div class="hint">格式要求:XXXX级YY专业Z班(记得加“专业”两个字)</div>
|
||||
<button id="submitBtn" type="submit">提交并进入登录页</button>
|
||||
<div id="error" class="error"></div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
function getCookie(name){const v=`; ${document.cookie}`;const p=v.split(`; ${name}=`);if(p.length===2) return p.pop().split(';').shift();}
|
||||
|
||||
document.getElementById('classForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const err = document.getElementById('error');
|
||||
err.textContent = '';
|
||||
const className = document.getElementById('class_name').value.trim();
|
||||
const userId = document.getElementById('user_id').value;
|
||||
|
||||
// 正则校验:2024级**专业*班
|
||||
const pattern = /^\d{4}级.+专业\d+班$/;
|
||||
if (!pattern.test(className)) {
|
||||
err.textContent = '班级格式不正确,请重新输入(例:2024级计算机专业1班)';
|
||||
return;
|
||||
}
|
||||
|
||||
const btn = document.getElementById('submitBtn');
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
const csrftoken = getCookie('csrftoken');
|
||||
const resp = await fetch('/accounts/class-info/submit/', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrftoken || ''
|
||||
},
|
||||
body: JSON.stringify({ user_id: userId, class_name: className })
|
||||
});
|
||||
const data = await resp.json();
|
||||
if (!resp.ok || !data.ok) {
|
||||
throw new Error(data.message || '提交失败');
|
||||
}
|
||||
window.location.href = '/accounts/login/';
|
||||
} catch (e) {
|
||||
err.textContent = e.message || '发生错误';
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user