Commit 505660cfdf1461a1a43bf0563193e35ea213a369
1 parent
0c19b627
自定义首页
Showing
4 changed files
with
156 additions
and
38 deletions
juvenile-prosecution-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/enums/RoleIndexConfigEnum.java
0 → 100644
| 1 | +package org.jeecg.common.constant.enums; | |
| 2 | + | |
| 3 | +import org.jeecg.common.util.oConvertUtils; | |
| 4 | + | |
| 5 | +import java.util.List; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 首页自定义 | |
| 9 | + * 通过角色编码与首页组件路径配置 | |
| 10 | + * 枚举的顺序有权限高低权重作用(也就是配置多个角色,在前面的角色首页,会优先生效) | |
| 11 | + */ | |
| 12 | +public enum RoleIndexConfigEnum { | |
| 13 | + | |
| 14 | + ADMIN("admin", "business/MinorList"), | |
| 15 | + //TEST("test", "dashboard/IndexChart"), | |
| 16 | + HR("hr", "dashboard/IndexBdc"); | |
| 17 | + //DM("dm", "dashboard/IndexTask"), | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 角色编码 | |
| 21 | + */ | |
| 22 | + String roleCode; | |
| 23 | + /** | |
| 24 | + * 路由index | |
| 25 | + */ | |
| 26 | + String componentUrl; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 构造器 | |
| 30 | + * | |
| 31 | + * @param roleCode 角色编码 | |
| 32 | + * @param componentUrl 首页组件路径(规则跟菜单配置一样) | |
| 33 | + */ | |
| 34 | + RoleIndexConfigEnum(String roleCode, String componentUrl) { | |
| 35 | + this.roleCode = roleCode; | |
| 36 | + this.componentUrl = componentUrl; | |
| 37 | + } | |
| 38 | + /** | |
| 39 | + * 根据code找枚举 | |
| 40 | + * @param roleCode 角色编码 | |
| 41 | + * @return | |
| 42 | + */ | |
| 43 | + private static RoleIndexConfigEnum getEnumByCode(String roleCode) { | |
| 44 | + for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { | |
| 45 | + if (e.roleCode.equals(roleCode)) { | |
| 46 | + return e; | |
| 47 | + } | |
| 48 | + } | |
| 49 | + return null; | |
| 50 | + } | |
| 51 | + /** | |
| 52 | + * 根据code找index | |
| 53 | + * @param roleCode 角色编码 | |
| 54 | + * @return | |
| 55 | + */ | |
| 56 | + private static String getIndexByCode(String roleCode) { | |
| 57 | + for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { | |
| 58 | + if (e.roleCode.equals(roleCode)) { | |
| 59 | + return e.componentUrl; | |
| 60 | + } | |
| 61 | + } | |
| 62 | + return null; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public static String getIndexByRoles(List<String> roles) { | |
| 66 | + String[] rolesArray = roles.toArray(new String[roles.size()]); | |
| 67 | + for (RoleIndexConfigEnum e : RoleIndexConfigEnum.values()) { | |
| 68 | + if (oConvertUtils.isIn(e.roleCode,rolesArray)){ | |
| 69 | + return e.componentUrl; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + return null; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public String getRoleCode() { | |
| 76 | + return roleCode; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public void setRoleCode(String roleCode) { | |
| 80 | + this.roleCode = roleCode; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public String getComponentUrl() { | |
| 84 | + return componentUrl; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public void setComponentUrl(String componentUrl) { | |
| 88 | + this.componentUrl = componentUrl; | |
| 89 | + } | |
| 90 | +} | ... | ... |
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; |
| 5 | 5 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 6 | 6 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 7 | 7 | import lombok.extern.slf4j.Slf4j; |
| 8 | +import org.apache.commons.lang3.StringUtils; | |
| 8 | 9 | import org.apache.shiro.SecurityUtils; |
| 9 | 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; |
| 13 | +import org.jeecg.common.constant.enums.RoleIndexConfigEnum; | |
| 12 | 14 | import org.jeecg.common.system.util.JwtUtil; |
| 15 | +import org.jeecg.common.system.vo.DictModel; | |
| 13 | 16 | import org.jeecg.common.system.vo.LoginUser; |
| 14 | 17 | import org.jeecg.common.util.MD5Util; |
| 15 | 18 | import org.jeecg.common.util.oConvertUtils; |
| ... | ... | @@ -52,6 +55,13 @@ public class SysPermissionController { |
| 52 | 55 | @Autowired |
| 53 | 56 | private ISysDepartPermissionService sysDepartPermissionService; |
| 54 | 57 | |
| 58 | + @Autowired | |
| 59 | + private ISysDictService sysDictItemService; | |
| 60 | + | |
| 61 | + @Autowired | |
| 62 | + private ISysUserService sysUserService; | |
| 63 | + | |
| 64 | + | |
| 55 | 65 | /** |
| 56 | 66 | * 加载数据节点 |
| 57 | 67 | * |
| ... | ... | @@ -214,10 +224,39 @@ public class SysPermissionController { |
| 214 | 224 | SysPermission indexMenu = sysPermissionService.list(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getName,"首页")).get(0); |
| 215 | 225 | metaList.add(0,indexMenu); |
| 216 | 226 | } |
| 227 | + //update-begin--Author:wxy Date:20220727 for:自定义首页地址LOWCOD-1578 | |
| 228 | + List<String> roles = sysUserService.getRole(loginUser.getUsername()); | |
| 229 | + //改为字典表内取 | |
| 230 | + List<DictModel> list=sysDictItemService.queryDictItemsByCode("access_home_page"); | |
| 231 | + String compUrl=""; | |
| 232 | + if(list!=null&&list.size()>0){ | |
| 233 | + for (String role:roles) { | |
| 234 | + for (DictModel dictModel:list) { | |
| 235 | + if(dictModel.getValue().equals(role)){ | |
| 236 | + compUrl=dictModel.getText(); | |
| 237 | + break; | |
| 238 | + } | |
| 239 | + } | |
| 240 | + } | |
| 241 | + | |
| 242 | + }else { | |
| 243 | + compUrl = RoleIndexConfigEnum.getIndexByRoles(roles); | |
| 244 | + } | |
| 245 | + if("".equals(compUrl)){ | |
| 246 | + compUrl = RoleIndexConfigEnum.getIndexByRoles(roles); | |
| 247 | + } | |
| 248 | + if(StringUtils.isNotBlank(compUrl)){ | |
| 249 | + List<SysPermission> menus = metaList.stream().filter(sysPermission -> "首页".equals(sysPermission.getName())).collect(Collectors.toList()); | |
| 250 | + menus.get(0).setComponent(compUrl); | |
| 251 | + } | |
| 252 | + //update-begin--Author:wxy Date:20220727 for:自定义首页地址LOWCOD-1578 | |
| 217 | 253 | //update-end-author:taoyan date:20200211 for: TASK #3368 【路由缓存】首页的缓存设置有问题,需要根据后台的路由配置来实现是否缓存 |
| 218 | 254 | JSONObject json = new JSONObject(); |
| 219 | 255 | JSONArray menujsonArray = new JSONArray(); |
| 220 | 256 | this.getPermissionJsonArray(menujsonArray, metaList, null); |
| 257 | + //一级菜单下的子菜单全部是隐藏路由,则一级菜单不显示 | |
| 258 | + this.handleFirstLevelMenuHidden(menujsonArray); | |
| 259 | + | |
| 221 | 260 | JSONArray authjsonArray = new JSONArray(); |
| 222 | 261 | this.getAuthJsonArray(authjsonArray, metaList); |
| 223 | 262 | //查询所有的权限 |
| ... | ... | @@ -244,6 +283,30 @@ public class SysPermissionController { |
| 244 | 283 | } |
| 245 | 284 | |
| 246 | 285 | /** |
| 286 | + * 一级菜单的子菜单全部是隐藏路由,则一级菜单不显示 | |
| 287 | + * @param jsonArray | |
| 288 | + */ | |
| 289 | + private void handleFirstLevelMenuHidden(JSONArray jsonArray) { | |
| 290 | + jsonArray = jsonArray.stream().map(obj -> { | |
| 291 | + JSONObject returnObj = new JSONObject(); | |
| 292 | + JSONObject jsonObj = (JSONObject)obj; | |
| 293 | + if(jsonObj.containsKey("children")){ | |
| 294 | + JSONArray childrens = jsonObj.getJSONArray("children"); | |
| 295 | + childrens = childrens.stream().filter(arrObj -> !"true".equals(((JSONObject) arrObj).getString("hidden"))).collect(Collectors.toCollection(JSONArray::new)); | |
| 296 | + if(childrens==null || childrens.size()==0){ | |
| 297 | + jsonObj.put("hidden",true); | |
| 298 | + | |
| 299 | + //vue3版本兼容代码 | |
| 300 | + JSONObject meta = new JSONObject(); | |
| 301 | + meta.put("hideMenu",true); | |
| 302 | + jsonObj.put("meta", meta); | |
| 303 | + } | |
| 304 | + } | |
| 305 | + return returnObj; | |
| 306 | + }).collect(Collectors.toCollection(JSONArray::new)); | |
| 307 | + } | |
| 308 | + | |
| 309 | + /** | |
| 247 | 310 | * 添加菜单 |
| 248 | 311 | * @param permission |
| 249 | 312 | * @return | ... | ... |
juvenile-prosecution-boot/jeecg-boot-module-system/target/classes/org/jeecg/modules/system/controller/SysPermissionController.class
No preview for this file type
juvenile-prosecution-vue/src/views/system/modules/UserModal.vue
| ... | ... | @@ -30,7 +30,7 @@ |
| 30 | 30 | <a-form-model-item label="登录密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="password" > |
| 31 | 31 | <a-input type="password" placeholder="请输入登录密码" v-model="model.password" /> |
| 32 | 32 | </a-form-model-item> |
| 33 | - | |
| 33 | + | |
| 34 | 34 | <a-form-model-item label="确认密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="confirmpassword" > |
| 35 | 35 | <a-input type="password" @blur="handleConfirmBlur" placeholder="请重新输入登录密码" v-model="model.confirmpassword"/> |
| 36 | 36 | </a-form-model-item> |
| ... | ... | @@ -40,14 +40,6 @@ |
| 40 | 40 | <a-input placeholder="请输入用户姓名" v-model="model.realname" /> |
| 41 | 41 | </a-form-model-item> |
| 42 | 42 | |
| 43 | - <a-form-model-item label="工号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workNo"> | |
| 44 | - <a-input placeholder="请输入工号" v-model="model.workNo" /> | |
| 45 | - </a-form-model-item> | |
| 46 | - | |
| 47 | - <a-form-model-item label="职务" :labelCol="labelCol" :wrapperCol="wrapperCol"> | |
| 48 | - <j-select-position placeholder="请选择职务" :multiple="false" v-model="model.post"/> | |
| 49 | - </a-form-model-item> | |
| 50 | - | |
| 51 | 43 | <a-form-model-item label="角色分配" :labelCol="labelCol" :wrapperCol="wrapperCol" v-show="!roleDisabled" > |
| 52 | 44 | <j-multi-select-tag |
| 53 | 45 | :disabled="disableSubmit" |
| ... | ... | @@ -58,34 +50,11 @@ |
| 58 | 50 | </a-form-model-item> |
| 59 | 51 | |
| 60 | 52 | <!--部门分配--> |
| 61 | - <a-form-model-item label="部门分配" :labelCol="labelCol" :wrapperCol="wrapperCol" v-show="!departDisabled"> | |
| 53 | + <a-form-model-item label="单位分配" :labelCol="labelCol" :wrapperCol="wrapperCol" v-show="!departDisabled"> | |
| 62 | 54 | <j-select-depart v-model="model.selecteddeparts" :multi="true" @back="backDepartInfo" :backDepart="true"></j-select-depart> |
| 63 | 55 | </a-form-model-item> |
| 64 | 56 | |
| 65 | - <!--租户分配--> | |
| 66 | - <a-form-model-item label="租户分配" :labelCol="labelCol" :wrapperCol="wrapperCol" v-show="!departDisabled"> | |
| 67 | - <j-multi-select-tag | |
| 68 | - :disabled="disableSubmit" | |
| 69 | - v-model="model.relTenantIds" | |
| 70 | - :options="tenantsOptions" | |
| 71 | - placeholder="请选择租户"> | |
| 72 | - </j-multi-select-tag> | |
| 73 | - </a-form-model-item> | |
| 74 | 57 | |
| 75 | - <a-form-model-item label="身份" :labelCol="labelCol" :wrapperCol="wrapperCol"> | |
| 76 | - <a-radio-group v-model="model.userIdentity" @change="identityChange"> | |
| 77 | - <a-radio :value="1">普通用户</a-radio> | |
| 78 | - <a-radio :value="2">上级</a-radio> | |
| 79 | - </a-radio-group> | |
| 80 | - </a-form-model-item> | |
| 81 | - <a-form-model-item label="负责部门" :labelCol="labelCol" :wrapperCol="wrapperCol" v-if="departIdShow==true"> | |
| 82 | - <j-multi-select-tag | |
| 83 | - :disabled="disableSubmit" | |
| 84 | - v-model="model.departIds" | |
| 85 | - :options="nextDepartOptions" | |
| 86 | - placeholder="请选择负责部门"> | |
| 87 | - </j-multi-select-tag> | |
| 88 | - </a-form-model-item> | |
| 89 | 58 | |
| 90 | 59 | <a-form-model-item label="头像" :labelCol="labelCol" :wrapperCol="wrapperCol"> |
| 91 | 60 | <j-image-upload class="avatar-uploader" text="上传" v-model="model.avatar" ></j-image-upload> |
| ... | ... | @@ -99,7 +68,7 @@ |
| 99 | 68 | :format="dateFormat" |
| 100 | 69 | :getCalendarContainer="node => node.parentNode"/> |
| 101 | 70 | </a-form-model-item> |
| 102 | - | |
| 71 | + | |
| 103 | 72 | <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol"> |
| 104 | 73 | <a-select v-model="model.sex" placeholder="请选择性别" :getPopupContainer= "(target) => target.parentNode"> |
| 105 | 74 | <a-select-option :value="1">男</a-select-option> |
| ... | ... | @@ -119,10 +88,6 @@ |
| 119 | 88 | <a-input placeholder="请输入座机" v-model="model.telephone" /> |
| 120 | 89 | </a-form-model-item> |
| 121 | 90 | |
| 122 | - <a-form-model-item label="工作流引擎" :labelCol="labelCol" :wrapperCol="wrapperCol"> | |
| 123 | - <j-dict-select-tag v-model="model.activitiSync" placeholder="请选择是否同步工作流引擎" :type="'radio'" dictCode="activiti_sync"/> | |
| 124 | - </a-form-model-item> | |
| 125 | - | |
| 126 | 91 | </a-form-model> |
| 127 | 92 | </a-spin> |
| 128 | 93 | ... | ... |