229 lines
8.2 KiB
HTML
229 lines
8.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>登录 - 容量报表处理程序</title>
|
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>📊</text></svg>">
|
|
<style>
|
|
:root {
|
|
--brand-color: #0052d9;
|
|
--brand-hover: #0034b5;
|
|
--text-primary: rgba(0, 0, 0, 0.9);
|
|
--text-secondary: rgba(0, 0, 0, 0.6);
|
|
--text-placeholder: rgba(0, 0, 0, 0.4);
|
|
--bg-page: #f3f3f3;
|
|
--bg-container: #ffffff;
|
|
--bg-component: #f3f3f3;
|
|
--border-color: #dcdcdc;
|
|
--shadow: 0 6px 30px 5px rgba(0,0,0,0.05), 0 16px 24px 2px rgba(0,0,0,0.04), 0 8px 10px -5px rgba(0,0,0,0.08);
|
|
--radius: 12px;
|
|
--transition: 0.2s cubic-bezier(0.38, 0, 0.24, 1);
|
|
--error-color: #e34d59;
|
|
--success-color: #00a870;
|
|
--warning-color: #ed7b2f;
|
|
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
|
|
}
|
|
|
|
@media (prefers-color-scheme: dark) {
|
|
:root {
|
|
--brand-color: #4787f0;
|
|
--brand-hover: #618dff;
|
|
--text-primary: rgba(255, 255, 255, 0.9);
|
|
--text-secondary: rgba(255, 255, 255, 0.55);
|
|
--text-placeholder: rgba(255, 255, 255, 0.35);
|
|
--bg-page: #1b1b1b;
|
|
--bg-container: #242424;
|
|
--bg-component: #2c2c2c;
|
|
--border-color: #5e5e5e;
|
|
--shadow: 0 6px 30px 5px rgba(0,0,0,0.15), 0 16px 24px 2px rgba(0,0,0,0.12), 0 8px 10px -5px rgba(0,0,0,0.24);
|
|
}
|
|
}
|
|
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
html, body { height: 100%; }
|
|
|
|
body {
|
|
font-family: var(--font-family);
|
|
background: var(--bg-page);
|
|
color: var(--text-primary);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.login-container {
|
|
width: 380px;
|
|
padding: 48px 40px;
|
|
background: var(--bg-container);
|
|
border-radius: var(--radius);
|
|
box-shadow: var(--shadow);
|
|
text-align: center;
|
|
}
|
|
|
|
.login-logo { font-size: 56px; margin-bottom: 8px; line-height: 1; }
|
|
.login-title { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; letter-spacing: 0.5px; }
|
|
.login-subtitle { font-size: 14px; color: var(--text-secondary); margin-bottom: 32px; }
|
|
|
|
.login-form { text-align: left; }
|
|
|
|
.form-group { margin-bottom: 0; }
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 6px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.form-input {
|
|
width: 100%;
|
|
height: 40px;
|
|
padding: 0 12px;
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
color: var(--text-primary);
|
|
background: var(--bg-container);
|
|
transition: all var(--transition);
|
|
outline: none;
|
|
}
|
|
|
|
.form-input:focus {
|
|
border-color: var(--brand-color);
|
|
box-shadow: 0 0 0 2px rgba(0, 82, 217, 0.2);
|
|
}
|
|
|
|
.form-input[readonly] {
|
|
background: var(--bg-component);
|
|
color: var(--text-secondary);
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 100%;
|
|
height: 40px;
|
|
margin-top: 24px;
|
|
padding: 0 24px;
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
border: none;
|
|
cursor: pointer;
|
|
background: var(--brand-color);
|
|
color: #fff;
|
|
transition: all var(--transition);
|
|
}
|
|
|
|
.btn:hover { background: var(--brand-hover); }
|
|
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
|
|
.toast {
|
|
position: fixed;
|
|
top: 24px;
|
|
left: 50%;
|
|
transform: translateX(-50%) translateY(-120%);
|
|
padding: 10px 20px;
|
|
border-radius: 6px;
|
|
font-size: 13px;
|
|
color: #fff;
|
|
opacity: 0;
|
|
transition: all 0.3s ease;
|
|
z-index: 9999;
|
|
white-space: nowrap;
|
|
}
|
|
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
|
|
.toast.error { background: var(--error-color); }
|
|
.toast.success { background: var(--success-color); }
|
|
.toast.warning { background: var(--warning-color); }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="login-logo">📊</div>
|
|
<h2 class="login-title">CapacityReport</h2>
|
|
<p class="login-subtitle">容量报表处理系统</p>
|
|
<form class="login-form" id="loginForm" autocomplete="on">
|
|
<div class="form-group">
|
|
<label for="username">账号</label>
|
|
<input type="text" id="username" name="username" class="form-input" value="root" readonly>
|
|
</div>
|
|
<div class="form-group" style="margin-top: 16px;">
|
|
<label for="password">密码</label>
|
|
<input type="password" id="password" name="password" class="form-input" placeholder="请输入密码" autofocus>
|
|
</div>
|
|
<button type="submit" class="btn" id="loginBtn">登录</button>
|
|
</form>
|
|
</div>
|
|
<div class="toast" id="toast"></div>
|
|
|
|
<script>
|
|
const LEGACY_TOKEN_KEY = 'token';
|
|
const APP_TOKEN_KEY = 'capacity_report_token';
|
|
|
|
function getLegacyHomePath() {
|
|
const path = window.location.pathname;
|
|
return path === '/old/login.html' || path.startsWith('/old/') ? '/old' : '/';
|
|
}
|
|
|
|
function setAuthToken(token) {
|
|
if (!token) return;
|
|
localStorage.setItem(APP_TOKEN_KEY, token);
|
|
localStorage.setItem(LEGACY_TOKEN_KEY, token);
|
|
document.cookie = `token=${encodeURIComponent(token)}; path=/; max-age=${86400 * 30}; SameSite=Lax`;
|
|
}
|
|
|
|
function showToast(msg, type) {
|
|
const t = document.getElementById('toast');
|
|
t.textContent = msg;
|
|
t.className = 'toast ' + (type || 'error');
|
|
t.classList.add('show');
|
|
setTimeout(() => { t.classList.remove('show'); }, 3000);
|
|
}
|
|
|
|
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const btn = document.getElementById('loginBtn');
|
|
const password = document.getElementById('password').value;
|
|
const username = document.getElementById('username').value;
|
|
|
|
if (!password) {
|
|
showToast('请输入密码', 'warning');
|
|
return;
|
|
}
|
|
|
|
btn.disabled = true;
|
|
btn.textContent = '登录中...';
|
|
|
|
try {
|
|
const res = await fetch('/api/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ username, password })
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const err = await res.json().catch(() => ({ detail: '登录失败' }));
|
|
throw new Error(err.detail || '账号或密码错误');
|
|
}
|
|
|
|
const data = await res.json();
|
|
if (data.success && data.token) {
|
|
setAuthToken(data.token);
|
|
showToast('登录成功', 'success');
|
|
setTimeout(() => { window.location.href = getLegacyHomePath(); }, 300);
|
|
}
|
|
} catch (err) {
|
|
showToast(err.message, 'error');
|
|
} finally {
|
|
btn.disabled = false;
|
|
btn.textContent = '登录';
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|