하석형 하석형 04-16
250416 하석형 새로고침 시 좌측 메뉴에 현재 페이지 표시
@e6e286ff7e365159141a8330f35dc5e74864eb1b
client/views/layout/AdminMenu.vue
--- client/views/layout/AdminMenu.vue
+++ client/views/layout/AdminMenu.vue
@@ -54,13 +54,20 @@
     },
     created() {
         this.findAll();
-        this.menuCheck();
+        // this.menuCheck();
     },
     methods: {
+        // 새로고침 시 메뉴 체크
         menuCheck() {
-            const menu = store.state.menu;
+            let menu = store.state.menu;
             if (menu) {
-                this.checkMenu = menu.menuId;
+                // this.checkMenu = menu.menuId;
+                this.activeMenus = this.getParentMenus(menu);
+                for (const mu of this.activeMenus) {
+                    if (mu.childList && mu.childList.length > 0) {
+                        mu.isOpen = true; // 하위 메뉴가 있을 시 메뉴 펼치기
+                    }
+                }
             }
         },
         async findAll() {
@@ -85,8 +92,6 @@
 
                     // 전체 메뉴 트리 store에 저장
                     this.$store.commit('setMenuList', this.menuList);
-
-                    console.log("menulist",this.menuList)
                 }
             } catch (error) {
                 alert('에러가 발생했습니다.\n관리자에게 문의하세요.');
@@ -125,24 +130,28 @@
         },
 
         isActive(menuId) {
-            return this.activeMenus.includes(menuId);
+            // return this.activeMenus.includes(menuId);
+            return this.activeMenus.some(menu => menu.menuId === menuId);
         },
 
         getParentMenus(menu) {
             let parents = [];
             while (menu) {
-                parents.push(menu.menuId);
+                // parents.push(menu.menuId);
+                parents.push(menu);
                 menu = this.findParent(menu);
             }
             return parents;
         },
         findParent(menu) {
             for (const parent of this.menuList) {
-                if (parent.childList && parent.childList.includes(menu)) {
-                    return parent;
+                if (parent.childList?.some(child => child.menuId === menu.menuId)) {
+                // if (parent.childList && parent.childList.includes(menu)) {
+                return parent;
                 }
                 for (const child of parent.childList || []) {
-                    if (child.childList && child.childList.includes(menu)) {
+                    if (child.childList?.some(grand => grand.menuId === menu.menuId)) {
+                    // if (child.childList && child.childList.includes(menu)) {
                         return child;
                     }
                 }
@@ -172,11 +181,19 @@
     watch: {
         // 나중에 네비게이션 가드에서 form 받을 수 있으면 form adm/main으로 갈때 sotre.state값0로 바꿔주기
         $route(to) {
-        this.currentPath = to.path;
+            this.currentPath = to.path;
         },
         "$store.state.mbrNm"(newVal) {
             this.mbrNm = newVal;
         },
+        '$store.state.menuList': {
+            immediate: true,
+            handler(val) {
+                if (val && val.length > 0) {
+                    this.menuCheck();
+                }
+            }
+        }
     }
 };
 </script>
Add a comment
List