From 725da078afc3398f49f1efdc25bc82b9ec1dac35 Mon Sep 17 00:00:00 2001
From: DYL0109 <dn18191638832@163.com>
Date: 星期三, 16 四月 2025 19:27:30 +0800
Subject: [PATCH] Merge pull request #64 from zhitan-cloud/develop1.0

---
 zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue |  224 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 222 insertions(+), 2 deletions(-)

diff --git a/zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue b/zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue
index 73346ce..8e38476 100644
--- a/zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue
+++ b/zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue
@@ -9,7 +9,7 @@
       </app-link>
     </template>
 
-    <el-sub-menu v-else ref="subMenu" :index="resolvePath(item.path)" teleported>
+    <el-sub-menu v-else ref="subMenu" :index="resolvePath(item.path)" teleported @click="handleSubMenuClick">
       <template v-if="item.meta" #title>
         <svg-icon :icon-class="item.meta && item.meta.icon" />
         <span class="menu-title" :title="hasTitle(item.meta.title)">{{ item.meta.title }}</span>
@@ -31,6 +31,9 @@
 import { isExternal } from '@/utils/validate'
 import AppLink from './Link'
 import { getNormalPath } from '@/utils/ruoyi'
+import { useRouter } from 'vue-router'
+
+const router = useRouter();
 
 const props = defineProps({
   // route object
@@ -50,6 +53,204 @@
 
 const onlyOneChild = ref({});
 
+/**
+ * 鏌ユ壘鏈�娣卞眰鐨勫瓙鑿滃崟锛堝彾瀛愯妭鐐癸級
+ * 閫掑綊鏌ユ壘绗竴涓病鏈塩hildren鐨勫瓙鑿滃崟
+ */
+function findDeepestLeafMenu(route) {
+  if (!route) return null;
+  
+  // 濡傛灉娌℃湁瀛愯彍鍗曟垨瀛愯彍鍗曚负绌猴紝鍒欒繑鍥炲綋鍓嶈矾鐢�
+  if (!route.children || route.children.length === 0) {
+    return route;
+  }
+  
+  // 鎵惧埌绗竴涓潪闅愯棌鐨勫瓙鑿滃崟
+  const firstVisibleChild = route.children.find(child => !child.hidden);
+  if (!firstVisibleChild) {
+    return route; // 濡傛灉鎵�鏈夊瓙鑿滃崟閮芥槸闅愯棌鐨勶紝杩斿洖褰撳墠璺敱
+  }
+  
+  // 閫掑綊鏌ユ壘杩欎釜瀛愯彍鍗曠殑鏈�娣卞眰瀛愯彍鍗�
+  return findDeepestLeafMenu(firstVisibleChild);
+}
+
+// 澶勭悊瀛愯彍鍗曠偣鍑�
+function handleSubMenuClick(e) {
+  // 闃绘浜嬩欢鍐掓场
+  e.stopPropagation();
+  
+  // 濡傛灉鐐瑰嚮鐨勬槸瀛愯彍鍗曟爣棰橈紝鍒欒嚜鍔ㄥ鑸埌鏈�娣卞眰鐨勫瓙鑿滃崟
+  if (e.target.closest('.el-sub-menu__title')) {
+    // 鎸夌収姝g‘鐨勮矾寰勬瀯寤哄眰绾�
+    let currentNode = props.item;
+    
+    console.log('褰撳墠鐐瑰嚮鐨勮彍鍗曢」:', JSON.stringify(currentNode, null, 2));
+    console.log('basePath:', props.basePath);
+    
+    // 鑾峰彇绗竴涓彲瑙佸瓙鑿滃崟锛屽鏋滄病鏈夊彲瑙佸瓙鑿滃崟锛屼笉杩涜璺宠浆
+    if (!currentNode.children || currentNode.children.length === 0) {
+      return;
+    }
+    
+    const firstVisibleChild = currentNode.children.find(child => !child.hidden);
+    if (!firstVisibleChild) {
+      return;
+    }
+    
+    console.log('绗竴涓彲瑙佸瓙鑿滃崟:', JSON.stringify(firstVisibleChild, null, 2));
+    
+    // 鏃ュ織绠$悊绛変笁绾ц彍鍗曠壒娈婂鐞�
+    // 妫�鏌ユ槸鍚︽湁棰勫厛鍐欏叆鐨勫畬鏁磋矾寰勶紝濡傛灉鏈夊垯鐩存帴浣跨敤
+    if (firstVisibleChild.fullPath) {
+      console.log('浣跨敤棰勫厛璁剧疆鐨勫畬鏁磋矾寰�:', firstVisibleChild.fullPath);
+      router.push({ path: firstVisibleChild.fullPath });
+      return;
+    }
+    
+    // 鍒ゆ柇鏄惁鏄郴缁�/鏃ュ織绠$悊绫诲瀷鐨勪笁绾ц彍鍗曪紙渚嬪锛�/system/log/operlog锛�
+    // 杩欑鎯呭喌涓嬶紝鐩存帴璺宠浆鍒扮涓�涓瓙鑿滃崟鐨勫畬鏁磋矾寰�
+    if (firstVisibleChild.component === 'ParentView' || 
+        (typeof firstVisibleChild.component === 'object' && 
+         firstVisibleChild.component.name === 'ParentView')) {
+      console.log('妫�娴嬪埌ParentView缁勪欢锛屽鐞嗕笁绾ц彍鍗�');
+      
+      // 鏄湁涓夌骇鑿滃崟鐨勬儏鍐�
+      if (firstVisibleChild.children && firstVisibleChild.children.length > 0) {
+        const grandChild = firstVisibleChild.children.find(child => !child.hidden);
+        if (grandChild) {
+          console.log('鎵惧埌绗笁绾ц彍鍗�:', JSON.stringify(grandChild, null, 2));
+          
+          // 鍒ゆ柇鏄惁搴旇浣跨敤parentPath
+          if (firstVisibleChild.parentPath && grandChild.path.startsWith('/')) {
+            console.log('浣跨敤parentPath灞炴��:', firstVisibleChild.parentPath);
+            // 濡傛灉瀛愯彍鍗曟槸缁濆璺緞锛屼絾鏈塸arentPath锛屽垯搴旇浣跨敤parentPath浣滀负鍩虹
+            let fullPath = firstVisibleChild.parentPath;
+            if (!fullPath.startsWith('/')) {
+              fullPath = '/' + fullPath;
+            }
+            
+            // 绗簩绾ц矾寰勫熀浜庢牴璺緞
+            if (firstVisibleChild.path.startsWith('/')) {
+              // 绗簩绾у凡缁忔槸缁濆璺緞锛屾埅鍙栨渶鍚庨儴鍒�
+              const pathParts = firstVisibleChild.path.split('/');
+              const lastPart = pathParts[pathParts.length - 1];
+              fullPath = fullPath + '/' + lastPart;
+            } else {
+              fullPath = buildFullPath(fullPath, firstVisibleChild.path);
+            }
+            console.log('浜岀骇璺緞:', fullPath);
+            
+            // 绗笁绾ц矾寰勫熀浜庝簩绾ц矾寰�
+            if (grandChild.path.startsWith('/')) {
+              // 绗笁绾ф槸缁濆璺緞锛屾埅鍙栨渶鍚庨儴鍒�
+              const pathParts = grandChild.path.split('/');
+              const lastPart = pathParts[pathParts.length - 1];
+              fullPath = fullPath + '/' + lastPart;
+            } else {
+              fullPath = buildFullPath(fullPath, grandChild.path);
+            }
+            console.log('涓夌骇璺緞 (鏈�缁�):', fullPath);
+            
+            // 瀵艰埅鍒扮涓夌骇鑿滃崟
+            if (grandChild.query) {
+              router.push({ path: fullPath, query: grandChild.query });
+            } else {
+              router.push({ path: fullPath });
+            }
+            return;
+          }
+          
+          // 甯歌璺緞鏋勫缓
+          let fullPath;
+          
+          // 绗竴绾ц矾寰勫繀椤绘槸瀹屾暣鐨勶紙渚嬪/system锛�
+          if (currentNode.path.startsWith('/')) {
+            fullPath = currentNode.path;
+          } else {
+            fullPath = '/' + currentNode.path;
+          }
+          console.log('涓�绾ц矾寰�:', fullPath);
+          
+          // 绗簩绾ц矾寰勫繀椤诲熀浜庣涓�绾ц矾寰勶紙渚嬪/system/log锛�
+          fullPath = buildFullPath(fullPath, firstVisibleChild.path);
+          console.log('浜岀骇璺緞:', fullPath);
+          
+          // 绗笁绾ц矾寰勫繀椤诲熀浜庝簩绾ц矾寰勶紙渚嬪/system/log/operlog锛�
+          fullPath = buildFullPath(fullPath, grandChild.path);
+          console.log('涓夌骇璺緞 (鏈�缁�):', fullPath);
+          
+          // 瀵艰埅鍒扮涓夌骇鑿滃崟
+          if (grandChild.query) {
+            console.log('璺宠浆鍒�:', fullPath, '甯﹀弬鏁�:', grandChild.query);
+            router.push({ path: fullPath, query: grandChild.query });
+          } else {
+            console.log('璺宠浆鍒�:', fullPath);
+            router.push({ path: fullPath });
+          }
+          return;
+        }
+      }
+    }
+    
+    console.log('澶勭悊鏍囧噯浜岀骇鑿滃崟');
+    
+    // 妫�鏌ユ槸鍚﹂渶瑕佷娇鐢╬arentPath
+    if (firstVisibleChild.parentPath && firstVisibleChild.path.startsWith('/')) {
+      console.log('浣跨敤parentPath灞炴��:', firstVisibleChild.parentPath);
+      // 濡傛灉瀛愯彍鍗曟槸缁濆璺緞锛屼絾鏈塸arentPath锛屽垯搴旇浣跨敤parentPath浣滀负鍩虹
+      let fullPath = firstVisibleChild.parentPath;
+      if (!fullPath.startsWith('/')) {
+        fullPath = '/' + fullPath;
+      }
+      
+      // 鏋勫缓瀹屾暣璺緞
+      if (firstVisibleChild.path.startsWith('/')) {
+        // 鎴彇瀛愯矾寰勭殑鏈�鍚庨儴鍒�
+        const pathParts = firstVisibleChild.path.split('/');
+        const lastPart = pathParts[pathParts.length - 1];
+        fullPath = fullPath + '/' + lastPart;
+      } else {
+        fullPath = buildFullPath(fullPath, firstVisibleChild.path);
+      }
+      console.log('鏋勫缓鐨勬渶缁堣矾寰�:', fullPath);
+      
+      // 瀵艰埅鍒扮洰鏍囪矾鐢�
+      if (firstVisibleChild.query) {
+        router.push({ path: fullPath, query: firstVisibleChild.query });
+      } else {
+        router.push({ path: fullPath });
+      }
+      return;
+    }
+    
+    // 鏍囧噯鐨勪簩绾ц彍鍗曞鐞�
+    // 鏋勫缓姝g‘鐨勮矾寰�
+    let fullPath;
+    
+    // 澶勭悊绗竴绾ц矾寰勶紙渚嬪/system锛�- 蹇呴』鏄畬鏁寸殑璺緞
+    if (currentNode.path.startsWith('/')) {
+      fullPath = currentNode.path;
+    } else {
+      fullPath = '/' + currentNode.path;
+    }
+    console.log('涓�绾ц矾寰�:', fullPath);
+    
+    // 澶勭悊绗簩绾ц矾寰勶紙渚嬪/system/user锛�- 蹇呴』鍩轰簬绗竴绾ц矾寰�
+    fullPath = buildFullPath(fullPath, firstVisibleChild.path);
+    console.log('浜岀骇璺緞 (鏈�缁�):', fullPath);
+    
+    // 瀵艰埅鍒扮洰鏍囪矾鐢�
+    if (firstVisibleChild.query) {
+      console.log('璺宠浆鍒�:', fullPath, '甯﹀弬鏁�:', firstVisibleChild.query);
+      router.push({ path: fullPath, query: firstVisibleChild.query });
+    } else {
+      console.log('璺宠浆鍒�:', fullPath);
+      router.push({ path: fullPath });
+    }
+  }
+}
+
 function hasOneShowingChild(children = [], parent) {
   if (!children) {
     children = [];
@@ -65,8 +266,13 @@
   })
 
   // When there is only one child router, the child router is displayed by default
-  if (showingChildren.length === 1) {
+  if (showingChildren.length === 1 && !showingChildren[0].children) {
     return true
+  }
+
+  // If the single child also has children, don't treat it as a single showing child
+  if (showingChildren.length === 1 && showingChildren[0].children && showingChildren[0].children.length > 0) {
+    return false
   }
 
   // Show parent if there are no child router to display
@@ -100,6 +306,20 @@
   return getNormalPath(props.basePath + '/' + routePath)
 }
 
+// 姝g‘鏋勫缓璺緞
+function buildFullPath(base, segment) {
+  // 濡傛灉segment鏄粷瀵硅矾寰勶紝鐩存帴杩斿洖
+  if (segment.startsWith('/')) {
+    return segment;
+  }
+  
+  // 纭繚base鏈夋纭殑寮�澶存枩鏉�
+  const normalizedBase = base.startsWith('/') ? base : '/' + base;
+  
+  // 鎷兼帴璺緞锛岄伩鍏嶅弻鏂滄潬
+  return normalizedBase.endsWith('/') ? normalizedBase + segment : normalizedBase + '/' + segment;
+}
+
 function hasTitle(title){
   if (title.length > 5) {
     return title;

--
Gitblit v1.9.3