Merge branch 'feature/20251219_zy' into develop_web
This commit is contained in:
@@ -57,20 +57,47 @@ export const useMenu = create<MenuState>((set, get) => ({
|
||||
const { allMenus } = get()
|
||||
const menus = allMenus[source] || []
|
||||
let result: MenuItem[] = []
|
||||
const matchedMenu: MenuItem | undefined = menus.find(menu => menu.path === paths[paths.length - 1] || `${menu.id}` === paths[1]);
|
||||
|
||||
if (matchedMenu) {
|
||||
let matchedSubMenu: MenuItem | undefined = undefined;
|
||||
if (paths.length > 1 && matchedMenu?.subs?.length) {
|
||||
matchedSubMenu = matchedMenu.subs.find(menu => menu.path === paths[0]);
|
||||
|
||||
console.log('updateBreadcrumbs paths:', paths);
|
||||
|
||||
if (paths.length === 3) {
|
||||
// 三级菜单:[subSubPath, subId, menuId]
|
||||
const menuId = paths[2];
|
||||
const subId = paths[1];
|
||||
const subSubPath = paths[0];
|
||||
|
||||
const matchedMenu = menus.find(menu => `${menu.id}` === menuId);
|
||||
if (matchedMenu && matchedMenu.subs) {
|
||||
const matchedSub = matchedMenu.subs.find(sub => `${sub.id}` === subId);
|
||||
if (matchedSub && matchedSub.subs) {
|
||||
const matchedSubSub = matchedSub.subs.find(subSub => subSub.path === subSubPath);
|
||||
if (matchedSubSub) {
|
||||
result = [
|
||||
{ ...matchedMenu, subs: null },
|
||||
{ ...matchedSub, subs: null },
|
||||
{ ...matchedSubSub, subs: null }
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
result = [
|
||||
{ ...matchedMenu, subs: null },
|
||||
matchedSubMenu
|
||||
].filter(item => item !== undefined) as MenuItem[]
|
||||
} else {
|
||||
result = [] as MenuItem[]
|
||||
// 原有逻辑处理一级和二级菜单
|
||||
const matchedMenu: MenuItem | undefined = menus.find(menu => menu.path === paths[paths.length - 1] || `${menu.id}` === paths[1]);
|
||||
|
||||
if (matchedMenu) {
|
||||
let matchedSubMenu: MenuItem | undefined = undefined;
|
||||
if (paths.length > 1 && matchedMenu?.subs?.length) {
|
||||
matchedSubMenu = matchedMenu.subs.find(menu => menu.path === paths[0]);
|
||||
}
|
||||
result = [
|
||||
{ ...matchedMenu, subs: null },
|
||||
matchedSubMenu
|
||||
].filter(item => item !== undefined) as MenuItem[]
|
||||
} else {
|
||||
result = [] as MenuItem[]
|
||||
}
|
||||
}
|
||||
|
||||
const allBreadcrumbs = { ...get().allBreadcrumbs, [source]: result }
|
||||
set({ allBreadcrumbs })
|
||||
localStorage.setItem('breadcrumbs', JSON.stringify(allBreadcrumbs))
|
||||
|
||||
Reference in New Issue
Block a user