305 lines
9.5 KiB
HTML
305 lines
9.5 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>DNS服务器控制台 - 登录</title>
|
|
<!-- Font Awesome -->
|
|
<link href="css/font-awesome.min.css" rel="stylesheet">
|
|
<style>
|
|
/* CSS变量定义 */
|
|
:root {
|
|
--bg-primary: #f5f7fa;
|
|
--bg-secondary: #ffffff;
|
|
--text-primary: #333333;
|
|
--text-secondary: #555555;
|
|
--text-muted: #7f8c8d;
|
|
--border-color: #e1e5e9;
|
|
--primary-color: #3498db;
|
|
--primary-hover: #2980b9;
|
|
--error-bg: #fee;
|
|
--error-text: #c00;
|
|
--shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.dark {
|
|
--bg-primary: #1a1a1a;
|
|
--bg-secondary: #2d2d2d;
|
|
--text-primary: #e2e8f0;
|
|
--text-secondary: #a0aec0;
|
|
--text-muted: #718096;
|
|
--border-color: #4a5568;
|
|
--primary-color: #4299e1;
|
|
--primary-hover: #3182ce;
|
|
--error-bg: #742a2a;
|
|
--error-text: #fed7d7;
|
|
--shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
background-color: var(--bg-primary);
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
color: var(--text-primary);
|
|
transition: background-color 0.3s ease, color 0.3s ease;
|
|
}
|
|
|
|
/* 主题切换按钮 */
|
|
#theme-toggle {
|
|
position: absolute;
|
|
top: 20px;
|
|
right: 20px;
|
|
background: var(--bg-secondary);
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 50%;
|
|
width: 40px;
|
|
height: 40px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
cursor: pointer;
|
|
color: var(--text-primary);
|
|
box-shadow: var(--shadow);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
#theme-toggle:hover {
|
|
background: var(--primary-color);
|
|
color: white;
|
|
}
|
|
|
|
.login-container {
|
|
background-color: var(--bg-secondary);
|
|
border-radius: 8px;
|
|
box-shadow: var(--shadow);
|
|
padding: 40px;
|
|
width: 100%;
|
|
max-width: 400px;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.login-header {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.login-header h1 {
|
|
font-size: 24px;
|
|
color: var(--text-primary);
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.login-header p {
|
|
color: var(--text-muted);
|
|
font-size: 14px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
font-weight: 500;
|
|
color: var(--text-secondary);
|
|
}
|
|
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 4px;
|
|
font-size: 16px;
|
|
background-color: var(--bg-secondary);
|
|
color: var(--text-primary);
|
|
transition: border-color 0.3s ease;
|
|
}
|
|
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: var(--primary-color);
|
|
box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.1);
|
|
}
|
|
|
|
.btn {
|
|
width: 100%;
|
|
padding: 12px;
|
|
background-color: var(--primary-color);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-size: 16px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s ease;
|
|
}
|
|
|
|
.btn:hover {
|
|
background-color: var(--primary-hover);
|
|
}
|
|
|
|
.btn:active {
|
|
transform: translateY(1px);
|
|
}
|
|
|
|
.error-message {
|
|
background-color: var(--error-bg);
|
|
color: var(--error-text);
|
|
padding: 12px;
|
|
border-radius: 4px;
|
|
margin-bottom: 20px;
|
|
text-align: center;
|
|
font-size: 14px;
|
|
display: none;
|
|
}
|
|
|
|
.loading {
|
|
opacity: 0.7;
|
|
cursor: not-allowed;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- 主题切换按钮 -->
|
|
<button id="theme-toggle" class="theme-toggle-btn">
|
|
<i class="fa fa-moon-o"></i>
|
|
</button>
|
|
|
|
<div class="login-container">
|
|
<div class="login-header">
|
|
<h1>DNS服务器控制台</h1>
|
|
<p>请输入您的登录凭据</p>
|
|
</div>
|
|
|
|
<div class="error-message" id="errorMessage"></div>
|
|
|
|
<form id="loginForm">
|
|
<div class="form-group">
|
|
<label for="username">用户名</label>
|
|
<input type="text" id="username" name="username" placeholder="请输入用户名" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="password">密码</label>
|
|
<input type="password" id="password" name="password" placeholder="请输入密码" required>
|
|
</div>
|
|
|
|
<button type="submit" class="btn" id="loginBtn">登录</button>
|
|
</form>
|
|
</div>
|
|
|
|
<script>
|
|
// 主题切换功能
|
|
function initThemeToggle() {
|
|
const themeToggleBtn = document.getElementById('theme-toggle');
|
|
if (!themeToggleBtn) return;
|
|
|
|
// 初始化主题
|
|
const savedTheme = localStorage.getItem('theme');
|
|
if (savedTheme === 'dark') {
|
|
document.documentElement.classList.add('dark');
|
|
updateThemeIcon(true);
|
|
}
|
|
|
|
// 添加主题切换事件监听器
|
|
themeToggleBtn.addEventListener('click', toggleTheme);
|
|
}
|
|
|
|
// 切换主题
|
|
function toggleTheme() {
|
|
const isDark = document.documentElement.classList.toggle('dark');
|
|
localStorage.setItem('theme', isDark ? 'dark' : 'light');
|
|
updateThemeIcon(isDark);
|
|
}
|
|
|
|
// 更新主题图标
|
|
function updateThemeIcon(isDark) {
|
|
const themeToggleBtn = document.getElementById('theme-toggle');
|
|
if (!themeToggleBtn) return;
|
|
|
|
const icon = themeToggleBtn.querySelector('i');
|
|
if (isDark) {
|
|
icon.classList.remove('fa-moon-o');
|
|
icon.classList.add('fa-sun-o');
|
|
} else {
|
|
icon.classList.remove('fa-sun-o');
|
|
icon.classList.add('fa-moon-o');
|
|
}
|
|
}
|
|
|
|
// 初始化登录表单
|
|
function initLoginForm() {
|
|
document.getElementById('loginForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const username = document.getElementById('username').value;
|
|
const password = document.getElementById('password').value;
|
|
const loginBtn = document.getElementById('loginBtn');
|
|
const errorMessage = document.getElementById('errorMessage');
|
|
|
|
// 显示加载状态
|
|
loginBtn.textContent = '登录中...';
|
|
loginBtn.classList.add('loading');
|
|
errorMessage.style.display = 'none';
|
|
|
|
// 发送登录请求
|
|
fetch('/api/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
username: username,
|
|
password: password
|
|
})
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
if (response.status === 401) {
|
|
throw new Error('未知用户名或密码');
|
|
} else {
|
|
throw new Error('登录失败');
|
|
}
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
if (data.status === 'success') {
|
|
// 登录成功,重定向到主页
|
|
window.location.href = '/';
|
|
} else {
|
|
if (data.error === '用户名或密码错误') {
|
|
throw new Error('未知用户名或密码');
|
|
} else {
|
|
throw new Error(data.error || '登录失败');
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
// 显示错误信息
|
|
errorMessage.textContent = error.message;
|
|
errorMessage.style.display = 'block';
|
|
loginBtn.textContent = '登录';
|
|
loginBtn.classList.remove('loading');
|
|
});
|
|
});
|
|
}
|
|
|
|
// 页面加载完成后初始化
|
|
window.addEventListener('DOMContentLoaded', function() {
|
|
initThemeToggle();
|
|
initLoginForm();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |