blob: 993941dc044f87648086bc484198af0a6863a58d [file] [log] [blame]
<!-- src/main/resources/static/login.html -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<h2>用户登录</h2>
<form id="loginForm">
<label>身份证号:</label>
<input type="number" name="identificationNumber" required>
<label>密码:</label>
<input type="password" name="password" required>
<button type="submit">登录</button>
</form>
<script>
document.getElementById('loginForm')
.addEventListener('submit', async e => {
e.preventDefault();
const form = new URLSearchParams(new FormData(e.target));
const res = await fetch('/login', {
method: 'POST',
body: form
});
const json = await res.json();
if (res.ok && json.code === 0) {
// 保存 token
localStorage.setItem('token', json.data);
// 跳转到受保护的页面
window.location.href = 'home.html';
} else {
alert(json.msg);
}
});
</script>
</body>
</html>