This commit introduces a series of refactoring changes to the web-ui to remove hardcoded values and improve page integration. - **Centralized Configuration:** Created to centralize API ports, paths, and navigation URLs, replacing hardcoded values across multiple files. - **Modular Component Loading:** Introduced to handle dynamic loading of common HTML components (e.g., sidebar, navbar), using paths from . - **Modular Navigation:** Created to centralize page redirection logic, improving maintainability and reducing direct manipulations. - **Refactored Existing Modules:** Updated , , , and to utilize the new , , and modules. - **ES6 Module Compatibility:** Ensured loads scripts as ES6 modules () to support statements.
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
// /js/login.js
|
|
import { saveAuthData, clearAuthData } from './auth.js';
|
|
import { redirectToDefaultDashboard } from './navigation.js';
|
|
// api-helper.js가 ES6 모듈로 변환되면 import를 사용해야 합니다.
|
|
// import { login } from './api-helper.js';
|
|
|
|
document.getElementById('loginForm').addEventListener('submit', async function (e) {
|
|
e.preventDefault();
|
|
|
|
const username = document.getElementById('username').value;
|
|
const password = document.getElementById('password').value;
|
|
const errorDiv = document.getElementById('error');
|
|
|
|
const submitBtn = e.target.querySelector('button[type="submit"]');
|
|
const originalText = submitBtn.textContent;
|
|
|
|
// 로딩 상태 시작
|
|
submitBtn.disabled = true;
|
|
submitBtn.textContent = '로그인 중...';
|
|
errorDiv.style.display = 'none';
|
|
|
|
try {
|
|
// 현재는 window 객체를 통해 호출하지만, 향후 모듈화 필요
|
|
const result = await window.login(username, password);
|
|
|
|
if (result.success && result.data && result.data.token) {
|
|
// auth.js에서 가져온 함수로 인증 정보 저장
|
|
saveAuthData(result.data.token, result.data.user);
|
|
|
|
// navigation.js를 통해 리디렉션
|
|
redirectToDefaultDashboard(result.data.redirectUrl);
|
|
|
|
} else {
|
|
// api-helper가 에러를 throw하므로 이 블록은 실행될 가능성이 낮음
|
|
clearAuthData();
|
|
errorDiv.textContent = result.error || '로그인에 실패했습니다.';
|
|
errorDiv.style.display = 'block';
|
|
}
|
|
} catch (err) {
|
|
console.error('로그인 오류:', err);
|
|
clearAuthData();
|
|
errorDiv.textContent = err.message || '서버 연결에 실패했습니다.';
|
|
errorDiv.style.display = 'block';
|
|
} finally {
|
|
// 로딩 상태 해제
|
|
submitBtn.disabled = false;
|
|
submitBtn.textContent = originalText;
|
|
}
|
|
}); |