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.

285 lines
8.4 KiB

<!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: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.login-container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 100%;
max-width: 420px;
padding: 40px;
animation: slideIn 0.5s ease-out;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.login-header {
text-align: center;
margin-bottom: 40px;
}
.login-logo {
font-size: 48px;
margin-bottom: 10px;
}
.login-title {
font-size: 28px;
font-weight: 700;
color: #1D1D1F;
margin-bottom: 8px;
}
.login-subtitle {
font-size: 14px;
color: #86868B;
}
.form-group {
margin-bottom: 24px;
}
.form-label {
display: block;
font-size: 14px;
font-weight: 600;
color: #1D1D1F;
margin-bottom: 8px;
}
.form-input {
width: 100%;
padding: 12px 16px;
border: 2px solid #E5E5E7;
border-radius: 12px;
font-size: 15px;
transition: all 0.3s;
outline: none;
}
.form-input:focus {
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.login-btn {
width: 100%;
padding: 14px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 12px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
margin-top: 10px;
}
.login-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
.login-btn:active {
transform: translateY(0);
}
.login-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.error-message {
background: #FFF3F3;
color: #DC2626;
padding: 12px 16px;
border-radius: 8px;
font-size: 14px;
margin-bottom: 20px;
display: none;
border-left: 4px solid #DC2626;
}
.error-message.show {
display: block;
animation: shake 0.5s;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-10px); }
75% { transform: translateX(10px); }
}
.footer {
text-align: center;
margin-top: 30px;
font-size: 12px;
color: #86868B;
}
.loading-spinner {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 1s ease-in-out infinite;
margin-right: 8px;
vertical-align: middle;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="login-container">
<div class="login-header">
<div class="login-logo"></div>
<h1 class="login-title">期货智析</h1>
<p class="login-subtitle">智能期货期权分析系统</p>
</div>
<div class="error-message" id="error-message"></div>
<form id="login-form">
<div class="form-group">
<label class="form-label" for="username">用户名</label>
<input type="text" id="username" class="form-input" placeholder="请输入用户名" required autocomplete="username">
</div>
<div class="form-group">
<label class="form-label" for="password">密码</label>
<input type="password" id="password" class="form-input" placeholder="请输入密码" required autocomplete="current-password">
</div>
<button type="submit" class="login-btn" id="login-btn">
登录
</button>
</form>
<div class="footer">
<p>© 2026 期货智析系统 · 安全登录</p>
</div>
</div>
<script>
const loginForm = document.getElementById('login-form');
const loginBtn = document.getElementById('login-btn');
const errorMessage = document.getElementById('error-message');
loginForm.addEventListener('submit', async (e) => {
e.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
loginBtn.disabled = true;
loginBtn.innerHTML = '<span class="loading-spinner"></span>登录中...';
errorMessage.classList.remove('show');
try {
const response = await fetch('/api/v1/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, password })
});
const data = await response.json();
if (data.success) {
// 保存令牌
localStorage.setItem('auth_token', data.token);
localStorage.setItem('user_info', JSON.stringify(data.user));
// 根据角色跳转
if (data.user.role === 'admin') {
window.location.href = '/role-select';
} else {
window.location.href = '/futures-analysis';
}
} else {
showError(data.message || '登录失败,请重试');
}
} catch (error) {
showError('网络错误,请检查连接后重试');
} finally {
loginBtn.disabled = false;
loginBtn.innerHTML = '登录';
}
});
function showError(message) {
errorMessage.textContent = message;
errorMessage.classList.add('show');
setTimeout(() => {
errorMessage.classList.remove('show');
}, 5000);
}
// 检查是否已登录
window.addEventListener('DOMContentLoaded', async () => {
const token = localStorage.getItem('auth_token');
if (token) {
try {
const response = await fetch('/api/v1/auth/verify', {
headers: {
'Authorization': `Bearer ${token}`
}
});
if (response.ok) {
const data = await response.json();
if (data.user.role === 'admin') {
window.location.href = '/role-select';
} else {
window.location.href = '/futures-analysis';
}
}
} catch (error) {
// 令牌无效,继续显示登录页
localStorage.removeItem('auth_token');
localStorage.removeItem('user_info');
}
}
});
</script>
</body>
</html>