VUE角色授权菜单时,加载慢问题解决

分享 未结 2 833
huangxin
huangxin VIP4 2020-04-28 17:37:51   最后修改:2020-05-04 14:38:59
收藏
1、在RoleMapper.xml中加一个查询方法 <!-- 查询角色的所有无下属菜单ID --> <select id="queryAllNotChildrenMenuId" resultType="String"> SELECT distinct rm.menu_id FROM sys_role a LEFT JOIN sys_role_menu rm ON a.id = rm.role_id WHERE a.id = #{id} AND (SELECT count(*) FROM sys_menu WHERE parent_id=menu_id ) = 0 </select> 2、在RoleMapper的MAPPER接口类中加: /** * 查询角色的所有无下属菜单ID * @param id * @return */ public List<String> queryAllNotChildrenMenuId(String id); 3、在RoleService中加: /** * 查询角色的所有无下属菜单ID * @param id * @return */ public List<String> queryAllNotChildrenMenuId(String id){ if(StringUtils.isNotEmpty(id)){ return mapper.queryAllNotChildrenMenuId(id); } return Lists.newArrayList(); } 4、在RoleController修改queryById方法内容改成: String newDataRuleIds = ""; if (role != null) { if (StringUtils.isNotBlank(role.getDataRuleIds())) { for (String id : role.getDataRuleIds().split(",")) { newDataRuleIds = newDataRuleIds + "dataRule-" + id + ","; } } if (newDataRuleIds.length() > 1) { role.setDataRuleIds(newDataRuleIds.substring(0, newDataRuleIds.length() - 1)); } role.setMenuIdList(roleService.queryAllNotChildrenMenuId(role.getId())); } return AjaxJson.success().put("role", role); 总结:减少遍历时间 2020-5-4修改了第一步
回帖