菜单管理功能加强,新增功能项:是否隐藏菜单(某些页面不需要显示在左侧菜单栏中),是否缓存菜单(可解决切换Tab重新渲染的问题,使用该功能必须填写组件名称,且必须与组件中的name一致)

pull/127/head
dqjdda 2019-08-27 15:58:18 +08:00
parent 8fc04d4af4
commit d6888471cd
4 changed files with 29 additions and 1 deletions

View File

@ -40,6 +40,9 @@ public class Menu implements Serializable {
private String component;
@Column(unique = true)
private String componentName;
private String icon;
@Column(columnDefinition = "bit(1) default 0")

View File

@ -23,6 +23,13 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
*/
Menu findByName(String name);
/**
* findByName
* @param name
* @return
*/
Menu findByComponentName(String name);
/**
* findByPid
* @param pid

View File

@ -31,6 +31,8 @@ public class MenuDTO {
private Boolean hidden;
private String componentName;
private String icon;
private List<MenuDTO> children;

View File

@ -1,5 +1,7 @@
package me.zhengjie.modules.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.vo.MenuMetaVo;
@ -13,6 +15,7 @@ import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
import me.zhengjie.modules.system.service.mapper.MenuMapper;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.StringUtils;
import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -58,6 +61,11 @@ public class MenuServiceImpl implements MenuService {
if(menuRepository.findByName(resources.getName()) != null){
throw new EntityExistException(Menu.class,"name",resources.getName());
}
if(StringUtils.isNotBlank(resources.getComponentName())){
if(menuRepository.findByComponentName(resources.getComponentName()) != null){
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
}
}
if(resources.getIFrame()){
if (!(resources.getPath().toLowerCase().startsWith("http://")||resources.getPath().toLowerCase().startsWith("https://"))) {
throw new BadRequestException("外链必须以http://或者https://开头");
@ -85,6 +93,13 @@ public class MenuServiceImpl implements MenuService {
if(menu1 != null && !menu1.getId().equals(menu.getId())){
throw new EntityExistException(Menu.class,"name",resources.getName());
}
if(StringUtils.isNotBlank(resources.getComponentName())){
menu1 = menuRepository.findByComponentName(resources.getComponentName());
if(menu1 != null && !menu1.getId().equals(menu.getId())){
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
}
}
menu.setName(resources.getName());
menu.setComponent(resources.getComponent());
menu.setPath(resources.getPath());
@ -94,6 +109,7 @@ public class MenuServiceImpl implements MenuService {
menu.setSort(resources.getSort());
menu.setCache(resources.getCache());
menu.setHidden(resources.getHidden());
menu.setComponentName(resources.getComponentName());
menuRepository.save(menu);
}
@ -158,7 +174,7 @@ public class MenuServiceImpl implements MenuService {
if (menuDTO!=null){
List<MenuDTO> menuDTOList = menuDTO.getChildren();
MenuVo menuVo = new MenuVo();
menuVo.setName(menuDTO.getName());
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponentName()) ? menuDTO.getComponentName() : RandomUtil.randomString(5));
menuVo.setPath(menuDTO.getPath());
menuVo.setHidden(menuDTO.getHidden());