File size: 10,960 Bytes
ceb3821
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE html>
<html lang="zh-CN" id="html-root">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title data-i18n="login.title">登录 - AIClient2API</title>
    <link rel="icon" type="image/x-icon" href="/favicon.ico">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .login-container {
            background: white;
            border-radius: 12px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
            padding: 40px;
            animation: fadeIn 0.5s ease-in;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .logo {
            text-align: center;
            margin-bottom: 30px;
        }

        .logo img {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            margin-bottom: 15px;
        }

        .logo h1 {
            font-size: 24px;
            color: #333;
            margin-bottom: 5px;
        }

        .logo p {
            font-size: 14px;
            color: #666;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-size: 14px;
            font-weight: 500;
        }

        .form-group input {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #e1e8ed;
            border-radius: 8px;
            font-size: 14px;
            transition: all 0.3s ease;
            outline: none;
        }

        .form-group input:focus {
            border-color: #059669;
            box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
        }

        .form-group input::placeholder {
            color: #aaa;
        }

        .error-message {
            color: #e74c3c;
            font-size: 13px;
            margin-top: 8px;
            display: none;
            animation: shake 0.3s ease-in-out;
        }

        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-10px); }
            75% { transform: translateX(10px); }
        }

        .error-message.show {
            display: block;
        }

        .login-button {
            width: 100%;
            padding: 12px;
            background: linear-gradient(135deg, #059669 0%, #10b981 100%);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 10px;
        }

        .login-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 20px rgba(5, 150, 105, 0.4);
        }

        .login-button:active {
            transform: translateY(0);
        }

        .login-button:disabled {
            background: #ccc;
            cursor: not-allowed;
            transform: none;
        }

        .footer {
            text-align: center;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #e1e8ed;
        }

        .footer p {
            font-size: 13px;
            color: #999;
        }

        .loading {
            display: inline-block;
            width: 16px;
            height: 16px;
            border: 2px solid #ffffff;
            border-radius: 50%;
            border-top-color: transparent;
            animation: spin 0.8s linear infinite;
            margin-right: 8px;
            vertical-align: middle;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        @media (max-width: 480px) {
            .login-container {
                padding: 30px 20px;
            }

            .logo h1 {
                font-size: 20px;
            }
        }
    </style>
    <link rel="stylesheet" href="app/base.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
    <div style="position: absolute; top: 20px; right: 20px;" id="langSwitcherContainer"></div>
    <div class="login-container">
        <div class="logo">
            <img src="/favicon.ico" alt="Logo" onerror="this.style.display='none'">
            <h1>AIClient2API</h1>
            <p data-i18n="login.heading">请登录以继续</p>
        </div>

        <form id="loginForm">
            <div class="form-group">
                <label for="password" data-i18n="login.password">密码</label>
                <input
                    type="password"
                    id="password"
                    name="password"
                    data-i18n="login.passwordPlaceholder"
                    placeholder="请输入密码"
                    autocomplete="current-password"
                    required
                >
                <div class="error-message" id="errorMessage" data-i18n="login.error.incorrect">密码错误,请重试</div>
            </div>

            <button type="submit" class="login-button" id="loginButton" data-i18n="login.button">
                登录
            </button>
        </form>

        <div class="footer">
            <p>&copy; 2025 AIClient2API. All rights reserved.</p>
        </div>
    </div>

    <script type="module">
        import { initI18n, t, setLanguage } from './app/i18n.js';
        import { initLanguageSwitcher } from './app/language-switcher.js';

        // 初始化多语言
        initI18n();
        
        // 初始化语言切换器
        const langContainer = document.getElementById('langSwitcherContainer');
        if (langContainer) {
            import('./app/language-switcher.js').then(module => {
                const switcher = module.createLanguageSwitcher();
                langContainer.appendChild(switcher);
                
                // 绑定事件逻辑(由于是动态创建,复用逻辑)
                const languageBtn = switcher.querySelector('#languageBtn');
                const languageDropdown = switcher.querySelector('#languageDropdown');
                const languageOptions = switcher.querySelectorAll('.language-option');
                
                languageBtn.addEventListener('click', (e) => {
                    e.stopPropagation();
                    languageDropdown.classList.toggle('show');
                });
                
                languageOptions.forEach(option => {
                    option.addEventListener('click', (e) => {
                        e.stopPropagation();
                        const lang = option.getAttribute('data-lang');
                        setLanguage(lang);
                        switcher.querySelector('.current-lang').textContent = lang === 'zh-CN' ? '中文' : 'EN';
                        languageOptions.forEach(opt => opt.classList.remove('active'));
                        option.classList.add('active');
                        languageDropdown.classList.remove('show');
                    });
                });
                
                document.addEventListener('click', () => {
                    languageDropdown.classList.remove('show');
                });
            });
        }

        const loginForm = document.getElementById('loginForm');
        const passwordInput = document.getElementById('password');
        const errorMessage = document.getElementById('errorMessage');
        const loginButton = document.getElementById('loginButton');

        // 检查是否已经登录
        checkLoginStatus();

        loginForm.addEventListener('submit', async (e) => {
            e.preventDefault();
            
            const password = passwordInput.value.trim();
            
            if (!password) {
                showError(t('login.error.empty'));
                return;
            }

            // 禁用按钮并显示加载状态
            loginButton.disabled = true;
            loginButton.innerHTML = `<span class="loading"></span>${t('login.loggingIn')}`;
            errorMessage.classList.remove('show');

            try {
                // 直接使用fetch进行登录请求(登录页面不需要token)
                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) {
                    // 登录成功,保存token
                    localStorage.setItem('authToken', data.token);
                    
                    // 跳转到主页
                    window.location.href = '/';
                } else {
                    showError(data.message || t('login.error.incorrect'));
                    loginButton.disabled = false;
                    loginButton.innerHTML = t('login.button');
                    passwordInput.value = '';
                    passwordInput.focus();
                }
            } catch (error) {
                console.error('登录错误:', error);
                showError(t('login.error.failed'));
                loginButton.disabled = false;
                loginButton.innerHTML = t('login.button');
            }
        });

        function showError(message) {
            errorMessage.textContent = message;
            errorMessage.classList.add('show');
            passwordInput.classList.add('error');
            
            setTimeout(() => {
                passwordInput.classList.remove('error');
            }, 300);
        }

        function checkLoginStatus() {
            const token = localStorage.getItem('authToken');
            
            if (token) {
                // Token存在,跳转到主页
                window.location.href = '/';
            }
        }

        // 监听输入,清除错误提示
        passwordInput.addEventListener('input', () => {
            errorMessage.classList.remove('show');
        });

        // 页面加载时聚焦到密码输入框
        passwordInput.focus();
    </script>
    </body>
</html>