From 4745c48798fc7d967a7fd4416c10050d4f79fb98 Mon Sep 17 00:00:00 2001
From: birt <2499248221@qq.com>
Date: 星期日, 13 四月 2025 21:43:49 +0800
Subject: [PATCH] 123

---
 zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 104 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..7b468d2 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,100 @@
 
 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;
+    let pathSegments = [];
+    
+    // 棣栧厛娣诲姞褰撳墠鑺傜偣鐨勮矾寰�
+    if (currentNode.path) {
+      pathSegments.push(currentNode.path);
+    }
+    
+    // 閫愬眰娣诲姞瀛愯矾寰�
+    while (currentNode.children && currentNode.children.length > 0) {
+      const firstChild = currentNode.children.find(child => !child.hidden);
+      if (!firstChild) break;
+      
+      // 璺宠繃ParentView绫诲瀷鐨勪腑闂磋妭鐐�
+      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];
+      }
+      
+      // 濡傛灉鍒拌揪鍙跺瓙鑺傜偣锛屽垯缁撴潫鏌ユ壘
+      if (!firstChild.children || firstChild.children.length === 0) {
+        break;
+      }
+    }
+    
+    // 鏋勫缓鏈�缁堣矾寰�
+    if (pathSegments.length > 0) {
+      // 濡傛灉绗竴娈典笉鏄互/寮�澶达紝娣诲姞/
+      if (!pathSegments[0].startsWith('/')) {
+        pathSegments[0] = '/' + pathSegments[0];
+      }
+      
+      // 缁勫悎璺緞
+      const targetPath = pathSegments.reduce((fullPath, segment, index) => {
+        if (segment.startsWith('/')) {
+          return segment;
+        } else if (index === 0) {
+          return segment;
+        } else {
+          return `${fullPath}/${segment}`;
+        }
+      });
+      
+      // 瀵艰埅鍒扮洰鏍囪矾鐢憋紝濡傛灉鏈夋煡璇㈠弬鏁板垯娣诲姞
+      if (currentNode.query) {
+        router.push({ path: targetPath, query: currentNode.query });
+      } else {
+        router.push({ path: targetPath });
+      }
+    }
+  }
+}
+
 function hasOneShowingChild(children = [], parent) {
   if (!children) {
     children = [];
@@ -65,10 +162,15 @@
   })
 
   // 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
   if (showingChildren.length === 0) {
     onlyOneChild.value = { ...parent, path: '', noShowingChildren: true }

--
Gitblit v1.9.3