| | |
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.framework.web.domain.TreeSelect;
|
| | | import com.ruoyi.project.system.domain.SysMenu;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.domain.vo.MetaVo;
|
| | | import com.ruoyi.project.system.domain.vo.RouterVo;
|
| | | import com.ruoyi.project.system.mapper.SysMenuMapper;
|
| | |
| | | private SysRoleMenuMapper roleMenuMapper;
|
| | |
|
| | | /**
|
| | | * 根据用户查询系统菜单列表
|
| | | * |
| | | * @param userId 用户ID
|
| | | * @return 菜单列表
|
| | | */
|
| | | @Override
|
| | | public List<SysMenu> selectMenuList(Long userId)
|
| | | {
|
| | | return selectMenuList(new SysMenu(), userId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 查询系统菜单列表
|
| | | *
|
| | | * @param menu 菜单信息
|
| | | * @return 菜单列表
|
| | | */
|
| | | @Override
|
| | | public List<SysMenu> selectMenuList(SysMenu menu)
|
| | | public List<SysMenu> selectMenuList(SysMenu menu, Long userId)
|
| | | {
|
| | | List<SysMenu> menuList = menuMapper.selectMenuList(menu);
|
| | | List<SysMenu> menuList = null;
|
| | | // 管理员显示所有菜单信息
|
| | | if (SysUser.isAdmin(userId))
|
| | | {
|
| | | menuList = menuMapper.selectMenuList(menu);
|
| | | }
|
| | | else
|
| | | {
|
| | | menu.getParams().put("userId", userId);
|
| | | menuList = menuMapper.selectMenuListByUserId(menu);
|
| | | }
|
| | | return menuList;
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 根据用户名称查询菜单
|
| | | * 根据用户ID查询菜单
|
| | | *
|
| | | * @param username 用户名称
|
| | | * @param userId 用户名称
|
| | | * @return 菜单列表
|
| | | */
|
| | | @Override
|
| | |
| | | for (SysMenu menu : menus)
|
| | | {
|
| | | RouterVo router = new RouterVo();
|
| | | router.setName(StringUtils.capitalize(menu.getPath()));
|
| | | router.setHidden("1".equals(menu.getVisible()));
|
| | | router.setName(getRouteName(menu));
|
| | | router.setPath(getRouterPath(menu));
|
| | | router.setComponent(StringUtils.isEmpty(menu.getComponent()) ? "Layout" : menu.getComponent());
|
| | | router.setComponent(getComponent(menu));
|
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
| | | List<SysMenu> cMenus = menu.getChildren();
|
| | | if (!cMenus.isEmpty() && cMenus.size() > 0 && "M".equals(menu.getMenuType()))
|
| | | if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()))
|
| | | {
|
| | | router.setAlwaysShow(true);
|
| | | router.setRedirect("noRedirect");
|
| | | router.setChildren(buildMenus(cMenus));
|
| | | }
|
| | | else if (isMeunFrame(menu))
|
| | | {
|
| | | List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
| | | RouterVo children = new RouterVo();
|
| | | children.setPath(menu.getPath());
|
| | | children.setComponent(menu.getComponent());
|
| | | children.setName(StringUtils.capitalize(menu.getPath()));
|
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
| | | childrenList.add(children);
|
| | | router.setChildren(childrenList);
|
| | | }
|
| | | routers.add(router);
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 获取路由名称
|
| | | * |
| | | * @param menu 菜单信息
|
| | | * @return 路由名称
|
| | | */
|
| | | public String getRouteName(SysMenu menu)
|
| | | {
|
| | | String routerName = StringUtils.capitalize(menu.getPath());
|
| | | // 非外链并且是一级目录(类型为目录)
|
| | | if (isMeunFrame(menu))
|
| | | {
|
| | | routerName = StringUtils.EMPTY;
|
| | | }
|
| | | return routerName;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取路由地址
|
| | | *
|
| | | * @param menu 菜单信息
|
| | |
| | | public String getRouterPath(SysMenu menu)
|
| | | {
|
| | | String routerPath = menu.getPath();
|
| | | // 非外链并且是一级目录
|
| | | if (0 == menu.getParentId() && "1".equals(menu.getIsFrame()))
|
| | | // 非外链并且是一级目录(类型为目录)
|
| | | if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType())
|
| | | && UserConstants.NO_FRAME.equals(menu.getIsFrame()))
|
| | | {
|
| | | routerPath = "/" + menu.getPath();
|
| | | }
|
| | | // 非外链并且是一级目录(类型为菜单)
|
| | | else if (isMeunFrame(menu))
|
| | | {
|
| | | routerPath = "/";
|
| | | }
|
| | | return routerPath;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取组件信息
|
| | | * |
| | | * @param menu 菜单信息
|
| | | * @return 组件信息
|
| | | */
|
| | | public String getComponent(SysMenu menu)
|
| | | {
|
| | | String component = UserConstants.LAYOUT;
|
| | | if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu))
|
| | | {
|
| | | component = menu.getComponent();
|
| | | }
|
| | | return component;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 是否为菜单内部跳转
|
| | | * |
| | | * @param menu 菜单信息
|
| | | * @return 结果
|
| | | */
|
| | | public boolean isMeunFrame(SysMenu menu)
|
| | | {
|
| | | return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType())
|
| | | && menu.getIsFrame().equals(UserConstants.NO_FRAME);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据父节点的ID获取所有子节点
|
| | | *
|
| | | * @param list 分类表
|