diff --git a/src/utils/menuUtils.js b/src/utils/menuUtils.js index 2051139..df25b5d 100644 --- a/src/utils/menuUtils.js +++ b/src/utils/menuUtils.js @@ -2,7 +2,7 @@ export function filterMenu(menuList) { return menuList // 过滤不是4级的 123 为菜单 - .filter(menu => menu.menuType ===1 || menu.menuType === 2 || menu.menuType === 3) + .filter(menu => menu.menuType === 1 || menu.menuType === 2 || menu.menuType === 3) .map(menu => ({ ...menu, children: menu.children ? filterMenu(menu.children) : [] @@ -38,69 +38,54 @@ export function findFirstThirdLevelMenu(menuList) { return null; } -// 路由映射(左侧菜单栏) +/** + * 根据菜单信息获取对应的路由路径 + * @param {Object} menu - 菜单对象,必须包含 id 属性(对应接口返回的 menuName 数值标识) + * @returns {string} 匹配的路由路径,无匹配时返回 '/noPermission'(无权限页面) + */ export const getRoutePath = (menu) => { - // 路由映射表:key为接口menuName,value为对应路由路径 + // 路由映射表: + // key: 接口返回的菜单唯一标识(menuName 对应的数值) + // value: 前端对应的路由路径(用于页面跳转) const routeMap = { - - '工作台': '/workbench', - - '金币管理': '/goldManage', - '现金管理': '/moneyManage', - '活动管理': '/activityManage', - '频道管理': '/channelManage', - '多语言配置': '/language', - - '金币审核': '/audit', - '金豆审核': '/beanAudit', - - '汇率管理': '/rate', - - - '金币充值': '/coinRecharge', - '金豆充值': '/beanRecharge', - - '金币消耗': '/coinConsume', - '金豆消耗': '/beanConsume', - - - '退款管理': '/coinRefund', - - '历史数据查询': '/history', - '新版金币查询': '/history/newHistory', - '旧版金币查询': '/history/oldHistory', - - - '权限管理': '/permissions', - '用户管理': '/permissions/userPermission', - '角色管理': '/permissions/rolePermission', - - - '金币客户账户明细': '/usergold', - '金豆客户账户明细': '/userbean', - - '收款明细': '/moneyManage/receiveDetail', - '收款-地区客服':'/moneyManage/receiveDetail/receiveService', - '收款-地区财务':'/moneyManage/receiveDetail/receiveFinance', - '收款-地区负责人':'/moneyManage/receiveDetail/receiveManager', - '收款-总部财务':'/moneyManage/receiveDetail/receiveHeader', - - - '退款明细': '/moneyManage/refundDetail', - '退款-地区客服':'/moneyManage/refundDetail/refundService', - '退款-地区财务':'/moneyManage/refundDetail/refundFinance', - '退款-地区负责人':'/moneyManage/refundDetail/refundCharge', - '退款-总部财务':'/moneyManage/refundDetail/refundHeader', - - '执行明细': '/moneyManage/executor', - - - '打赏管理': '/channelManage/reward', - '铁粉管理': '/channelManage/fans', - '小黄车管理': '/channelManage/cart', + "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" // 小黄车管理(频道管理子菜单) }; - // console.log('1111',menu.menuName) - // 未匹配的菜单默认使用id作为路由(可根据实际需求调整) - return routeMap[menu.menuName] || '/noPermission' + // 从映射表中匹配路由,无匹配时返回无权限页面路径 + return routeMap[menu.id] || '/noPermission'; } \ No newline at end of file diff --git a/src/views/login.vue b/src/views/login.vue index d8d53e6..123b023 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -77,7 +77,7 @@ const login = async function () { // 获取第一个可访问的菜单 const firstMenu = findFirstThirdLevelMenu(filteredMenu) - console.log('获取到的第一个可访问的菜单', firstMenu) + console.log('获取到的第一个可访问的菜单的id', firstMenu) // 获取第一个可访问的菜单的 path const redirectPath = firstMenu ? getRoutePath(firstMenu) : '/noPermission'