1234567891011121314151617181920212223242526272829303132333435363738394041 |
- document.addEventListener('DOMContentLoaded', () => {
- fetch('http://127.0.0.1:8080/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://127.0.0.1:8080/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);
- }
- }
|