天翎MyApps技术社区 - 低代码平台 | 流程管理系统 | BPM软件

 找回密码
 注册成为天翎用户
查看: 800|回复: 0

[javascript] 根据角色编码判断当前用户是否具有下列角色(可以传多个角色编码)

[复制链接]
smart 发表于 2020-12-7 18:42:23 | 显示全部楼层 |阅读模式
本帖最后由 smart 于 2020-12-7 18:44 编辑
  1. /**
  2. *根据角色编码判断当前用户是否具有下列角色(可以传多个角色编码)
  3. *roleCode:角色编码        传多个角色编码用";"隔开
  4. */
  5. function isOwenTheRolesByRoleCodes(roleCode) {
  6.     var applicationid = getApplication();
  7.     var flag = false;
  8.     var process = new Packages.cn.myapps.runtime.role.service.RoleServiceImpl();
  9.     if (roleCode != null && !"".equals(roleCode)) {
  10.         if (roleCode.indexOf(";") >= 0) {
  11.             var roleCodes = roleCode.split(";");
  12.             if (roleCodes != null && roleCodes.length > 0) {
  13.                 for (var i = 0; i < roleCodes.length; i++) {
  14.                     var roleCodeI = roleCodes[i];
  15.                     var role1 = process.findByRoleNo(roleCodeI, applicationid);
  16.                     if (role1 != null) {
  17.                         var crRoleId = role1.getId();
  18.                         if (crRoleId != null && !"".equals(crRoleId)) {
  19.                             var roles = getWebUser().getRoles();
  20.                             for (var it = roles.iterator(); roles != null && it.hasNext(); ) {
  21.                                 var role = it.next();
  22.                                 var roleId = role.getId();
  23.                                 if (crRoleId.equals(roleId)) {
  24.                                     flag = true;
  25.                                     break;
  26.                                 }
  27.                             }
  28.                         }
  29.                     }
  30.                 }
  31.             }
  32.         } else {
  33.             var role1 = process.findByRoleNo(roleCode, applicationid);
  34.             if (role1 != null) {
  35.                 var crRoleId = role1.getId();
  36.                 if (crRoleId != null && !"".equals(crRoleId)) {
  37.                     var roles = getWebUser().getRoles();
  38.                     for (var it = roles.iterator(); roles != null && it.hasNext(); ) {
  39.                         var role = it.next();
  40.                         var roleId = role.getId();

  41.                         if (crRoleId.equals(roleId)) {
  42.                             flag = true;
  43.                             break;
  44.                         }
  45.                     }
  46.                 }
  47.             }
  48.         }
  49.     }
  50.     return flag;
  51. };
复制代码

本版积分规则

QQ|手机版|天翎MyApps技术社区 ( 粤ICP备11093750号 )

GMT+8, 2026-8-12 11:27

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表