// 全局变量定义 const serverIP = '10.28.20.150'; const serverPort = '8080'; document.addEventListener('DOMContentLoaded', () => { fetch(`http://${serverIP}:${serverPort}/api/image`) .then(response => response.blob()) .then(imageBlob => { const imageObjectURL = URL.createObjectURL(imageBlob); document.getElementById('logo').src = imageObjectURL; }) .catch(error => { console.error('Error fetching logo:', error); }); }); async function login(event) { event.preventDefault(); // 阻止表单的默认提交行为 const Account = document.getElementById('Account').value; const password = document.getElementById('password').value; try { const response = await fetch(`http://${serverIP}:${serverPort}/api/login`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ Account, password }) }); if (!response.ok) { const errorText = await response.text(); throw new Error(errorText || response.statusText); } const result = await response.json(); const token = result.token; // 假设服务器返回的 JSON 中包含一个 token 字段 localStorage.setItem('Authorization', token); // 登录成功后重定向到 license_info.html 页面 window.location.href = '/static/license_info/license_info.html'; } catch (error) { alert('登录失败: ' + error.message); } }