123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package com.ruoyi.system.domain;
- import com.baomidou.mybatisplus.annotation.TableId;
- import com.baomidou.mybatisplus.annotation.TableName;
- import com.ruoyi.common.core.constant.Constants;
- import com.ruoyi.common.core.constant.UserConstants;
- import com.ruoyi.common.core.utils.StringUtils;
- import com.ruoyi.common.mybatis.core.domain.TreeEntity;
- import lombok.Data;
- import lombok.EqualsAndHashCode;
- /**
- * 菜单权限表 sys_menu
- *
- * @author Lion Li
- */
- @Data
- @EqualsAndHashCode(callSuper = true)
- @TableName("sys_menu")
- public class SysMenu extends TreeEntity<SysMenu> {
- /**
- * 菜单ID
- */
- @TableId(value = "menu_id")
- private Long menuId;
- /**
- * 菜单名称
- */
- private String menuName;
- /**
- * 显示顺序
- */
- private Integer orderNum;
- /**
- * 路由地址
- */
- private String path;
- /**
- * 组件路径
- */
- private String component;
- /**
- * 路由参数
- */
- private String queryParam;
- /**
- * 是否为外链(0是 1否)
- */
- private String isFrame;
- /**
- * 是否缓存(0缓存 1不缓存)
- */
- private String isCache;
- /**
- * 类型(M目录 C菜单 F按钮)
- */
- private String menuType;
- /**
- * 显示状态(0显示 1隐藏)
- */
- private String visible;
- /**
- * 菜单状态(0正常 1停用)
- */
- private String status;
- /**
- * 权限字符串
- */
- private String perms;
- /**
- * 菜单图标
- */
- private String icon;
- /**
- * 备注
- */
- private String remark;
- /**
- * 获取路由名称
- */
- public String getRouteName() {
- String routerName = StringUtils.capitalize(path);
- // 非外链并且是一级目录(类型为目录)
- if (isMenuFrame()) {
- routerName = StringUtils.EMPTY;
- }
- return routerName;
- }
- /**
- * 获取路由地址
- */
- public String getRouterPath() {
- String routerPath = this.path;
- // 内链打开外网方式
- if (getParentId() != 0L && isInnerLink()) {
- routerPath = innerLinkReplaceEach(routerPath);
- }
- // 非外链并且是一级目录(类型为目录)
- if (0L == getParentId() && UserConstants.TYPE_DIR.equals(getMenuType())
- && UserConstants.NO_FRAME.equals(getIsFrame())) {
- routerPath = "/" + this.path;
- }
- // 非外链并且是一级目录(类型为菜单)
- else if (isMenuFrame()) {
- routerPath = "/";
- }
- return routerPath;
- }
- /**
- * 获取组件信息
- */
- public String getComponent() {
- String component = UserConstants.LAYOUT;
- if (StringUtils.isNotEmpty(this.component) && !isMenuFrame()) {
- component = this.component;
- } else if (StringUtils.isEmpty(this.component) && getParentId() != 0L && isInnerLink()) {
- component = UserConstants.INNER_LINK;
- } else if (StringUtils.isEmpty(this.component) && isParentView()) {
- component = UserConstants.PARENT_VIEW;
- }
- return component;
- }
- /**
- * 是否为菜单内部跳转
- */
- public boolean isMenuFrame() {
- return getParentId() == 0L && UserConstants.TYPE_MENU.equals(menuType) && isFrame.equals(UserConstants.NO_FRAME);
- }
- /**
- * 是否为内链组件
- */
- public boolean isInnerLink() {
- return isFrame.equals(UserConstants.NO_FRAME) && StringUtils.ishttp(path);
- }
- /**
- * 是否为parent_view组件
- */
- public boolean isParentView() {
- return getParentId() != 0L && UserConstants.TYPE_DIR.equals(menuType);
- }
- /**
- * 内链域名特殊字符替换
- */
- public static String innerLinkReplaceEach(String path) {
- return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."},
- new String[]{"", "", "", "/"});
- }
- }
|