You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
4.4 KiB
91 lines
4.4 KiB
// 菜单树过滤 (展示的? )
|
|
export function filterMenu(menuList) {
|
|
return menuList
|
|
// 过滤不是4级的 123 为菜单
|
|
.filter(menu => menu.menuType === 1 || menu.menuType === 2 || menu.menuType === 3)
|
|
.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 === 1) {
|
|
return menu;
|
|
}
|
|
// 若不是,递归查找其子菜单(无论当前菜单是几级,都深入子菜单找三级)
|
|
const childResult = findFirstThirdLevelMenu(menu.children);
|
|
if (childResult) {
|
|
return childResult;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 根据菜单信息获取对应的路由路径
|
|
* @param {Object} menu - 菜单对象,必须包含 id 属性(对应接口返回的 menuName 数值标识)
|
|
* @returns {string} 匹配的路由路径,无匹配时返回 '/noPermission'(无权限页面)
|
|
*/
|
|
export const getRoutePath = (menu) => {
|
|
// 路由映射表:
|
|
// key: 接口返回的菜单唯一标识(menuName 对应的数值)
|
|
// value: 前端对应的路由路径(用于页面跳转)
|
|
const routeMap = {
|
|
"2": "/workbench", // 工作台
|
|
"3": "/goldManage", // 金币管理
|
|
"58": "/moneyManage", // 现金管理
|
|
"119": "/activityManage", // 活动管理
|
|
"124": "/channelManage", // 频道管理
|
|
"146": "/language", // 多语言配置
|
|
"5": "/audit", // 金币审核
|
|
"20": "/beanAudit", // 金豆审核
|
|
"27": "/rate", // 汇率管理
|
|
"31": "/coinRecharge", // 金币充值
|
|
"34": "/beanRecharge", // 金豆充值
|
|
"39": "/coinConsume", // 金币消耗
|
|
"42": "/beanConsume", // 金豆消耗
|
|
"47": "/coinRefund", // 退款管理
|
|
"55": "/history", // 历史数据查询(父菜单)
|
|
"56": "/history/newHistory", // 新版金币查询(历史数据查询子菜单)
|
|
"57": "/history/oldHistory", // 旧版金币查询(历史数据查询子菜单)
|
|
"128": "/permissions", // 权限管理(父菜单)
|
|
"129": "/permissions/userPermission", // 用户管理(权限管理子菜单)
|
|
"136": "/permissions/rolePermission", // 角色管理(权限管理子菜单)
|
|
"51": "/usergold", // 金币客户账户明细
|
|
"54": "/userbean", // 金豆客户账户明细
|
|
"59": "/moneyManage/receiveDetail", // 收款明细(现金管理子菜单)
|
|
"60": "/moneyManage/receiveDetail/receiveService", // 收款-地区客服(收款明细子菜单)
|
|
"67": "/moneyManage/receiveDetail/receiveFinance", // 收款-地区财务(收款明细子菜单)
|
|
"79": "/moneyManage/receiveDetail/receiveManager", // 收款-地区负责人(收款明细子菜单)
|
|
"91": "/moneyManage/receiveDetail/receiveHeader", // 收款-总部财务(收款明细子菜单)
|
|
"98": "/moneyManage/refundDetail", // 退款明细(现金管理子菜单)
|
|
"99": "/moneyManage/refundDetail/refundService", // 退款-地区客服(退款明细子菜单)
|
|
"103": "/moneyManage/refundDetail/refundFinance", // 退款-地区财务(退款明细子菜单)
|
|
"107": "/moneyManage/refundDetail/refundCharge", // 退款-地区负责人(退款明细子菜单)
|
|
"111": "/moneyManage/refundDetail/refundHeader", // 退款-总部财务(退款明细子菜单)
|
|
"115": "/moneyManage/executor", // 执行明细(现金管理子菜单)
|
|
"125": "/channelManage/reward", // 打赏管理(频道管理子菜单)
|
|
"126": "/channelManage/fans", // 铁粉管理(频道管理子菜单)
|
|
"127": "/channelManage/cart" // 小黄车管理(频道管理子菜单)
|
|
};
|
|
|
|
// 从映射表中匹配路由,无匹配时返回无权限页面路径
|
|
return routeMap[menu.id] || '/noPermission';
|
|
}
|