Merge branch 'feature/20251219_zy' into develop_web
This commit is contained in:
@@ -26,19 +26,6 @@
|
||||
"sort": 0,
|
||||
"subs": []
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"parent": 0,
|
||||
"code": "tool",
|
||||
"label": "工具管理",
|
||||
"i18nKey": "menu.toolManagement",
|
||||
"path": "/tool",
|
||||
"enable": true,
|
||||
"display": true,
|
||||
"level": 1,
|
||||
"sort": 1,
|
||||
"subs": []
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"parent": 0,
|
||||
@@ -251,15 +238,15 @@
|
||||
"sort": 0,
|
||||
"subs": [
|
||||
{
|
||||
"id": 81,
|
||||
"parent": 8,
|
||||
"code": "emotionDetail",
|
||||
"id": 811,
|
||||
"parent": 81,
|
||||
"code": "statementDetail",
|
||||
"label": "记忆详情",
|
||||
"i18nKey": "menu.emotionDetail",
|
||||
"path": "/user-memory/emotion/:id",
|
||||
"i18nKey": "menu.statementDetail",
|
||||
"path": "/statement/:id",
|
||||
"enable": true,
|
||||
"display": false,
|
||||
"level": 2,
|
||||
"level": 3,
|
||||
"sort": 0,
|
||||
"subs": null
|
||||
}
|
||||
|
||||
@@ -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