hmkim 03-28
250328 김혜민 관리자및사용자 페이지 breadcrumb 공통 수정
@2f392cae3579cb3a1416665873c5b2166af0bdbe
client/views/component/Breadcrumb/Breadcrumb.vue
--- client/views/component/Breadcrumb/Breadcrumb.vue
+++ client/views/component/Breadcrumb/Breadcrumb.vue
@@ -1,5 +1,5 @@
 <template>
-  <div>
+  <div v-if="breadcrumbList.length > 0">
     <span v-for="(crumb, index) in breadcrumbList" :key="index">
       {{ crumb.menuNm }}
       <span v-if="index < breadcrumbList.length - 1"> &gt; </span>
@@ -24,23 +24,56 @@
   },
   methods: {
     generateBreadcrumb() {
-      const fullMenuList = this.$store.state.menuList || []; // 전체 메뉴 트리
+      const menuState = this.$store.state;
       const currentPath = this.$route.path;
-      const findMenuPath = (menus, path, trail = []) => {
+
+      // 관리자: childList 기반
+      const findFromTree = (menus, path, trail = []) => {
         for (const menu of menus) {
           const newTrail = [...trail, menu];
           if (menu.routerUrl === path) return newTrail;
           if (menu.childList?.length) {
-            const found = findMenuPath(menu.childList, path, newTrail);
+            const found = findFromTree(menu.childList, path, newTrail);
             if (found) return found;
           }
         }
-        return null;  
+        return null;
       };
 
-      const breadcrumb = findMenuPath(fullMenuList, currentPath);
-      this.breadcrumbList = breadcrumb || [];
+      // 사용자: upMenuId 기반
+      const findFromFlat = (flatMenus, path) => {
+        const findCurrent = flatMenus.find(menu => menu.routerUrl === path);
+        if (!findCurrent) return [];
+
+        const buildTrail = (menu, trail = []) => {
+          const parent = flatMenus.find(m => m.menuId === menu.upMenuId);
+          if (parent) {
+            return buildTrail(parent, [parent, ...trail]);
+          }
+          return trail;
+        };
+
+        const trail = buildTrail(findCurrent);
+        return [...trail, findCurrent];
+      };
+
+      let breadcrumb = [];
+
+      // 구조 판단
+      if (menuState.menuList?.length) {
+        // 사용자용
+        const flatMenus = menuState.menuList.flatMap(menu =>
+          [menu, ...(menu.childList || [])]
+        );
+        breadcrumb = findFromFlat(flatMenus, currentPath);
+      } else if (menuState.menu?.childList?.length) {
+        // 관리자용
+        breadcrumb = findFromTree(menuState.menu.childList, currentPath);
+      }
+
+      this.breadcrumbList = breadcrumb;
     }
+
   },
 };
-</script>
+</script>
(파일 끝에 줄바꿈 문자 없음)
client/views/layout/UserMenu.vue
--- client/views/layout/UserMenu.vue
+++ client/views/layout/UserMenu.vue
@@ -152,8 +152,10 @@
         const res = await findBySysMenu(params);
         if (res.status == 200) {
           this.menuList = res.data.data.menuList;
-          this.fnMenuActive(this.$route.path);
+          // 전체 메뉴 트리 store에 저장
           this.$store.commit('setMenuList', this.menuList);
+          console.log('this.menuList', this.menuList);
+          this.fnMenuActive(this.$route.path);
         }
       } catch (error) {
         alert("에러가 발생했습니다.\n관리자에게 문의하세요");
client/views/pages/App.vue
--- client/views/pages/App.vue
+++ client/views/pages/App.vue
@@ -3,7 +3,7 @@
     <AdminHeader />
     <AdminMenu />
     <main class="main-wrap">
-      <Breadcrumb />
+      <Breadcrumb v-if="$route.path !== '/adm/main.page' && $route.path !== '/main.page'" />
         <div :class="{'content-wrap': true, 'main': this.$route.path === '/adm/main.page'}">
           <router-view />
         </div>
@@ -11,8 +11,8 @@
   </div>
   <div v-else v-cloak class="user-wrap relative">
     <UserHeader v-if="path != '/login.page'"/>
-    <Breadcrumb />
     <main class="main-wrap">
+      <Breadcrumb v-if="$route.path !== '/adm/main.page' && $route.path !== '/main.page'" />
       <router-view />
     </main>
   </div>
Add a comment
List