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.

67 lines
1.9 KiB

  1. // 菜单树过滤 (展示的? )
  2. export function filterMenu(menuList) {
  3. return menuList
  4. // 过滤不是4级的 123 为菜单
  5. .filter(menu => menu.menuType !== 4)
  6. .map(menu => ({
  7. ...menu,
  8. children: menu.children ? filterMenu(menu.children) : []
  9. }))
  10. .sort((a, b) => a.id - b.id); // 按 id 升序
  11. }
  12. // 辅助函数:查找第一个可访问的菜单项
  13. export function findFirstAccessibleMenu(menuList) {
  14. if (!menuList || menuList.length === 0) return null
  15. for (const menu of menuList) {
  16. if (menu.menuType === 1) { // 根
  17. const childResult = findFirstAccessibleMenu(menu.children)
  18. if (childResult) return childResult
  19. } else if (menu.menuType === 2) { // 目录
  20. return menu
  21. } else if (menu.menuType === 3) { // 菜单
  22. console.log('菜单:', menu)
  23. return menu
  24. }
  25. }
  26. return null
  27. }
  28. // 路由映射
  29. export const getRoutePath = (menu) => {
  30. // 路由映射表:key为接口menuName,value为对应路由路径
  31. const routeMap = {
  32. '工作台': '/workspace',
  33. '财务审核': '/audit',
  34. '金币审核': '/audit',
  35. '金豆审核': '/beanAudit',
  36. '汇率管理': '/rate',
  37. '充值管理': '/coinRecharge',
  38. '金币充值': '/coinRecharge',
  39. '金豆充值': '/beanRecharge',
  40. '消耗管理': '/coinConsume',
  41. '金币消耗': '/coinConsume',
  42. '金豆消耗': '/beanConsume',
  43. '退款管理': '/coinRefund',
  44. '金币退款': '/coinRefund',
  45. // '金豆退款': '/beanRefund',
  46. '权限管理': '/permissions',
  47. '客户账户明细': '/usergold',
  48. '金币客户账户明细': '/usergold',
  49. '金豆客户账户明细': '/userbean',
  50. };
  51. // 未匹配的菜单默认使用id作为路由(可根据实际需求调整)
  52. return routeMap[menu.menuName] || '/noPermission'
  53. }