update 优化 SysMenu 相关代码
This commit is contained in:
parent
e8225fbdee
commit
e8483729b1
@ -157,6 +157,10 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
|||||||
return BeanCopyUtils.copy(obj, voClass);
|
return BeanCopyUtils.copy(obj, voClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<V> selectVoList() {
|
||||||
|
return selectVoList(new QueryWrapper<>(), this.currentVoClass());
|
||||||
|
}
|
||||||
|
|
||||||
default List<V> selectVoList(Wrapper<T> wrapper) {
|
default List<V> selectVoList(Wrapper<T> wrapper) {
|
||||||
return selectVoList(wrapper, this.currentVoClass());
|
return selectVoList(wrapper, this.currentVoClass());
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,22 @@
|
|||||||
package com.ruoyi.system.controller.system;
|
package com.ruoyi.system.controller.system;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import com.ruoyi.common.log.annotation.Log;
|
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.web.core.BaseController;
|
|
||||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.system.domain.SysDictType;
|
|
||||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
|
||||||
import com.ruoyi.common.log.enums.BusinessType;
|
|
||||||
import com.ruoyi.common.excel.utils.ExcelUtil;
|
import com.ruoyi.common.excel.utils.ExcelUtil;
|
||||||
|
import com.ruoyi.common.log.annotation.Log;
|
||||||
|
import com.ruoyi.common.log.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||||
|
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.web.core.BaseController;
|
||||||
import com.ruoyi.system.domain.bo.SysDictTypeBo;
|
import com.ruoyi.system.domain.bo.SysDictTypeBo;
|
||||||
import com.ruoyi.system.domain.vo.SysDictTypeVo;
|
import com.ruoyi.system.domain.vo.SysDictTypeVo;
|
||||||
import com.ruoyi.system.service.ISysDictTypeService;
|
import com.ruoyi.system.service.ISysDictTypeService;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,8 +119,8 @@ public class SysDictTypeController extends BaseController {
|
|||||||
* 获取字典选择框列表
|
* 获取字典选择框列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/optionselect")
|
@GetMapping("/optionselect")
|
||||||
public R<List<SysDictType>> optionselect() {
|
public R<List<SysDictTypeVo>> optionselect() {
|
||||||
List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll();
|
List<SysDictTypeVo> dictTypes = dictTypeService.selectDictTypeAll();
|
||||||
return R.ok(dictTypes);
|
return R.ok(dictTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,10 @@ import cn.hutool.core.lang.tree.Tree;
|
|||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.web.core.BaseController;
|
|
||||||
import com.ruoyi.common.log.annotation.Log;
|
import com.ruoyi.common.log.annotation.Log;
|
||||||
import com.ruoyi.common.log.enums.BusinessType;
|
import com.ruoyi.common.log.enums.BusinessType;
|
||||||
import com.ruoyi.common.satoken.utils.LoginHelper;
|
import com.ruoyi.common.satoken.utils.LoginHelper;
|
||||||
import com.ruoyi.system.domain.SysMenu;
|
import com.ruoyi.common.web.core.BaseController;
|
||||||
import com.ruoyi.system.domain.bo.SysMenuBo;
|
import com.ruoyi.system.domain.bo.SysMenuBo;
|
||||||
import com.ruoyi.system.domain.vo.SysMenuVo;
|
import com.ruoyi.system.domain.vo.SysMenuVo;
|
||||||
import com.ruoyi.system.service.ISysMenuService;
|
import com.ruoyi.system.service.ISysMenuService;
|
||||||
@ -38,8 +37,8 @@ public class SysMenuController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@SaCheckPermission("system:menu:list")
|
@SaCheckPermission("system:menu:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public R<List<SysMenu>> list(SysMenu menu) {
|
public R<List<SysMenuVo>> list(SysMenuBo menu) {
|
||||||
List<SysMenu> menus = menuService.selectMenuList(menu, LoginHelper.getUserId());
|
List<SysMenuVo> menus = menuService.selectMenuList(menu, LoginHelper.getUserId());
|
||||||
return R.ok(menus);
|
return R.ok(menus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +57,8 @@ public class SysMenuController extends BaseController {
|
|||||||
* 获取菜单下拉树列表
|
* 获取菜单下拉树列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/treeselect")
|
@GetMapping("/treeselect")
|
||||||
public R<List<Tree<Long>>> treeselect(SysMenu menu) {
|
public R<List<Tree<Long>>> treeselect(SysMenuBo menu) {
|
||||||
List<SysMenu> menus = menuService.selectMenuList(menu, LoginHelper.getUserId());
|
List<SysMenuVo> menus = menuService.selectMenuList(menu, LoginHelper.getUserId());
|
||||||
return R.ok(menuService.buildMenuTreeSelect(menus));
|
return R.ok(menuService.buildMenuTreeSelect(menus));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ public class SysMenuController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
||||||
public R<Map<String, Object>> roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
|
public R<Map<String, Object>> roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
|
||||||
List<SysMenu> menus = menuService.selectMenuList(LoginHelper.getUserId());
|
List<SysMenuVo> menus = menuService.selectMenuList(LoginHelper.getUserId());
|
||||||
return R.ok(Map.of(
|
return R.ok(Map.of(
|
||||||
"checkedKeys", menuService.selectMenuListByRoleId(roleId),
|
"checkedKeys", menuService.selectMenuListByRoleId(roleId),
|
||||||
"menus", menuService.buildMenuTreeSelect(menus)
|
"menus", menuService.buildMenuTreeSelect(menus)
|
||||||
|
@ -2,15 +2,13 @@ package com.ruoyi.system.domain;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.mybatis.core.domain.TreeEntity;
|
import com.ruoyi.common.mybatis.core.domain.TreeEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单权限表 sys_menu
|
* 菜单权限表 sys_menu
|
||||||
*
|
*
|
||||||
@ -93,4 +91,80 @@ public class SysMenu extends TreeEntity<SysMenu> {
|
|||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取路由名称
|
||||||
|
*/
|
||||||
|
public String getRouteName() {
|
||||||
|
String routerName = StringUtils.capitalize(path);
|
||||||
|
// 非外链并且是一级目录(类型为目录)
|
||||||
|
if (isMenuFrame()) {
|
||||||
|
routerName = StringUtils.EMPTY;
|
||||||
|
}
|
||||||
|
return routerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取路由地址
|
||||||
|
*/
|
||||||
|
public String getRouterPath() {
|
||||||
|
String routerPath = this.path;
|
||||||
|
// 内链打开外网方式
|
||||||
|
if (getParentId() != 0L && isInnerLink()) {
|
||||||
|
routerPath = innerLinkReplaceEach(routerPath);
|
||||||
|
}
|
||||||
|
// 非外链并且是一级目录(类型为目录)
|
||||||
|
if (0L == getParentId() && UserConstants.TYPE_DIR.equals(getMenuType())
|
||||||
|
&& UserConstants.NO_FRAME.equals(getIsFrame())) {
|
||||||
|
routerPath = "/" + this.path;
|
||||||
|
}
|
||||||
|
// 非外链并且是一级目录(类型为菜单)
|
||||||
|
else if (isMenuFrame()) {
|
||||||
|
routerPath = "/";
|
||||||
|
}
|
||||||
|
return routerPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取组件信息
|
||||||
|
*/
|
||||||
|
public String getComponent() {
|
||||||
|
String component = UserConstants.LAYOUT;
|
||||||
|
if (StringUtils.isNotEmpty(this.component) && !isMenuFrame()) {
|
||||||
|
component = this.component;
|
||||||
|
} else if (StringUtils.isEmpty(this.component) && getParentId() != 0L && isInnerLink()) {
|
||||||
|
component = UserConstants.INNER_LINK;
|
||||||
|
} else if (StringUtils.isEmpty(this.component) && isParentView()) {
|
||||||
|
component = UserConstants.PARENT_VIEW;
|
||||||
|
}
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为菜单内部跳转
|
||||||
|
*/
|
||||||
|
public boolean isMenuFrame() {
|
||||||
|
return getParentId() == 0L && UserConstants.TYPE_MENU.equals(menuType) && isFrame.equals(UserConstants.NO_FRAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为内链组件
|
||||||
|
*/
|
||||||
|
public boolean isInnerLink() {
|
||||||
|
return isFrame.equals(UserConstants.NO_FRAME) && StringUtils.ishttp(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为parent_view组件
|
||||||
|
*/
|
||||||
|
public boolean isParentView() {
|
||||||
|
return getParentId() != 0L && UserConstants.TYPE_DIR.equals(menuType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内链域名特殊字符替换
|
||||||
|
*/
|
||||||
|
public static String innerLinkReplaceEach(String path) {
|
||||||
|
return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."},
|
||||||
|
new String[]{"", "", "", "/"});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,9 @@ import lombok.Data;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,4 +106,9 @@ public class SysMenuVo implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子菜单
|
||||||
|
*/
|
||||||
|
private List<SysMenuVo> children = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.ruoyi.system.service;
|
package com.ruoyi.system.service;
|
||||||
|
|
||||||
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
import com.ruoyi.common.mybatis.core.page.PageQuery;
|
||||||
import com.ruoyi.system.domain.SysDictType;
|
|
||||||
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||||
import com.ruoyi.system.domain.bo.SysDictTypeBo;
|
import com.ruoyi.system.domain.bo.SysDictTypeBo;
|
||||||
import com.ruoyi.system.domain.vo.SysDictDataVo;
|
import com.ruoyi.system.domain.vo.SysDictDataVo;
|
||||||
@ -32,7 +31,7 @@ public interface ISysDictTypeService {
|
|||||||
*
|
*
|
||||||
* @return 字典类型集合信息
|
* @return 字典类型集合信息
|
||||||
*/
|
*/
|
||||||
List<SysDictType> selectDictTypeAll();
|
List<SysDictTypeVo> selectDictTypeAll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据字典类型查询字典数据
|
* 根据字典类型查询字典数据
|
||||||
|
@ -22,7 +22,7 @@ public interface ISysMenuService {
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
List<SysMenu> selectMenuList(Long userId);
|
List<SysMenuVo> selectMenuList(Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户查询系统菜单列表
|
* 根据用户查询系统菜单列表
|
||||||
@ -31,7 +31,7 @@ public interface ISysMenuService {
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
List<SysMenu> selectMenuList(SysMenu menu, Long userId);
|
List<SysMenuVo> selectMenuList(SysMenuBo menu, Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID查询权限
|
* 根据用户ID查询权限
|
||||||
@ -79,7 +79,7 @@ public interface ISysMenuService {
|
|||||||
* @param menus 菜单列表
|
* @param menus 菜单列表
|
||||||
* @return 下拉树结构列表
|
* @return 下拉树结构列表
|
||||||
*/
|
*/
|
||||||
List<Tree<Long>> buildMenuTreeSelect(List<SysMenu> menus);
|
List<Tree<Long>> buildMenuTreeSelect(List<SysMenuVo> menus);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据菜单ID查询信息
|
* 根据菜单ID查询信息
|
||||||
|
@ -84,8 +84,8 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
|||||||
* @return 字典类型集合信息
|
* @return 字典类型集合信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysDictType> selectDictTypeAll() {
|
public List<SysDictTypeVo> selectDictTypeAll() {
|
||||||
return baseMapper.selectList();
|
return baseMapper.selectVoList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,8 +7,8 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.ruoyi.common.core.constant.Constants;
|
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.utils.BeanCopyUtils;
|
||||||
import com.ruoyi.common.core.utils.StreamUtils;
|
import com.ruoyi.common.core.utils.StreamUtils;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.core.utils.TreeBuildUtils;
|
import com.ruoyi.common.core.utils.TreeBuildUtils;
|
||||||
@ -49,8 +49,8 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysMenu> selectMenuList(Long userId) {
|
public List<SysMenuVo> selectMenuList(Long userId) {
|
||||||
return selectMenuList(new SysMenu(), userId);
|
return selectMenuList(new SysMenuBo(), userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,11 +60,11 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
* @return 菜单列表
|
* @return 菜单列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysMenu> selectMenuList(SysMenu menu, Long userId) {
|
public List<SysMenuVo> selectMenuList(SysMenuBo menu, Long userId) {
|
||||||
List<SysMenu> menuList = null;
|
List<SysMenuVo> menuList;
|
||||||
// 管理员显示所有菜单信息
|
// 管理员显示所有菜单信息
|
||||||
if (LoginHelper.isAdmin(userId)) {
|
if (LoginHelper.isAdmin(userId)) {
|
||||||
menuList = baseMapper.selectList(new LambdaQueryWrapper<SysMenu>()
|
menuList = baseMapper.selectVoList(new LambdaQueryWrapper<SysMenu>()
|
||||||
.like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName())
|
.like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName())
|
||||||
.eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible())
|
.eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible())
|
||||||
.eq(StringUtils.isNotBlank(menu.getStatus()), SysMenu::getStatus, menu.getStatus())
|
.eq(StringUtils.isNotBlank(menu.getStatus()), SysMenu::getStatus, menu.getStatus())
|
||||||
@ -78,7 +78,8 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
.eq(StringUtils.isNotBlank(menu.getStatus()), "m.status", menu.getStatus())
|
.eq(StringUtils.isNotBlank(menu.getStatus()), "m.status", menu.getStatus())
|
||||||
.orderByAsc("m.parent_id")
|
.orderByAsc("m.parent_id")
|
||||||
.orderByAsc("m.order_num");
|
.orderByAsc("m.order_num");
|
||||||
menuList = baseMapper.selectMenuListByUserId(wrapper);
|
List<SysMenu> list = baseMapper.selectMenuListByUserId(wrapper);
|
||||||
|
menuList = BeanCopyUtils.copyList(list, SysMenuVo.class);
|
||||||
}
|
}
|
||||||
return menuList;
|
return menuList;
|
||||||
}
|
}
|
||||||
@ -127,7 +128,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysMenu> selectMenuTreeByUserId(Long userId) {
|
public List<SysMenu> selectMenuTreeByUserId(Long userId) {
|
||||||
List<SysMenu> menus = null;
|
List<SysMenu> menus;
|
||||||
if (LoginHelper.isAdmin(userId)) {
|
if (LoginHelper.isAdmin(userId)) {
|
||||||
menus = baseMapper.selectMenuTreeAll();
|
menus = baseMapper.selectMenuTreeAll();
|
||||||
} else {
|
} else {
|
||||||
@ -160,9 +161,9 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
for (SysMenu menu : menus) {
|
for (SysMenu menu : menus) {
|
||||||
RouterVo router = new RouterVo();
|
RouterVo router = new RouterVo();
|
||||||
router.setHidden("1".equals(menu.getVisible()));
|
router.setHidden("1".equals(menu.getVisible()));
|
||||||
router.setName(getRouteName(menu));
|
router.setName(menu.getRouteName());
|
||||||
router.setPath(getRouterPath(menu));
|
router.setPath(menu.getRouterPath());
|
||||||
router.setComponent(getComponent(menu));
|
router.setComponent(menu.getComponent());
|
||||||
router.setQuery(menu.getQueryParam());
|
router.setQuery(menu.getQueryParam());
|
||||||
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
||||||
List<SysMenu> cMenus = menu.getChildren();
|
List<SysMenu> cMenus = menu.getChildren();
|
||||||
@ -170,7 +171,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
router.setAlwaysShow(true);
|
router.setAlwaysShow(true);
|
||||||
router.setRedirect("noRedirect");
|
router.setRedirect("noRedirect");
|
||||||
router.setChildren(buildMenus(cMenus));
|
router.setChildren(buildMenus(cMenus));
|
||||||
} else if (isMenuFrame(menu)) {
|
} else if (menu.isMenuFrame()) {
|
||||||
router.setMeta(null);
|
router.setMeta(null);
|
||||||
List<RouterVo> childrenList = new ArrayList<>();
|
List<RouterVo> childrenList = new ArrayList<>();
|
||||||
RouterVo children = new RouterVo();
|
RouterVo children = new RouterVo();
|
||||||
@ -181,12 +182,12 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
children.setQuery(menu.getQueryParam());
|
children.setQuery(menu.getQueryParam());
|
||||||
childrenList.add(children);
|
childrenList.add(children);
|
||||||
router.setChildren(childrenList);
|
router.setChildren(childrenList);
|
||||||
} else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) {
|
} else if (menu.getParentId().intValue() == 0 && menu.isInnerLink()) {
|
||||||
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
|
||||||
router.setPath("/");
|
router.setPath("/");
|
||||||
List<RouterVo> childrenList = new ArrayList<>();
|
List<RouterVo> childrenList = new ArrayList<>();
|
||||||
RouterVo children = new RouterVo();
|
RouterVo children = new RouterVo();
|
||||||
String routerPath = innerLinkReplaceEach(menu.getPath());
|
String routerPath = SysMenu.innerLinkReplaceEach(menu.getPath());
|
||||||
children.setPath(routerPath);
|
children.setPath(routerPath);
|
||||||
children.setComponent(UserConstants.INNER_LINK);
|
children.setComponent(UserConstants.INNER_LINK);
|
||||||
children.setName(StringUtils.capitalize(routerPath));
|
children.setName(StringUtils.capitalize(routerPath));
|
||||||
@ -206,7 +207,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
* @return 下拉树结构列表
|
* @return 下拉树结构列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Tree<Long>> buildMenuTreeSelect(List<SysMenu> menus) {
|
public List<Tree<Long>> buildMenuTreeSelect(List<SysMenuVo> menus) {
|
||||||
if (CollUtil.isEmpty(menus)) {
|
if (CollUtil.isEmpty(menus)) {
|
||||||
return CollUtil.newArrayList();
|
return CollUtil.newArrayList();
|
||||||
}
|
}
|
||||||
@ -303,94 +304,6 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
return UserConstants.UNIQUE;
|
return UserConstants.UNIQUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取路由名称
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 路由名称
|
|
||||||
*/
|
|
||||||
public String getRouteName(SysMenu menu) {
|
|
||||||
String routerName = StringUtils.capitalize(menu.getPath());
|
|
||||||
// 非外链并且是一级目录(类型为目录)
|
|
||||||
if (isMenuFrame(menu)) {
|
|
||||||
routerName = StringUtils.EMPTY;
|
|
||||||
}
|
|
||||||
return routerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取路由地址
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 路由地址
|
|
||||||
*/
|
|
||||||
public String getRouterPath(SysMenu menu) {
|
|
||||||
String routerPath = menu.getPath();
|
|
||||||
// 内链打开外网方式
|
|
||||||
if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) {
|
|
||||||
routerPath = innerLinkReplaceEach(routerPath);
|
|
||||||
}
|
|
||||||
// 非外链并且是一级目录(类型为目录)
|
|
||||||
if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType())
|
|
||||||
&& UserConstants.NO_FRAME.equals(menu.getIsFrame())) {
|
|
||||||
routerPath = "/" + menu.getPath();
|
|
||||||
}
|
|
||||||
// 非外链并且是一级目录(类型为菜单)
|
|
||||||
else if (isMenuFrame(menu)) {
|
|
||||||
routerPath = "/";
|
|
||||||
}
|
|
||||||
return routerPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取组件信息
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 组件信息
|
|
||||||
*/
|
|
||||||
public String getComponent(SysMenu menu) {
|
|
||||||
String component = UserConstants.LAYOUT;
|
|
||||||
if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) {
|
|
||||||
component = menu.getComponent();
|
|
||||||
} else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) {
|
|
||||||
component = UserConstants.INNER_LINK;
|
|
||||||
} else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) {
|
|
||||||
component = UserConstants.PARENT_VIEW;
|
|
||||||
}
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为菜单内部跳转
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public boolean isMenuFrame(SysMenu menu) {
|
|
||||||
return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType())
|
|
||||||
&& menu.getIsFrame().equals(UserConstants.NO_FRAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为内链组件
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public boolean isInnerLink(SysMenu menu) {
|
|
||||||
return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为parent_view组件
|
|
||||||
*
|
|
||||||
* @param menu 菜单信息
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public boolean isParentView(SysMenu menu) {
|
|
||||||
return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据父节点的ID获取所有子节点
|
* 根据父节点的ID获取所有子节点
|
||||||
*
|
*
|
||||||
@ -415,34 +328,14 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|||||||
*/
|
*/
|
||||||
private void recursionFn(List<SysMenu> list, SysMenu t) {
|
private void recursionFn(List<SysMenu> list, SysMenu t) {
|
||||||
// 得到子节点列表
|
// 得到子节点列表
|
||||||
List<SysMenu> childList = getChildList(list, t);
|
List<SysMenu> childList = StreamUtils.filter(list, n -> n.getParentId().equals(t.getMenuId()));
|
||||||
t.setChildren(childList);
|
t.setChildren(childList);
|
||||||
for (SysMenu tChild : childList) {
|
for (SysMenu tChild : childList) {
|
||||||
if (hasChild(list, tChild)) {
|
// 判断是否有子节点
|
||||||
|
if (list.stream().anyMatch(n -> n.getParentId().equals(tChild.getMenuId()))) {
|
||||||
recursionFn(list, tChild);
|
recursionFn(list, tChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 得到子节点列表
|
|
||||||
*/
|
|
||||||
private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) {
|
|
||||||
return StreamUtils.filter(list, n -> n.getParentId().equals(t.getMenuId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否有子节点
|
|
||||||
*/
|
|
||||||
private boolean hasChild(List<SysMenu> list, SysMenu t) {
|
|
||||||
return CollUtil.isNotEmpty(getChildList(list, t));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 内链域名特殊字符替换
|
|
||||||
*/
|
|
||||||
public String innerLinkReplaceEach(String path) {
|
|
||||||
return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."},
|
|
||||||
new String[]{"", "", "", "/"});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user