78 lines
1.9 KiB
HTML
78 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
body,
|
|
html {
|
|
margin: 0;
|
|
height: 100%;
|
|
width: 100%;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
form {
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: 280px;
|
|
gap: 12px;
|
|
text-align: center;
|
|
}
|
|
|
|
input {
|
|
padding: 8px;
|
|
font-size: 15px;
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
button {
|
|
padding: 10px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
<title>Login</title>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<form id="loginForm">
|
|
<input type="text" id="username" placeholder="请输入用户名">
|
|
<input type="password" id="password" placeholder="请输入密码">
|
|
<button type="button" id="loginBtn">登录</button>
|
|
</form>
|
|
|
|
<script>
|
|
document.getElementById("loginBtn").addEventListener("click", login);
|
|
|
|
async function login() {
|
|
const username = document.getElementById("username").value.trim();
|
|
const password = document.getElementById("password").value.trim();
|
|
|
|
if (!username || !password) {
|
|
alert("请输入用户名和密码");
|
|
return;
|
|
}
|
|
|
|
const res = await fetch("http://localhost:3000/login", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: JSON.stringify({ username, password })
|
|
});
|
|
|
|
const data = await res.text();
|
|
alert(data);
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|