You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.3 KiB

2 months ago
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #f0f2f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-container {
background-color: white;
padding: 40px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
}
h2 {
text-align: center;
margin-bottom: 30px;
color: #333;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
color: #666;
font-weight: bold;
}
input {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
input:focus {
outline: none;
border-color: #1890ff;
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}
button {
width: 100%;
padding: 12px;
background-color: #1890ff;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
margin-top: 20px;
}
button:hover {
background-color: #40a9ff;
}
.error-message {
color: #ff4d4f;
text-align: center;
margin-top: 15px;
}
</style>
</head>
<body>
<div class="login-container">
<h2>用户登录</h2>
<form id="loginForm">
<div class="form-group">
<label for="projectName">职位名称</label>
<input type="text" id="projectName" name="projectName" required>
</div>
<div class="form-group">
<label for="userName">用户名</label>
<input type="text" id="userName" name="userName" required>
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit">登录</button>
<div id="errorMessage" class="error-message"></div>
</form>
</div>
<script>
document.getElementById('loginForm').addEventListener('submit', function(e) {
e.preventDefault();
const projectName = document.getElementById('projectName').value;
const userName = document.getElementById('userName').value;
const password = document.getElementById('password').value;
const errorMessage = document.getElementById('errorMessage');
errorMessage.textContent = '';
// 发送登录请求
fetch('http://8.137.125.67:8083/KH/api/login', {
2 months ago
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
projectName: projectName,
userName: userName,
password: password
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
// 登录成功,存储用户信息并跳转到主页面
localStorage.setItem('userInfo', JSON.stringify(data));
window.location.href = 'index.html';
} else {
errorMessage.textContent = data.message;
}
})
.catch(error => {
console.error('登录失败:', error);
errorMessage.textContent = '登录失败,请重试';
});
});
</script>
</body>
</html>