feat(web): Home page ui upgrade
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-02 16:33:34
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-02-02 16:33:34
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-02-04 10:31:14
|
||||
*/
|
||||
/**
|
||||
* Menu Store
|
||||
@@ -42,6 +42,7 @@ export interface MenuItem {
|
||||
master?: string | null;
|
||||
disposable?: boolean;
|
||||
appSystem?: string | null;
|
||||
type?: 'group' | string;
|
||||
subs?: MenuItem[] | null;
|
||||
onClick?: (e?: React.MouseEvent) => void | boolean;
|
||||
}
|
||||
@@ -89,20 +90,27 @@ export const useMenu = create<MenuState>((set, get) => ({
|
||||
const { allMenus } = get()
|
||||
const menus = allMenus[source] || []
|
||||
let result: MenuItem[] = []
|
||||
|
||||
console.log('updateBreadcrumbs paths:', paths);
|
||||
|
||||
|
||||
/** Flatten group menus so top-level items are always real menu entries */
|
||||
const flatMenus = menus.flatMap(m => m.type === 'group' ? (m.subs || []) : [m]);
|
||||
|
||||
const findById = (list: MenuItem[], id: string) => list.find(m => `${m.id}` === id);
|
||||
/** Find menu by id in both original menus and flatMenus (handles group ids) */
|
||||
const findMenuById = (id: string) => findById(menus, id) || findById(flatMenus, id);
|
||||
const pathMatches = (pattern: string, path: string) => {
|
||||
const n = pattern[0] !== '/' ? '/' + pattern : pattern;
|
||||
if (n === path) return true;
|
||||
if (n.includes(':')) return new RegExp('^' + n.replace(/:[\w-]+/g, '[^/]+') + '$').test(path);
|
||||
return false;
|
||||
};
|
||||
|
||||
if (paths.length === 3) {
|
||||
/** Three-level menu: [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);
|
||||
/** Three-level: [subSubPath, subId, menuId] */
|
||||
const matchedMenu = findMenuById(paths[2]);
|
||||
if (matchedMenu?.subs) {
|
||||
const matchedSub = findById(matchedMenu.subs, paths[1]);
|
||||
if (matchedSub?.subs) {
|
||||
const matchedSubSub = matchedSub.subs.find(s => s.path === paths[0] || pathMatches(s.path || '', paths[0]));
|
||||
if (matchedSubSub) {
|
||||
result = [
|
||||
{ ...matchedMenu, subs: null },
|
||||
@@ -113,23 +121,16 @@ export const useMenu = create<MenuState>((set, get) => ({
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/** Original logic for one-level and two-level menus */
|
||||
const matchedMenu: MenuItem | undefined = menus.find(menu => menu.path === paths[paths.length - 1] || `${menu.id}` === paths[1]);
|
||||
|
||||
const matchedMenu = flatMenus.find(m => m.path === paths[0] || `${m.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]);
|
||||
let matchedSubMenu: MenuItem | undefined;
|
||||
if (paths.length > 1 && matchedMenu.subs?.length) {
|
||||
matchedSubMenu = matchedMenu.subs.find(m => m.path === paths[0]);
|
||||
}
|
||||
result = [
|
||||
{ ...matchedMenu, subs: null },
|
||||
matchedSubMenu
|
||||
].filter(item => item !== undefined) as MenuItem[]
|
||||
} else {
|
||||
result = [] as MenuItem[]
|
||||
result = [{ ...matchedMenu, subs: null }, matchedSubMenu].filter(Boolean) as MenuItem[];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const allBreadcrumbs = { ...get().allBreadcrumbs, [source]: result }
|
||||
set({ allBreadcrumbs })
|
||||
localStorage.setItem('breadcrumbs', JSON.stringify(allBreadcrumbs))
|
||||
|
||||
Reference in New Issue
Block a user