feat(server.tests.test5): 新增 server 实验5

This commit is contained in:
2025-11-18 13:35:30 +08:00
parent 84b4770d5a
commit d0acf5a36d
9 changed files with 1095 additions and 1 deletions

View File

@@ -0,0 +1,106 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register</title>
<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;
}
input,
select,
textarea {
padding: 8px;
font-size: 15px;
}
button {
padding: 10px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<form id="registerForm">
<input id="username" type="text" placeholder="用户名" required>
<input id="password" type="password" placeholder="密码" required>
<input id="email" type="email" placeholder="邮箱" required>
<select id="gender">
<option value="male"></option>
<option value="female"></option>
</select>
<input id="hobbies" type="text" placeholder="爱好(用逗号分隔,例如:听音乐,玩游戏)">
<input id="city" type="text" placeholder="城市,例如:重庆">
<textarea id="description" rows="3" placeholder="自我介绍"></textarea>
<button type="button" id="registerBtn">注册</button>
</form>
<script>
document.getElementById("registerBtn").addEventListener("click", register);
async function register() {
const username = document.getElementById("username").value.trim();
const password = document.getElementById("password").value.trim();
const email = document.getElementById("email").value.trim();
const gender = document.getElementById("gender").value;
const hobbiesInput = document.getElementById("hobbies").value.trim();
const city = document.getElementById("city").value.trim();
const description = document.getElementById("description").value.trim();
if (!username || !password || !email) {
alert("请填写必填字段:用户名、密码、邮箱");
return;
}
const hobbies = hobbiesInput ? hobbiesInput.split(",").map(i => i.trim()) : [];
const payload = {
username,
password,
email,
gender,
hobbies,
city,
description
};
const res = await fetch("http://localhost:3000/register", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
const data = await res.text(); // 后端是字符串
alert(data);
}
</script>
</body>
</html>