| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>登录 - CJYDocs</title>
- <link rel="stylesheet" href="css/style.css">
- <style>
- .login-container {
- min-height: 100vh;
- display: flex;
- align-items: center;
- justify-content: center;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- padding: 20px;
- }
- .login-box {
- background: white;
- border-radius: 12px;
- box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
- padding: 40px;
- width: 100%;
- max-width: 400px;
- }
- .login-header {
- text-align: center;
- margin-bottom: 30px;
- }
- .login-title {
- font-size: 2rem;
- font-weight: 700;
- color: var(--text-color);
- margin-bottom: 8px;
- }
- .login-subtitle {
- color: #6b7280;
- font-size: 0.95rem;
- }
- .form-group {
- margin-bottom: 20px;
- }
- .form-label {
- display: block;
- font-weight: 500;
- margin-bottom: 8px;
- color: var(--text-color);
- }
- .form-input {
- width: 100%;
- padding: 12px 16px;
- border: 2px solid var(--border-color);
- border-radius: 8px;
- font-size: 1rem;
- transition: border-color 0.2s;
- }
- .form-input:focus {
- outline: none;
- border-color: var(--primary-color);
- }
- .login-btn {
- width: 100%;
- padding: 12px;
- background: var(--primary-color);
- color: white;
- border: none;
- border-radius: 8px;
- font-size: 1rem;
- font-weight: 600;
- cursor: pointer;
- transition: background-color 0.2s;
- }
- .login-btn:hover {
- background: var(--primary-hover);
- }
- .login-btn:disabled {
- background: #9ca3af;
- cursor: not-allowed;
- }
- .error-message {
- background: #fee2e2;
- color: #dc2626;
- padding: 12px;
- border-radius: 8px;
- margin-bottom: 20px;
- display: none;
- text-align: center;
- font-size: 0.9rem;
- }
- .error-message.show {
- display: block;
- }
- .password-toggle {
- position: relative;
- }
- .toggle-btn {
- position: absolute;
- right: 12px;
- top: 50%;
- transform: translateY(-50%);
- background: none;
- border: none;
- color: #6b7280;
- cursor: pointer;
- padding: 4px 8px;
- font-size: 0.85rem;
- }
- .toggle-btn:hover {
- color: var(--primary-color);
- }
- </style>
- </head>
- <body>
- <div class="login-container">
- <div class="login-box">
- <div class="login-header">
- <h1 class="login-title">CJYDocs</h1>
- <p class="login-subtitle">请输入密码访问文档系统</p>
- </div>
- <div id="error-message" class="error-message"></div>
- <form id="login-form">
- <div class="form-group">
- <label for="password" class="form-label">密码</label>
- <div class="password-toggle">
- <input
- type="password"
- id="password"
- class="form-input"
- placeholder="请输入密码"
- required
- autocomplete="current-password"
- >
- <button type="button" class="toggle-btn" id="toggle-password">显示</button>
- </div>
- </div>
- <button type="submit" class="login-btn" id="login-btn">
- 登录
- </button>
- </form>
- </div>
- </div>
- <script>
- const loginForm = document.getElementById('login-form');
- const passwordInput = document.getElementById('password');
- const loginBtn = document.getElementById('login-btn');
- const errorMessage = document.getElementById('error-message');
- const togglePasswordBtn = document.getElementById('toggle-password');
- // 切换密码显示/隐藏
- togglePasswordBtn.addEventListener('click', () => {
- if (passwordInput.type === 'password') {
- passwordInput.type = 'text';
- togglePasswordBtn.textContent = '隐藏';
- } else {
- passwordInput.type = 'password';
- togglePasswordBtn.textContent = '显示';
- }
- });
- // 显示错误信息
- function showError(message) {
- errorMessage.textContent = message;
- errorMessage.classList.add('show');
- setTimeout(() => {
- errorMessage.classList.remove('show');
- }, 3000);
- }
- // 登录表单提交
- loginForm.addEventListener('submit', async (e) => {
- e.preventDefault();
- const password = passwordInput.value.trim();
- if (!password) {
- showError('请输入密码');
- return;
- }
- // 禁用按钮,防止重复提交
- loginBtn.disabled = true;
- loginBtn.textContent = '登录中...';
- try {
- const response = await fetch('/api/login', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({ password })
- });
- const data = await response.json();
- if (response.ok && data.success) {
- // 登录成功,跳转到首页
- window.location.href = '/';
- } else {
- // 登录失败
- showError(data.error || '密码错误,请重试');
- passwordInput.value = '';
- passwordInput.focus();
- }
- } catch (error) {
- console.error('Login error:', error);
- showError('登录失败,请稍后重试');
- } finally {
- // 恢复按钮状态
- loginBtn.disabled = false;
- loginBtn.textContent = '登录';
- }
- });
- // 页面加载时聚焦到密码输入框
- passwordInput.focus();
- </script>
- </body>
- </html>
|