From 5d36e1f987ef21e44ded2e8a1d06c28094ec1e76 Mon Sep 17 00:00:00 2001 From: baoshiwei <baoshiwei@shlanbao.cn> Date: 星期六, 19 四月 2025 12:39:47 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- zhitan-vue/src/store/modules/permission.js | 64 ++++++++++++++++++++++++++++++-- 1 files changed, 60 insertions(+), 4 deletions(-) diff --git a/zhitan-vue/src/store/modules/permission.js b/zhitan-vue/src/store/modules/permission.js index 958fe63..5613f1c 100644 --- a/zhitan-vue/src/store/modules/permission.js +++ b/zhitan-vue/src/store/modules/permission.js @@ -56,8 +56,27 @@ }) // 閬嶅巻鍚庡彴浼犳潵鐨勮矾鐢卞瓧绗︿覆锛岃浆鎹负缁勪欢瀵硅薄 -function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) { +function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false, parentRoute = null) { return asyncRouterMap.filter(route => { + // 涓嶅啀杩囨护鎺夐椤电湅鏉跨浉鍏宠矾鐢� + /* + // 杩囨护鎺夐椤电湅鏉跨浉鍏宠矾鐢� + if (route.name === 'Index' && route.meta && route.meta.title === '棣栭〉鐪嬫澘') { + return false; + } + + // 濡傛灉鏄椤电湅鏉跨殑瀛愯彍鍗曪紝涔熻繃婊ゆ帀 + if (route.path === '/index' || route.path === 'index' || + (route.meta && route.meta.title === '棣栭〉鐪嬫澘')) { + return false; + } + */ + + // 璁剧疆鐖惰矾鐢卞紩鐢� + if (parentRoute) { + route.parent = parentRoute; + } + if (type && route.children) { route.children = filterChildren(route.children) } @@ -73,8 +92,17 @@ route.component = loadView(route.component) } } + // 澶勭悊 query 鍙傛暟锛屽皢瀛楃涓茶浆鎹负瀵硅薄 + if (route.query && typeof route.query === 'string') { + try { + route.query = JSON.parse(route.query); + } catch (error) { + console.error('Error parsing query string:', route.query, error); + } + } if (route.children != null && route.children && route.children.length) { - route.children = filterAsyncRouter(route.children, route, type) + // 灏嗗綋鍓嶈矾鐢变綔涓虹埗璺敱浼犻�掔粰瀛愯矾鐢� + route.children = filterAsyncRouter(route.children, route, type, route) } else { delete route['children'] delete route['redirect'] @@ -89,7 +117,21 @@ if (el.children && el.children.length) { if (el.component === 'ParentView' && !lastRouter) { el.children.forEach(c => { - c.path = el.path + '/' + c.path + // 璁剧疆鐖惰矾鐢卞紩鐢� + c.parent = el; + + // 纭繚璺緞鏍煎紡姝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 @@ -100,7 +142,21 @@ } } if (lastRouter) { - el.path = lastRouter.path + '/' + el.path + // 璁剧疆鐖惰矾鐢卞紩鐢� + el.parent = lastRouter; + + // 纭繚璺緞鏍煎紡姝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