// 菜单树过滤 (展示的? ) export function filterMenu(menuList) { return menuList // 过滤不是4级的 123 为菜单 .filter(menu => menu.menuType !== 4) .map(menu => ({ ...menu, children: menu.children ? filterMenu(menu.children) : [] })) .sort((a, b) => a.id - b.id); // 按 id 升序 } // 过滤 只获得第三级的菜单 export function filterFirstMenu(menuList) { return menuList .map(menu => ({ ...menu, children: menu.children ? filterMenu(menu.children) : [] })) .sort((a, b) => a.id - b.id); // 按 id 升序 } // 辅助函数:查找第一个可访问的菜单项 export function findFirstThirdLevelMenu(menuList) { if (!menuList || menuList.length === 0) return null; for (const menu of menuList) { // 先检查当前菜单是否为三级菜单 if (menu.menuType === 3) { return menu; } // 若不是,递归查找其子菜单(无论当前菜单是几级,都深入子菜单找三级) const childResult = findFirstThirdLevelMenu(menu.children); if (childResult) { return childResult; } } return null; } // 路由映射(左侧菜单栏) export const getRoutePath = (menu) => { // 路由映射表:key为接口menuName,value为对应路由路径 const routeMap = { '工作台': '/workspace', '工作台展示': '/workspace', '财务审核': '/audit', '金币审核': '/audit', '金豆审核': '/beanAudit', '汇率管理': '/rate', '充值管理': '/coinRecharge', '金币充值': '/coinRecharge', '金豆充值': '/beanRecharge', '消耗管理': '/coinConsume', '金币消耗': '/coinConsume', '金豆消耗': '/beanConsume', '退款管理': '/coinRefund', '金币退款': '/coinRefund', // '金豆退款': '/beanRefund', '权限管理': '/permissions', '客户账户明细': '/usergold', '金币客户账户明细': '/usergold', '金豆客户账户明细': '/userbean', }; // 未匹配的菜单默认使用id作为路由(可根据实际需求调整) return routeMap[menu.menuName] || '/noPermission' } // 路由映射(获取第一个菜单) export const getFirstRoutePath = (menu) => { // 路由映射表:key为接口menuName,value为对应路由路径 const routeMap = { '工作台展示': '/workspace', '金币审核': '/audit', '金豆审核': '/beanAudit', '汇率管理': '/rate', '金币充值': '/coinRecharge', '金豆充值': '/beanRecharge', '金币消耗': '/coinConsume', '金豆消耗': '/beanConsume', '金币退款': '/coinRefund', // '金豆退款': '/beanRefund', '权限管理': '/permissions', '金币客户账户明细': '/usergold', '金豆客户账户明细': '/userbean', }; // 未匹配的菜单默认使用id作为路由(可根据实际需求调整) return routeMap[menu.menuName] || '/noPermission' }