授权首页菜单后,自定义首页功能不生效 #3069

dev
zhangdaiscott 4 years ago
parent 6fb01abbc5
commit ef97f700ab

@ -1,5 +1,7 @@
package org.jeecg.common.constant.enums; package org.jeecg.common.constant.enums;
import java.util.List;
/** /**
* *
* *
@ -64,6 +66,17 @@ public enum RoleIndexConfigEnum {
return null; return null;
} }
public static String getIndexByRoles(List<String> roles) {
for (String role : roles) {
for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) {
if (e.roleCode.equals(role)) {
return e.componentUrl;
}
}
}
return null;
}
public String getRoleCode() { public String getRoleCode() {
return roleCode; return roleCode;
} }

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.RoleIndexConfigEnum; import org.jeecg.common.constant.enums.RoleIndexConfigEnum;
@ -22,6 +23,7 @@ import org.jeecg.modules.system.model.TreeModel;
import org.jeecg.modules.system.service.*; import org.jeecg.modules.system.service.*;
import org.jeecg.modules.system.util.PermissionDataUtil; import org.jeecg.modules.system.util.PermissionDataUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.*; import java.util.*;
@ -54,6 +56,12 @@ public class SysPermissionController {
@Autowired @Autowired
private ISysUserService sysUserService; private ISysUserService sysUserService;
/**
* truefalse
*/
@Value(value = "${jeecg.safeMode:false}")
private Boolean sysSafeMode;
/** /**
* *
@ -215,21 +223,18 @@ public class SysPermissionController {
//update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存 //update-begin-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
if(!PermissionDataUtil.hasIndexPage(metaList)){ if(!PermissionDataUtil.hasIndexPage(metaList)){
SysPermission indexMenu = sysPermissionService.list(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getName,"首页")).get(0); SysPermission indexMenu = sysPermissionService.list(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getName,"首页")).get(0);
metaList.add(0,indexMenu);
}
//update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
//update-begin--Author:liusq Date:20210624 for:自定义首页地址LOWCOD-1578 //update-begin--Author:liusq Date:20210624 for:自定义首页地址LOWCOD-1578
List<String> roles = sysUserService.getRole(loginUser.getUsername()); List<String> roles = sysUserService.getRole(loginUser.getUsername());
if(roles.size()>0){ String compUrl = RoleIndexConfigEnum.getIndexByRoles(roles);
for (String code:roles) { if(StringUtils.isNotBlank(compUrl)){
String componentUrl = RoleIndexConfigEnum.getIndexByCode(code); List<SysPermission> menus = metaList.stream().filter(sysPermission -> "首页".equals(sysPermission.getName())).collect(Collectors.toList());
if(StringUtils.isNotBlank(componentUrl)){ menus.get(0).setComponent(compUrl);
indexMenu.setComponent(componentUrl);
break;
}
}
} }
//update-end--Author:liusq Date:20210624 for自定义首页地址LOWCOD-1578 //update-end--Author:liusq Date:20210624 for自定义首页地址LOWCOD-1578
metaList.add(0,indexMenu);
}
//update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
JSONArray menujsonArray = new JSONArray(); JSONArray menujsonArray = new JSONArray();
this.getPermissionJsonArray(menujsonArray, metaList, null); this.getPermissionJsonArray(menujsonArray, metaList, null);
@ -249,6 +254,7 @@ public class SysPermissionController {
json.put("auth", authjsonArray); json.put("auth", authjsonArray);
//全部权限配置集合(按钮权限,访问权限) //全部权限配置集合(按钮权限,访问权限)
json.put("allAuth", allauthjsonArray); json.put("allAuth", allauthjsonArray);
json.put("sysSafeMode", sysSafeMode);
result.setResult(json); result.setResult(json);
result.success("查询成功"); result.success("查询成功");
} catch (Exception e) { } catch (Exception e) {

Loading…
Cancel
Save