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/components/TopNav/index.vue |  103 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 87 insertions(+), 16 deletions(-)

diff --git a/zhitan-vue/src/components/TopNav/index.vue b/zhitan-vue/src/components/TopNav/index.vue
index 7c42971..774132d 100644
--- a/zhitan-vue/src/components/TopNav/index.vue
+++ b/zhitan-vue/src/components/TopNav/index.vue
@@ -135,6 +135,28 @@
   setTimeout(updateScrollButtons, 300);
 }
 
+/**
+ * 鏌ユ壘鏈�娣卞眰鐨勫瓙鑿滃崟锛堝彾瀛愯妭鐐癸級
+ * 閫掑綊鏌ユ壘绗竴涓病鏈塩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 handleSelect(key, keyPath) {
   currentIndex.value = key;
   const route = routers.value.find(item => item.path === key);
@@ -145,23 +167,76 @@
     return;
   } 
   
-  if (key === '/index' || key === '/') {
-    // 棣栭〉鏃舵樉绀烘姌鍙犵殑渚ц竟鏍忥紝鑰屼笉鏄殣钘�
-    router.push({ path: key });
-    appStore.showCollapsedSidebar();
-    return;
-  } 
+ 
   
   // 妫�鏌ユ槸鍚︽湁瀛愯矾鐢�
   if (route && route.children && route.children.length > 0) {
     // 鏈夊瓙璺敱锛屾樉绀轰晶杈规爮
     activeRoutes(key);
-    const firstChild = route.children[0];
-    const path = firstChild.path.startsWith('/') ? firstChild.path : `${key}/${firstChild.path}`;
-    if (firstChild.query) {
-      router.push({ path, query: firstChild.query });
+    
+    // 鎸夌収姝g‘鐨勮矾寰勬瀯寤哄眰绾э紝杩欓噷鏄壒娈婂鐞�
+    let targetPath = key; // 浠庡綋鍓嶇偣鍑荤殑鑿滃崟璺緞寮�濮�
+    let targetQuery = null;
+    let currentNode = route;
+    let pathSegments = [];
+    
+    // 褰撳墠璺緞鏄涓�娈�
+    pathSegments.push(currentNode.path);
+    
+    // 閫愬眰娣诲姞瀛愯矾寰�
+    while (currentNode.children && currentNode.children.length > 0) {
+      const firstChild = currentNode.children.find(child => !child.hidden);
+      if (!firstChild) break;
+      
+      // 璺宠繃ParentView绫诲瀷鐨勪腑闂磋妭鐐癸紝鐩存帴浣跨敤鍏跺瓙鑺傜偣鐨刾ath
+      if (firstChild.component === 'ParentView' || firstChild.component.name === 'ParentView') {
+        currentNode = firstChild;
+        pathSegments.push(firstChild.path);
+        continue;
+      }
+      
+      // 鏅�氳妭鐐瑰鐞�
+      currentNode = firstChild;
+      // 濡傛灉璺緞涓嶆槸浠�/寮�澶达紝鍒欐坊鍔犲埌璺緞鐗囨涓�
+      if (!firstChild.path.startsWith('/')) {
+        pathSegments.push(firstChild.path);
+      } else {
+        // 濡傛灉鏄粷瀵硅矾寰勶紝鍒欐浛鎹箣鍓嶆墍鏈夎矾寰�
+        pathSegments = [firstChild.path];
+      }
+      
+      targetQuery = firstChild.query;
+      
+      // 濡傛灉鍒拌揪鍙跺瓙鑺傜偣锛堟病鏈夊瓙鑺傜偣锛夛紝鍒欑粨鏉熸煡鎵�
+      if (!firstChild.children || firstChild.children.length === 0) {
+        break;
+      }
+    }
+    
+    // 鏋勫缓鏈�缁堣矾寰�
+    if (pathSegments.length > 0) {
+      // 濡傛灉绗竴娈典笉鏄互/寮�澶达紝娣诲姞/
+      if (!pathSegments[0].startsWith('/')) {
+        pathSegments[0] = '/' + pathSegments[0];
+      }
+      
+      // 缁勫悎璺緞 - 鎶婃暟缁勪腑鎵�鏈夎矾寰勬嫾鎺ヨ捣鏉ワ紝濡傛灉鏌愭鍖呭惈瀹屾暣璺緞锛堜互/寮�澶达級鍒欎粠璇ユ閲嶆柊寮�濮�
+      targetPath = pathSegments.reduce((fullPath, segment, index) => {
+        if (segment.startsWith('/')) {
+          return segment;
+        } else if (index === 0) {
+          return segment;
+        } else {
+          return `${fullPath}/${segment}`;
+        }
+      });
+    }
+    
+    // 瀵艰埅鍒扮洰鏍囪矾鐢�
+    if (targetQuery) {
+      router.push({ path: targetPath, query: targetQuery });
     } else {
-      router.push({ path });
+      router.push({ path: targetPath });
     }
   } else {
     // 娌℃湁瀛愯矾鐢憋紝闅愯棌渚ц竟鏍�
@@ -178,11 +253,7 @@
 
 function activeRoutes(key) {
   let routes = [];
-  if (key === '/index' || key === '/') {
-    // 棣栭〉鏃舵樉绀烘姌鍙犵殑渚ц竟鏍忥紝鑰屼笉鏄殣钘�
-    appStore.showCollapsedSidebar();
-    return [];
-  }
+ 
   
   // 鏌ユ壘鍖归厤鐨勮矾鐢�
   if (childrenMenus.value && childrenMenus.value.length > 0) {

--
Gitblit v1.9.3