blob: 993941dc044f87648086bc484198af0a6863a58d [file] [log] [blame]
Your Name695f6a62025-05-17 00:58:04 +08001<!-- src/main/resources/static/login.html -->
2<!DOCTYPE html>
3<html lang="zh-CN">
4<head>
5 <meta charset="UTF-8">
6 <title>登录</title>
7</head>
8<body>
9<h2>用户登录</h2>
10<form id="loginForm">
11 <label>身份证号:</label>
12 <input type="number" name="identificationNumber" required>
13 <label>密码:</label>
14 <input type="password" name="password" required>
15 <button type="submit">登录</button>
16</form>
17<script>
18 document.getElementById('loginForm')
19 .addEventListener('submit', async e => {
20 e.preventDefault();
21 const form = new URLSearchParams(new FormData(e.target));
22 const res = await fetch('/login', {
23 method: 'POST',
24 body: form
25 });
26 const json = await res.json();
27 if (res.ok && json.code === 0) {
28 // 保存 token
29 localStorage.setItem('token', json.data);
30 // 跳转到受保护的页面
31 window.location.href = 'home.html';
32 } else {
33 alert(json.msg);
34 }
35 });
36</script>
37</body>
38</html>