saas-export项目-角色授权页面显示

打开授权页面显示角色名称

role-list.jsp

location.href="${path}/system/role/toRoleModule.do?roleId="+id;

RoleController

    //location.href="${path}/system/role/toRoleModule.do?roleId="+id;
    @RequestMapping(path="/toRoleModule",method ={ RequestMethod.GET, RequestMethod.POST})
    public String toRoleModule(String roleId){//接收页面提交的roleId
        //当前授权页面需要显示 角色名称
        l.info("toRoleModule roleId="+roleId);
        Role role = iRoleService.findById(roleId);

        //数据转发到页面
        request.setAttribute("role",role);
        return "system/role/role-module";
    }

页面显示效果如下图

在这里插入图片描述

页面发请求到后台获取数据

role-module.jsp

<link rel="stylesheet" type="text/css" href="${path}/plugins/ztree/css/zTreeStyle/zTreeStyle.css">
    <script type="text/javascript" src="${path}/plugins/ztree/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="${path}/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>

    <SCRIPT type="text/javascript">
        var setting = {
            check: {
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };

        $(document).ready(function(){
            var fn = function(data){
                $.fn.zTree.init($("#treeDemo"), setting, data);
            }
            $.get('${path}/system/role/getZtreeData.do?roleId=${role.roleId}',fn,'json')
        });
    </SCRIPT>

RoleController

    //$.get('${path}/system/role/getZtreeData.do?roleId=${role.roleId}',fn,'json')
    @RequestMapping(path="/getZtreeData",method ={ RequestMethod.GET, RequestMethod.POST})
    public @ResponseBody Object getZtreeData(String roleId) {//接收页面提交的roleId
        //所有的权限查询出来
        List<Module> all = iModuleService.findAllModules();
        //转换成 List<Map<String,Object>>  { id:1, pId:0, name:"Sass管理", open:true},
        List<Map<String,Object>> list = new ArrayList<>();
        //返回给页面
        for(Module m:all){
            //生成一个集合 Map<String,Object> 表示一个节点
            Map<String,Object> node = new HashMap<>();
            node.put("id",m.getModuleId());
            node.put("pId",m.getParentId());
            node.put("name",m.getName());
            node.put("open",true);
            
            //添加到集合中
            list.add(node);
        }
        return list;//@ResponseBody将list转成json
    }

页面显示效果如下图

在这里插入图片描述

对角色的权限进行勾选显示

RoleController

     @RequestMapping(path="/getZtreeData",method ={ RequestMethod.GET, RequestMethod.POST})
     public @ResponseBody
     Object getZtreeData(String roleId){
         //所有的权限查询出来
         List<Module> all = iModuleService.findAllModules();
         List<Module> myList = iModuleService.findModuleByRoleId(roleId);
         //转换成 List<Map<String,Object>>
         List<Map<String,Object>> list=new ArrayList<>();
         //返回给页面
         for (Module m:all){
             //生成一个集合 Map<String,Object> 表示一个节点
             Map<String,Object> node= new HashMap<>();
             node.put("id",m.getModuleId());
             node.put("pId",m.getParentId());
             node.put("name",m.getName());
             node.put("open",true);
             if(isInMyList(m,myList)) {
                 node.put("checked", true);
             }
             //添加到集合中
             list.add(node);
         }
         return list;//@ResponseBody将list转成json
     }

    //需要判断m是否在myList里面,如果在表示该角色有这个权限,否则没有
    private boolean isInMyList(Module m, List<Module> myList) {
         for (Module my:myList) {
             if(m.getModuleId().equals(my.getModuleId())){
                 l.info("isInMyList  moduleId1  "+m.getModuleId()+" "+m.getName());
                 l.info("isInMyList  moduleId2  "+my.getModuleId()+" "+my.getName());
                 return true;
             }
         }
         return false;
    }

IModuleService

List<Module> findModuleByRoleId(String roleId);

ModuleServiceImpl

@Override
    public List<Module> findModuleByRoleId(String roleId) {
        List<Module> list=dao.findByRoleId(roleId);
        return list;
    }

IModuleDao

List<Module> findByRoleId(String roleId);

IModuleDao.xml

<select id="findByRoleId" parameterType="string" resultMap="moduleMap">
        select * from pe_role_module rm inner join ss_module m
        on rm.module_id=m.module_id
        where rm.role_id=#{roleId}
    </select>

最终角色授权页面显示

  • 下图是鼓励师角色的授权页面
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值