From 505660cfdf1461a1a43bf0563193e35ea213a369 Mon Sep 17 00:00:00 2001 From: wxy <1229384355@qq.com> Date: Wed, 27 Jul 2022 17:45:52 +0800 Subject: [PATCH] 自定义首页 --- juvenile-prosecution-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/RoleIndexConfigEnum.java | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ juvenile-prosecution-boot/jeecg-boot-module-system/target/classes/org/jeecg/modules/system/controller/SysPermissionController.class | Bin 29745 -> 0 bytes juvenile-prosecution-vue/src/views/system/modules/UserModal.vue | 41 +++-------------------------------------- 4 files changed, 156 insertions(+), 38 deletions(-) create mode 100644 juvenile-prosecution-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/RoleIndexConfigEnum.java diff --git a/juvenile-prosecution-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/RoleIndexConfigEnum.java b/juvenile-prosecution-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/RoleIndexConfigEnum.java new file mode 100644 index 0000000..851711c --- /dev/null +++ b/juvenile-prosecution-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/RoleIndexConfigEnum.java @@ -0,0 +1,90 @@ +package org.jeecg.common.constant.enums; + +import org.jeecg.common.util.oConvertUtils; + +import java.util.List; + +/** + * 首页自定义 + * 通过角色编码与首页组件路径配置 + * 枚举的顺序有权限高低权重作用(也就是配置多个角色,在前面的角色首页,会优先生效) + */ +public enum RoleIndexConfigEnum { + + ADMIN("admin", "business/MinorList"), + //TEST("test", "dashboard/IndexChart"), + HR("hr", "dashboard/IndexBdc"); + //DM("dm", "dashboard/IndexTask"), + + /** + * 角色编码 + */ + String roleCode; + /** + * 路由index + */ + String componentUrl; + + /** + * 构造器 + * + * @param roleCode 角色编码 + * @param componentUrl 首页组件路径(规则跟菜单配置一样) + */ + RoleIndexConfigEnum(String roleCode, String componentUrl) { + this.roleCode = roleCode; + this.componentUrl = componentUrl; + } + /** + * 根据code找枚举 + * @param roleCode 角色编码 + * @return + */ + private static RoleIndexConfigEnum getEnumByCode(String roleCode) { + for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { + if (e.roleCode.equals(roleCode)) { + return e; + } + } + return null; + } + /** + * 根据code找index + * @param roleCode 角色编码 + * @return + */ + private static String getIndexByCode(String roleCode) { + for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { + if (e.roleCode.equals(roleCode)) { + return e.componentUrl; + } + } + return null; + } + + public static String getIndexByRoles(List roles) { + String[] rolesArray = roles.toArray(new String[roles.size()]); + for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { + if (oConvertUtils.isIn(e.roleCode,rolesArray)){ + return e.componentUrl; + } + } + return null; + } + + public String getRoleCode() { + return roleCode; + } + + public void setRoleCode(String roleCode) { + this.roleCode = roleCode; + } + + public String getComponentUrl() { + return componentUrl; + } + + public void setComponentUrl(String componentUrl) { + this.componentUrl = componentUrl; + } +} diff --git a/juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java b/juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java index 6b2a0f2..9b33df7 100644 --- a/juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java +++ b/juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java @@ -5,11 +5,14 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresRoles; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.constant.enums.RoleIndexConfigEnum; import org.jeecg.common.system.util.JwtUtil; +import org.jeecg.common.system.vo.DictModel; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.MD5Util; import org.jeecg.common.util.oConvertUtils; @@ -52,6 +55,13 @@ public class SysPermissionController { @Autowired private ISysDepartPermissionService sysDepartPermissionService; + @Autowired + private ISysDictService sysDictItemService; + + @Autowired + private ISysUserService sysUserService; + + /** * 加载数据节点 * @@ -214,10 +224,39 @@ public class SysPermissionController { SysPermission indexMenu = sysPermissionService.list(new LambdaQueryWrapper().eq(SysPermission::getName,"首页")).get(0); metaList.add(0,indexMenu); } + //update-begin--Author:wxy Date:20220727 for:自定义首页地址LOWCOD-1578 + List roles = sysUserService.getRole(loginUser.getUsername()); + //改为字典表内取 + List list=sysDictItemService.queryDictItemsByCode("access_home_page"); + String compUrl=""; + if(list!=null&&list.size()>0){ + for (String role:roles) { + for (DictModel dictModel:list) { + if(dictModel.getValue().equals(role)){ + compUrl=dictModel.getText(); + break; + } + } + } + + }else { + compUrl = RoleIndexConfigEnum.getIndexByRoles(roles); + } + if("".equals(compUrl)){ + compUrl = RoleIndexConfigEnum.getIndexByRoles(roles); + } + if(StringUtils.isNotBlank(compUrl)){ + List menus = metaList.stream().filter(sysPermission -> "首页".equals(sysPermission.getName())).collect(Collectors.toList()); + menus.get(0).setComponent(compUrl); + } + //update-begin--Author:wxy Date:20220727 for:自定义首页地址LOWCOD-1578 //update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存 JSONObject json = new JSONObject(); JSONArray menujsonArray = new JSONArray(); this.getPermissionJsonArray(menujsonArray, metaList, null); + //一级菜单下的子菜单全部是隐藏路由,则一级菜单不显示 + this.handleFirstLevelMenuHidden(menujsonArray); + JSONArray authjsonArray = new JSONArray(); this.getAuthJsonArray(authjsonArray, metaList); //查询所有的权限 @@ -244,6 +283,30 @@ public class SysPermissionController { } /** + * 一级菜单的子菜单全部是隐藏路由,则一级菜单不显示 + * @param jsonArray + */ + private void handleFirstLevelMenuHidden(JSONArray jsonArray) { + jsonArray = jsonArray.stream().map(obj -> { + JSONObject returnObj = new JSONObject(); + JSONObject jsonObj = (JSONObject)obj; + if(jsonObj.containsKey("children")){ + JSONArray childrens = jsonObj.getJSONArray("children"); + childrens = childrens.stream().filter(arrObj -> !"true".equals(((JSONObject) arrObj).getString("hidden"))).collect(Collectors.toCollection(JSONArray::new)); + if(childrens==null || childrens.size()==0){ + jsonObj.put("hidden",true); + + //vue3版本兼容代码 + JSONObject meta = new JSONObject(); + meta.put("hideMenu",true); + jsonObj.put("meta", meta); + } + } + return returnObj; + }).collect(Collectors.toCollection(JSONArray::new)); + } + + /** * 添加菜单 * @param permission * @return diff --git a/juvenile-prosecution-boot/jeecg-boot-module-system/target/classes/org/jeecg/modules/system/controller/SysPermissionController.class b/juvenile-prosecution-boot/jeecg-boot-module-system/target/classes/org/jeecg/modules/system/controller/SysPermissionController.class index d4a7893..1de5bdb 100644 Binary files a/juvenile-prosecution-boot/jeecg-boot-module-system/target/classes/org/jeecg/modules/system/controller/SysPermissionController.class and b/juvenile-prosecution-boot/jeecg-boot-module-system/target/classes/org/jeecg/modules/system/controller/SysPermissionController.class differ diff --git a/juvenile-prosecution-vue/src/views/system/modules/UserModal.vue b/juvenile-prosecution-vue/src/views/system/modules/UserModal.vue index 9a5a70e..630bc6e 100644 --- a/juvenile-prosecution-vue/src/views/system/modules/UserModal.vue +++ b/juvenile-prosecution-vue/src/views/system/modules/UserModal.vue @@ -30,7 +30,7 @@ - + @@ -40,14 +40,6 @@ - - - - - - - - - + - - - - - - - - 普通用户 - 上级 - - - - - - @@ -99,7 +68,7 @@ :format="dateFormat" :getCalendarContainer="node => node.parentNode"/> - + @@ -119,10 +88,6 @@ - - - - -- libgit2 0.21.4