Commit 03126efa4838fbc135f87ff169d90d3c486a0cf4
1 parent
d8017d29
授权首页菜单后,自定义首页功能不生效 #3069
Showing
2 changed files
with
37 additions
and
18 deletions
jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/RoleIndexConfigEnum.java
1 | 1 | package org.jeecg.common.constant.enums; |
2 | 2 | |
3 | +import java.util.List; | |
4 | + | |
3 | 5 | /** |
4 | 6 | * 首页自定义 |
5 | 7 | * 通过角色编码与首页组件路径配置 |
... | ... | @@ -64,6 +66,17 @@ public enum RoleIndexConfigEnum { |
64 | 66 | return null; |
65 | 67 | } |
66 | 68 | |
69 | + public static String getIndexByRoles(List<String> roles) { | |
70 | + for (String role : roles) { | |
71 | + for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { | |
72 | + if (e.roleCode.equals(role)) { | |
73 | + return e.componentUrl; | |
74 | + } | |
75 | + } | |
76 | + } | |
77 | + return null; | |
78 | + } | |
79 | + | |
67 | 80 | public String getRoleCode() { |
68 | 81 | return roleCode; |
69 | 82 | } |
... | ... |
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysPermissionController.java
... | ... | @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
7 | 7 | import lombok.extern.slf4j.Slf4j; |
8 | 8 | import org.apache.commons.lang3.StringUtils; |
9 | 9 | import org.apache.shiro.SecurityUtils; |
10 | +import org.apache.shiro.authz.annotation.RequiresRoles; | |
10 | 11 | import org.jeecg.common.api.vo.Result; |
11 | 12 | import org.jeecg.common.constant.CommonConstant; |
12 | 13 | import org.jeecg.common.constant.enums.RoleIndexConfigEnum; |
... | ... | @@ -22,6 +23,7 @@ import org.jeecg.modules.system.model.TreeModel; |
22 | 23 | import org.jeecg.modules.system.service.*; |
23 | 24 | import org.jeecg.modules.system.util.PermissionDataUtil; |
24 | 25 | import org.springframework.beans.factory.annotation.Autowired; |
26 | +import org.springframework.beans.factory.annotation.Value; | |
25 | 27 | import org.springframework.web.bind.annotation.*; |
26 | 28 | |
27 | 29 | import java.util.*; |
... | ... | @@ -54,6 +56,12 @@ public class SysPermissionController { |
54 | 56 | |
55 | 57 | @Autowired |
56 | 58 | private ISysUserService sysUserService; |
59 | + /** | |
60 | + * 系统安全模式(true开启,false关闭) | |
61 | + */ | |
62 | + @Value(value = "${jeecg.safeMode:false}") | |
63 | + private Boolean sysSafeMode; | |
64 | + | |
57 | 65 | |
58 | 66 | /** |
59 | 67 | * 加载数据节点 |
... | ... | @@ -215,21 +223,18 @@ public class SysPermissionController { |
215 | 223 | //update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存 |
216 | 224 | if(!PermissionDataUtil.hasIndexPage(metaList)){ |
217 | 225 | SysPermission indexMenu = sysPermissionService.list(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getName,"首页")).get(0); |
218 | - //update-begin--Author:liusq Date:20210624 for:自定义首页地址LOWCOD-1578 | |
219 | - List<String> roles = sysUserService.getRole(loginUser.getUsername()); | |
220 | - if(roles.size()>0){ | |
221 | - for (String code:roles) { | |
222 | - String componentUrl = RoleIndexConfigEnum.getIndexByCode(code); | |
223 | - if(StringUtils.isNotBlank(componentUrl)){ | |
224 | - indexMenu.setComponent(componentUrl); | |
225 | - break; | |
226 | - } | |
227 | - } | |
228 | - } | |
229 | - //update-end--Author:liusq Date:20210624 for:自定义首页地址LOWCOD-1578 | |
230 | 226 | metaList.add(0,indexMenu); |
231 | 227 | } |
232 | 228 | //update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存 |
229 | + | |
230 | + //update-begin--Author:liusq Date:20210624 for:自定义首页地址LOWCOD-1578 | |
231 | + List<String> roles = sysUserService.getRole(loginUser.getUsername()); | |
232 | + String compUrl = RoleIndexConfigEnum.getIndexByRoles(roles); | |
233 | + if(StringUtils.isNotBlank(compUrl)){ | |
234 | + List<SysPermission> menus = metaList.stream().filter(sysPermission -> "首页".equals(sysPermission.getName())).collect(Collectors.toList()); | |
235 | + menus.get(0).setComponent(compUrl); | |
236 | + } | |
237 | + //update-end--Author:liusq Date:20210624 for:自定义首页地址LOWCOD-1578 | |
233 | 238 | JSONObject json = new JSONObject(); |
234 | 239 | JSONArray menujsonArray = new JSONArray(); |
235 | 240 | this.getPermissionJsonArray(menujsonArray, metaList, null); |
... | ... | @@ -249,10 +254,11 @@ public class SysPermissionController { |
249 | 254 | json.put("auth", authjsonArray); |
250 | 255 | //全部权限配置集合(按钮权限,访问权限) |
251 | 256 | json.put("allAuth", allauthjsonArray); |
257 | + json.put("sysSafeMode", sysSafeMode); | |
252 | 258 | result.setResult(json); |
253 | 259 | result.success("查询成功"); |
254 | 260 | } catch (Exception e) { |
255 | - result.error500("查询失败:" + e.getMessage()); | |
261 | + result.error500("查询失败:" + e.getMessage()); | |
256 | 262 | log.error(e.getMessage(), e); |
257 | 263 | } |
258 | 264 | return result; |
... | ... | @@ -343,7 +349,7 @@ public class SysPermissionController { |
343 | 349 | |
344 | 350 | /** |
345 | 351 | * 获取全部的权限树 |
346 | - * | |
352 | + * | |
347 | 353 | * @return |
348 | 354 | */ |
349 | 355 | @RequestMapping(value = "/queryTreeList", method = RequestMethod.GET) |
... | ... | @@ -375,7 +381,7 @@ public class SysPermissionController { |
375 | 381 | |
376 | 382 | /** |
377 | 383 | * 异步加载数据节点 |
378 | - * | |
384 | + * | |
379 | 385 | * @return |
380 | 386 | */ |
381 | 387 | @RequestMapping(value = "/queryListAsync", method = RequestMethod.GET) |
... | ... | @@ -398,7 +404,7 @@ public class SysPermissionController { |
398 | 404 | |
399 | 405 | /** |
400 | 406 | * 查询角色授权 |
401 | - * | |
407 | + * | |
402 | 408 | * @return |
403 | 409 | */ |
404 | 410 | @RequestMapping(value = "/queryRolePermission", method = RequestMethod.GET) |
... | ... | @@ -416,7 +422,7 @@ public class SysPermissionController { |
416 | 422 | |
417 | 423 | /** |
418 | 424 | * 保存角色授权 |
419 | - * | |
425 | + * | |
420 | 426 | * @return |
421 | 427 | */ |
422 | 428 | @RequestMapping(value = "/saveRolePermission", method = RequestMethod.POST) |
... | ... | @@ -475,7 +481,7 @@ public class SysPermissionController { |
475 | 481 | |
476 | 482 | } |
477 | 483 | } |
478 | - | |
484 | + | |
479 | 485 | /** |
480 | 486 | * 获取权限JSON数组 |
481 | 487 | * @param jsonArray |
... | ... |