(() => { const button = document.getElementById('loginBtn'); if (!button) return; button.addEventListener('click', async (event) => { const name = document.getElementById('loginName')?.value.trim(); const password = document.getElementById('loginPass')?.value || ''; if (!name || !password) return; try { const response = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name, password }) }); const result = await response.json(); if (!response.ok) throw new Error(result.error || '登录失败'); window.__manyiToken = result.token; window.__manyiUser = result.user; document.getElementById('login').style.display = 'none'; document.getElementById('app').style.display = 'flex'; } catch (error) { alert(error.message); } }, true); })();