
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
import store from "./AppStore";
import uploadProgressStore from '@/resources/js/uploadProgressStore';
import { createWebHistory, createRouter } from "vue-router";
import { updateStatsByMenuId } from "../../resources/api/main";
// 공통
import Main from "./main/Main.vue";
import TotalSearch from "./main/TotalSearch.vue";
// 회원관리
import Login from "./login/Login.vue";
import MyInfo from "./user/MyInfo.vue";
import MemberManagement from "./member/MemberManagement.vue";
// 기록물 - 사진
import PicHistorySearch from "./bbsDcryPhoto/PicHistorySearch.vue";
import PicHistoryInsert from "./bbsDcryPhoto/PicHistoryInsert.vue";
import PicHistoryDetail from "./bbsDcryPhoto/PicHistoryDetail.vue";
// 기록물 - 영상
import VideoHistoryInsert from "./bbsDcryVideo/VideoHistoryInsert.vue";
import VideoHistoryDetail from "./bbsDcryVideo/VideoHistoryDetail.vue";
import VideoHistorySearch from "./bbsDcryVideo/VideoHistorySearch.vue";
// 미디어 영상
import MediaVideoInsert from "./bbsMediaVido/MediaVideoInsert.vue";
import MediaVideoDetail from "./bbsMediaVido/MediaVideoDetail.vue";
import MediaVideoSearch from "./bbsMediaVido/MediaVideoSearch.vue";
// 스크랩 자료
import NewsReleaseDetail from "./bbsNesDta/NewsReleaseDetail.vue";
import NewsReleaseInsert from "./bbsNesDta/NewsReleaseInsert.vue";
import NewsReleaseSearch from "./bbsNesDta/NewsReleaseSearch.vue";
// 카테고리 관리
import CategoryManagement from "./ctgry/CategoryManagement.vue";
// 메뉴 ID 매핑
const pathToMenuIdMap = {
'/PicHistorySearch.page': 'MENU_00000002',
'/VideoHistorySearch.page': 'MENU_00000003',
'/MediaVideoSearch.page': 'MENU_00000005',
'/NewsReleaseSearch.page': 'MENU_00000006',
'/MemberManagement.page': 'MENU_00000007',
'/CategoryManagement.page': 'MENU_00000008'
};
const routes = [
// 공통
{
path: "/", name: "MainPage", component: Main,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/TotalSearch.page", name: "TotalSearch", component: TotalSearch,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
// 회원관리
{
path: "/Login.page", name: "Login", component: Login,
meta: { requiresAuth: false, }
},
{
path: "/MyInfo.page", name: "MyInfo", component: MyInfo,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/MemberManagement.page", name: "MemberManagement", component: MemberManagement,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN'] }
},
// 기록물 - 사진
{
path: "/PicHistorySearch.page", name: "PicHistorySearch", component: PicHistorySearch,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/PicHistoryInsert.page", name: "PicHistoryInsert", component: PicHistoryInsert,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/PicHistoryDetail.page", name: "PicHistoryDetail", component: PicHistoryDetail,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
// 기록물 - 영상
{
path: "/VideoHistorySearch.page", name: "VideoHistorySearch", component: VideoHistorySearch,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/VideoHistoryInsert.page", name: "VideoHistoryInsert", component: VideoHistoryInsert,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/VideoHistoryDetail.page", name: "VideoHistoryDetail", component: VideoHistoryDetail,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
// 미디어 영상
{
path: "/MediaVideoSearch.page", name: "MediaVideoSearch", component: MediaVideoSearch,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/MediaVideoInsert.page", name: "MediaVideoInsert", component: MediaVideoInsert,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/MediaVideoDetail.page", name: "MediaVideoDetail", component: MediaVideoDetail,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
// 스크랩 자료
{
path: "/NewsReleaseSearch.page", name: "NewsReleaseSearch", component: NewsReleaseSearch,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/NewsReleaseInsert.page", name: "NewsReleaseInsert", component: NewsReleaseInsert,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
{
path: "/NewsReleaseDetail.page", name: "NewsReleaseDetail", component: NewsReleaseDetail,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN', 'ROLE_USER'] }
},
// 카테고리 관리
{
path: "/CategoryManagement.page", name: "CategoryManagement", component: CategoryManagement,
meta: { requiresAuth: true, roles: ['ROLE_ADMIN'] }
},
];
const AppRouter = createRouter({
history: createWebHistory(),
routes,
scrollBehavior() {
return { top: 0 }
},
});
AppRouter.beforeEach(async (to, from, next) => {
// 인증 필요 여부 확인
const requiresAuth = to.matched.some(record => record.meta.requiresAuth !== false);
// 로그인 여부
const isLoggedIn = !!store.state.authorization && !!store.state.userId;
// 로그인이 필요한데 로그인이 안되어 있는 경우
if (requiresAuth && !isLoggedIn) {
alert('로그인이 필요합니다.');
return next('/Login.page');
}
// 이미 로그인했는데 로그인 페이지로 가려는 경우
if (isLoggedIn && to.path === '/Login.page') {
return next('/');
}
// 권한 체크
if (isLoggedIn && to.meta.roles) {
const userRole = store.state.roles?.[0]?.authority;
if (!userRole || !to.meta.roles.includes(userRole)) {
alert('접근 권한이 없습니다.');
return next(from.path);
}
}
// 메뉴 통계 업데이트
const menuId = pathToMenuIdMap[to.path];
if (menuId) {
try {
await updateStatsByMenuId(menuId);
} catch (error) {
console.error(`메뉴 통계 업데이트 실패: ${menuId}`, error);
}
}
// 모든 페이지 이동 시 업로드 상태 초기화
uploadProgressStore.resetState();
next();
});
export default AppRouter;