feat(web-ui): Refactor web-ui for improved maintainability and modularity

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.
This commit is contained in:
Hyungi Ahn
2026-01-06 15:54:49 +09:00
parent 48fff7df64
commit b4037c9395
8 changed files with 223 additions and 133 deletions

View File

@@ -1,16 +1,8 @@
// /js/login.js
// ES6 모듈 의존성 제거 - 브라우저 호환성 개선
// 인증 데이터 저장 함수 (직접 구현)
function saveAuthData(token, user) {
localStorage.setItem('token', token);
localStorage.setItem('user', JSON.stringify(user));
}
function clearAuthData() {
localStorage.removeItem('token');
localStorage.removeItem('user');
}
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();
@@ -28,27 +20,18 @@ document.getElementById('loginForm').addEventListener('submit', async function (
errorDiv.style.display = 'none';
try {
// API 헬퍼를 통해 로그인 요청 (window 객체에서 가져오기)
// 현재는 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);
// 백엔드가 지정한 URL로 리디렉션
const redirectUrl = result.data.redirectUrl || '/pages/dashboard/user.html'; // 혹시 모를 예외처리
// 부드러운 화면 전환 효과
document.body.style.transition = 'opacity 0.3s ease-out';
document.body.style.opacity = '0';
setTimeout(() => {
window.location.href = redirectUrl;
}, 300);
// navigation.js를 통해 리디렉션
redirectToDefaultDashboard(result.data.redirectUrl);
} else {
// 이 케이스는 api-helper에서 throw new Error()로 처리되어 catch 블록으로 바로 이동합니다.
// 하지만, 만약의 경우를 대비해 방어 코드를 남겨둡니다.
// api-helper가 에러를 throw하므로 이 블록은 실행될 가능성이 낮음
clearAuthData();
errorDiv.textContent = result.error || '로그인에 실패했습니다.';
errorDiv.style.display = 'block';
@@ -56,7 +39,6 @@ document.getElementById('loginForm').addEventListener('submit', async function (
} catch (err) {
console.error('로그인 오류:', err);
clearAuthData();
// api-helper에서 보낸 에러 메시지를 표시
errorDiv.textContent = err.message || '서버 연결에 실패했습니다.';
errorDiv.style.display = 'block';
} finally {