SysMenu.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package com.ruoyi.system.domain;
  2. import com.baomidou.mybatisplus.annotation.TableId;
  3. import com.baomidou.mybatisplus.annotation.TableName;
  4. import com.ruoyi.common.core.constant.Constants;
  5. import com.ruoyi.common.core.constant.UserConstants;
  6. import com.ruoyi.common.core.utils.StringUtils;
  7. import com.ruoyi.common.mybatis.core.domain.TreeEntity;
  8. import lombok.Data;
  9. import lombok.EqualsAndHashCode;
  10. /**
  11. * 菜单权限表 sys_menu
  12. *
  13. * @author Lion Li
  14. */
  15. @Data
  16. @EqualsAndHashCode(callSuper = true)
  17. @TableName("sys_menu")
  18. public class SysMenu extends TreeEntity<SysMenu> {
  19. /**
  20. * 菜单ID
  21. */
  22. @TableId(value = "menu_id")
  23. private Long menuId;
  24. /**
  25. * 菜单名称
  26. */
  27. private String menuName;
  28. /**
  29. * 显示顺序
  30. */
  31. private Integer orderNum;
  32. /**
  33. * 路由地址
  34. */
  35. private String path;
  36. /**
  37. * 组件路径
  38. */
  39. private String component;
  40. /**
  41. * 路由参数
  42. */
  43. private String queryParam;
  44. /**
  45. * 是否为外链(0是 1否)
  46. */
  47. private String isFrame;
  48. /**
  49. * 是否缓存(0缓存 1不缓存)
  50. */
  51. private String isCache;
  52. /**
  53. * 类型(M目录 C菜单 F按钮)
  54. */
  55. private String menuType;
  56. /**
  57. * 显示状态(0显示 1隐藏)
  58. */
  59. private String visible;
  60. /**
  61. * 菜单状态(0正常 1停用)
  62. */
  63. private String status;
  64. /**
  65. * 权限字符串
  66. */
  67. private String perms;
  68. /**
  69. * 菜单图标
  70. */
  71. private String icon;
  72. /**
  73. * 备注
  74. */
  75. private String remark;
  76. /**
  77. * 获取路由名称
  78. */
  79. public String getRouteName() {
  80. String routerName = StringUtils.capitalize(path);
  81. // 非外链并且是一级目录(类型为目录)
  82. if (isMenuFrame()) {
  83. routerName = StringUtils.EMPTY;
  84. }
  85. return routerName;
  86. }
  87. /**
  88. * 获取路由地址
  89. */
  90. public String getRouterPath() {
  91. String routerPath = this.path;
  92. // 内链打开外网方式
  93. if (getParentId() != 0L && isInnerLink()) {
  94. routerPath = innerLinkReplaceEach(routerPath);
  95. }
  96. // 非外链并且是一级目录(类型为目录)
  97. if (0L == getParentId() && UserConstants.TYPE_DIR.equals(getMenuType())
  98. && UserConstants.NO_FRAME.equals(getIsFrame())) {
  99. routerPath = "/" + this.path;
  100. }
  101. // 非外链并且是一级目录(类型为菜单)
  102. else if (isMenuFrame()) {
  103. routerPath = "/";
  104. }
  105. return routerPath;
  106. }
  107. /**
  108. * 获取组件信息
  109. */
  110. public String getComponent() {
  111. String component = UserConstants.LAYOUT;
  112. if (StringUtils.isNotEmpty(this.component) && !isMenuFrame()) {
  113. component = this.component;
  114. } else if (StringUtils.isEmpty(this.component) && getParentId() != 0L && isInnerLink()) {
  115. component = UserConstants.INNER_LINK;
  116. } else if (StringUtils.isEmpty(this.component) && isParentView()) {
  117. component = UserConstants.PARENT_VIEW;
  118. }
  119. return component;
  120. }
  121. /**
  122. * 是否为菜单内部跳转
  123. */
  124. public boolean isMenuFrame() {
  125. return getParentId() == 0L && UserConstants.TYPE_MENU.equals(menuType) && isFrame.equals(UserConstants.NO_FRAME);
  126. }
  127. /**
  128. * 是否为内链组件
  129. */
  130. public boolean isInnerLink() {
  131. return isFrame.equals(UserConstants.NO_FRAME) && StringUtils.ishttp(path);
  132. }
  133. /**
  134. * 是否为parent_view组件
  135. */
  136. public boolean isParentView() {
  137. return getParentId() != 0L && UserConstants.TYPE_DIR.equals(menuType);
  138. }
  139. /**
  140. * 内链域名特殊字符替换
  141. */
  142. public static String innerLinkReplaceEach(String path) {
  143. return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."},
  144. new String[]{"", "", "", "/"});
  145. }
  146. }