From 7bc1c783bf4559ae121347114555964b06280bd0 Mon Sep 17 00:00:00 2001
From: birt <2499248221@qq.com>
Date: 星期一, 14 四月 2025 15:39:54 +0800
Subject: [PATCH] 123
---
zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue | 220 +++++++++++++++++++++++++++++++++----------
zhitan-vue/src/store/modules/permission.js | 26 ++++
zhitan-vue/src/permission.js | 16 ++
3 files changed, 206 insertions(+), 56 deletions(-)
diff --git a/zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue b/zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue
index 7b468d2..8e38476 100644
--- a/zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue
+++ b/zhitan-vue/src/layout/components/Sidebar/SidebarItem.vue
@@ -84,65 +84,169 @@
if (e.target.closest('.el-sub-menu__title')) {
// 鎸夌収姝g‘鐨勮矾寰勬瀯寤哄眰绾�
let currentNode = props.item;
- let pathSegments = [];
- // 棣栧厛娣诲姞褰撳墠鑺傜偣鐨勮矾寰�
- if (currentNode.path) {
- pathSegments.push(currentNode.path);
+ console.log('褰撳墠鐐瑰嚮鐨勮彍鍗曢」:', JSON.stringify(currentNode, null, 2));
+ console.log('basePath:', props.basePath);
+
+ // 鑾峰彇绗竴涓彲瑙佸瓙鑿滃崟锛屽鏋滄病鏈夊彲瑙佸瓙鑿滃崟锛屼笉杩涜璺宠浆
+ if (!currentNode.children || currentNode.children.length === 0) {
+ return;
}
- // 閫愬眰娣诲姞瀛愯矾寰�
- 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;
- }
+ const firstVisibleChild = currentNode.children.find(child => !child.hidden);
+ if (!firstVisibleChild) {
+ return;
}
- // 鏋勫缓鏈�缁堣矾寰�
- if (pathSegments.length > 0) {
- // 濡傛灉绗竴娈典笉鏄互/寮�澶达紝娣诲姞/
- if (!pathSegments[0].startsWith('/')) {
- pathSegments[0] = '/' + pathSegments[0];
- }
+ 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缁勪欢锛屽鐞嗕笁绾ц彍鍗�');
- // 缁勫悎璺緞
- const targetPath = pathSegments.reduce((fullPath, segment, index) => {
- if (segment.startsWith('/')) {
- return segment;
- } else if (index === 0) {
- return segment;
- } else {
- return `${fullPath}/${segment}`;
+ // 鏄湁涓夌骇鑿滃崟鐨勬儏鍐�
+ 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;
}
- });
-
- // 瀵艰埅鍒扮洰鏍囪矾鐢憋紝濡傛灉鏈夋煡璇㈠弬鏁板垯娣诲姞
- if (currentNode.query) {
- router.push({ path: targetPath, query: currentNode.query });
- } else {
- router.push({ path: targetPath });
}
+ }
+
+ 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 });
}
}
}
@@ -202,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;
diff --git a/zhitan-vue/src/permission.js b/zhitan-vue/src/permission.js
index 7fc2c80..3427d73 100644
--- a/zhitan-vue/src/permission.js
+++ b/zhitan-vue/src/permission.js
@@ -35,9 +35,16 @@
// 璺宠繃ParentView绫诲瀷鐨勪腑闂磋妭鐐�
if (firstChild.component === 'ParentView' ||
- (typeof firstChild.component === 'object' && firstChild.component.name === 'ParentView')) {
+ (typeof firstChild.component === 'object' &&
+ firstChild.component.name === 'ParentView')) {
currentNode = firstChild;
- pathSegments.push(firstChild.path);
+ // 濡傛灉璺緞涓嶆槸浠�/寮�澶达紝鍒欐坊鍔犲埌璺緞鐗囨涓�
+ if (!firstChild.path.startsWith('/')) {
+ pathSegments.push(firstChild.path);
+ } else {
+ // 濡傛灉鏄粷瀵硅矾寰勶紝鍒欐浛鎹箣鍓嶆墍鏈夎矾寰�
+ pathSegments = [firstChild.path];
+ }
continue;
}
@@ -72,7 +79,10 @@
} else if (index === 0) {
return segment;
} else {
- return `${fullPath}/${segment}`;
+ // 纭繚璺緞涔嬮棿涓嶄細鍑虹幇閲嶅鐨勬枩鏉�
+ const base = fullPath.endsWith('/') ? fullPath.slice(0, -1) : fullPath;
+ const part = segment.startsWith('/') ? segment : '/' + segment;
+ return `${base}${part}`;
}
});
}
diff --git a/zhitan-vue/src/store/modules/permission.js b/zhitan-vue/src/store/modules/permission.js
index 4eb8185..5613f1c 100644
--- a/zhitan-vue/src/store/modules/permission.js
+++ b/zhitan-vue/src/store/modules/permission.js
@@ -120,7 +120,18 @@
// 璁剧疆鐖惰矾鐢卞紩鐢�
c.parent = el;
- c.path = el.path + '/' + c.path
+ // 纭繚璺緞鏍煎紡姝g‘鎷兼帴
+ if (el.path) {
+ if (c.path.startsWith('/')) {
+ // 缁濆璺緞淇濇寔涓嶅彉
+ // 浣嗕篃璁剧疆鍘熷鐖惰矾寰勭敤浜庤彍鍗曞鑸�
+ c.parentPath = el.path;
+ } else {
+ // 鐩稿璺緞闇�瑕佹嫾鎺�
+ c.path = el.path.endsWith('/') ? el.path + c.path : el.path + '/' + c.path;
+ }
+ }
+
if (c.children && c.children.length) {
children = children.concat(filterChildren(c.children, c))
return
@@ -134,7 +145,18 @@
// 璁剧疆鐖惰矾鐢卞紩鐢�
el.parent = lastRouter;
- el.path = lastRouter.path + '/' + el.path
+ // 纭繚璺緞鏍煎紡姝g‘鎷兼帴
+ if (lastRouter.path) {
+ if (el.path.startsWith('/')) {
+ // 缁濆璺緞淇濇寔涓嶅彉
+ // 浣嗕篃璁剧疆鍘熷鐖惰矾寰勭敤浜庤彍鍗曞鑸�
+ el.parentPath = lastRouter.path;
+ } else {
+ // 鐩稿璺緞闇�瑕佹嫾鎺�
+ el.path = lastRouter.path.endsWith('/') ? lastRouter.path + el.path : lastRouter.path + '/' + el.path;
+ }
+ }
+
if (el.children && el.children.length) {
children = children.concat(filterChildren(el.children, el))
return
--
Gitblit v1.9.3