8343e82e89d300002f558e33df0b081d98adafd7.svn-base 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package org.jeecg.modules.system.util;
  2. import java.util.List;
  3. import org.jeecg.common.util.oConvertUtils;
  4. import org.jeecg.modules.system.entity.SysPermission;
  5. /**
  6. * @Author: scott
  7. * @Date: 2019-04-03
  8. */
  9. public class PermissionDataUtil {
  10. /**
  11. * 智能处理错误数据,简化用户失误操作
  12. *
  13. * @param permission
  14. */
  15. public static SysPermission intelligentProcessData(SysPermission permission) {
  16. if (permission == null) {
  17. return null;
  18. }
  19. // 组件
  20. if (oConvertUtils.isNotEmpty(permission.getComponent())) {
  21. String component = permission.getComponent();
  22. if (component.startsWith("/")) {
  23. component = component.substring(1);
  24. }
  25. if (component.startsWith("views/")) {
  26. component = component.replaceFirst("views/", "");
  27. }
  28. if (component.startsWith("src/views/")) {
  29. component = component.replaceFirst("src/views/", "");
  30. }
  31. if (component.endsWith(".vue")) {
  32. component = component.replace(".vue", "");
  33. }
  34. permission.setComponent(component);
  35. }
  36. // 请求URL
  37. if (oConvertUtils.isNotEmpty(permission.getUrl())) {
  38. String url = permission.getUrl();
  39. if (url.endsWith(".vue")) {
  40. url = url.replace(".vue", "");
  41. }
  42. if (!url.startsWith("http") && !url.startsWith("/")&&!url.trim().startsWith("{{")) {
  43. url = "/" + url;
  44. }
  45. permission.setUrl(url);
  46. }
  47. // 一级菜单默认组件
  48. if (0 == permission.getMenuType() && oConvertUtils.isEmpty(permission.getComponent())) {
  49. // 一级菜单默认组件
  50. permission.setComponent("layouts/RouteView");
  51. }
  52. return permission;
  53. }
  54. /**
  55. * 如果没有index页面 需要new 一个放到list中
  56. * @param metaList
  57. */
  58. public static void addIndexPage(List<SysPermission> metaList) {
  59. boolean hasIndexMenu = false;
  60. for (SysPermission sysPermission : metaList) {
  61. if("首页".equals(sysPermission.getName())) {
  62. hasIndexMenu = true;
  63. break;
  64. }
  65. }
  66. if(!hasIndexMenu) {
  67. metaList.add(0,new SysPermission(true));
  68. }
  69. }
  70. /**
  71. * 判断是否授权首页
  72. * @param metaList
  73. * @return
  74. */
  75. public static boolean hasIndexPage(List<SysPermission> metaList){
  76. boolean hasIndexMenu = false;
  77. for (SysPermission sysPermission : metaList) {
  78. if("首页".equals(sysPermission.getName())) {
  79. hasIndexMenu = true;
  80. break;
  81. }
  82. }
  83. return hasIndexMenu;
  84. }
  85. }