Commit bb1324a70ae25bac00eadbd4d14bb0c1faf5d2df
1 parent
c1db17dd
支持一级菜单(和主页同级)在main区域显示
Showing
3 changed files
with
65 additions
and
4 deletions
ruoyi-ui/src/store/modules/permission.js
| ... | ... | @@ -32,6 +32,10 @@ const permission = { |
| 32 | 32 | // 遍历后台传来的路由字符串,转换为组件对象 |
| 33 | 33 | function filterAsyncRouter(asyncRouterMap) { |
| 34 | 34 | return asyncRouterMap.filter(route => { |
| 35 | + if(!route.path){ | |
| 36 | + // 防止空路由出现的警告,设置默认path | |
| 37 | + route.path = '/path'; | |
| 38 | + } | |
| 35 | 39 | if (route.component) { |
| 36 | 40 | // Layout组件特殊处理 |
| 37 | 41 | if (route.component === 'Layout') { | ... | ... |
ruoyi/src/main/java/com/ruoyi/common/constant/UserConstants.java
| ... | ... | @@ -42,6 +42,18 @@ public class UserConstants |
| 42 | 42 | /** 是否菜单外链(否) */ |
| 43 | 43 | public static final String NO_FRAME = "1"; |
| 44 | 44 | |
| 45 | + /** 菜单类型(目录) */ | |
| 46 | + public static final String TYPE_DIR = "M"; | |
| 47 | + | |
| 48 | + /** 菜单类型(菜单) */ | |
| 49 | + public static final String TYPE_MENU = "C"; | |
| 50 | + | |
| 51 | + /** 菜单类型(按钮) */ | |
| 52 | + public static final String TYPE_BUTTON = "F"; | |
| 53 | + | |
| 54 | + /** Layout组件标识 */ | |
| 55 | + public final static String LAYOUT = "Layout"; | |
| 56 | + | |
| 45 | 57 | /** 校验返回结果码 */ |
| 46 | 58 | public final static String UNIQUE = "0"; |
| 47 | 59 | public final static String NOT_UNIQUE = "1"; | ... | ... |
ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java
| ... | ... | @@ -142,15 +142,26 @@ public class SysMenuServiceImpl implements ISysMenuService |
| 142 | 142 | router.setHidden("1".equals(menu.getVisible())); |
| 143 | 143 | router.setName(StringUtils.capitalize(menu.getPath())); |
| 144 | 144 | router.setPath(getRouterPath(menu)); |
| 145 | - router.setComponent(StringUtils.isEmpty(menu.getComponent()) ? "Layout" : menu.getComponent()); | |
| 145 | + router.setComponent(getComponent(menu)); | |
| 146 | 146 | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); |
| 147 | 147 | List<SysMenu> cMenus = menu.getChildren(); |
| 148 | - if (!cMenus.isEmpty() && cMenus.size() > 0 && "M".equals(menu.getMenuType())) | |
| 148 | + if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType())) | |
| 149 | 149 | { |
| 150 | 150 | router.setAlwaysShow(true); |
| 151 | 151 | router.setRedirect("noRedirect"); |
| 152 | 152 | router.setChildren(buildMenus(cMenus)); |
| 153 | 153 | } |
| 154 | + else if (isMeunFrame(menu)) | |
| 155 | + { | |
| 156 | + List<RouterVo> childrenList = new ArrayList<RouterVo>(); | |
| 157 | + RouterVo children = new RouterVo(); | |
| 158 | + children.setPath(menu.getPath()); | |
| 159 | + children.setComponent(menu.getComponent()); | |
| 160 | + children.setName(StringUtils.capitalize(menu.getPath())); | |
| 161 | + children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); | |
| 162 | + childrenList.add(children); | |
| 163 | + router.setChildren(childrenList); | |
| 164 | + } | |
| 154 | 165 | routers.add(router); |
| 155 | 166 | } |
| 156 | 167 | return routers; |
| ... | ... | @@ -297,15 +308,49 @@ public class SysMenuServiceImpl implements ISysMenuService |
| 297 | 308 | public String getRouterPath(SysMenu menu) |
| 298 | 309 | { |
| 299 | 310 | String routerPath = menu.getPath(); |
| 300 | - // 非外链并且是一级目录 | |
| 301 | - if (0 == menu.getParentId() && UserConstants.NO_FRAME.equals(menu.getIsFrame())) | |
| 311 | + // 非外链并且是一级目录(类型为目录) | |
| 312 | + if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) | |
| 313 | + && UserConstants.NO_FRAME.equals(menu.getIsFrame())) | |
| 302 | 314 | { |
| 303 | 315 | routerPath = "/" + menu.getPath(); |
| 304 | 316 | } |
| 317 | + // 非外链并且是一级目录(类型为菜单) | |
| 318 | + else if (isMeunFrame(menu)) | |
| 319 | + { | |
| 320 | + routerPath = StringUtils.EMPTY; | |
| 321 | + } | |
| 305 | 322 | return routerPath; |
| 306 | 323 | } |
| 307 | 324 | |
| 308 | 325 | /** |
| 326 | + * 获取组件信息 | |
| 327 | + * | |
| 328 | + * @param menu 菜单信息 | |
| 329 | + * @return 组件信息 | |
| 330 | + */ | |
| 331 | + public String getComponent(SysMenu menu) | |
| 332 | + { | |
| 333 | + String component = UserConstants.LAYOUT; | |
| 334 | + if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu)) | |
| 335 | + { | |
| 336 | + component = menu.getComponent(); | |
| 337 | + } | |
| 338 | + return component; | |
| 339 | + } | |
| 340 | + | |
| 341 | + /** | |
| 342 | + * 是否为菜单内部跳转 | |
| 343 | + * | |
| 344 | + * @param menu 菜单信息 | |
| 345 | + * @return 结果 | |
| 346 | + */ | |
| 347 | + public boolean isMeunFrame(SysMenu menu) | |
| 348 | + { | |
| 349 | + return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType()) | |
| 350 | + && menu.getIsFrame().equals(UserConstants.NO_FRAME); | |
| 351 | + } | |
| 352 | + | |
| 353 | + /** | |
| 309 | 354 | * 根据父节点的ID获取所有子节点 |
| 310 | 355 | * |
| 311 | 356 | * @param list 分类表 | ... | ... |