mirror of https://gitee.com/stylefeng/roses
【menu】更新antdv需要的一个获取所有菜单接口
parent
d5d598631d
commit
e2e1a15d10
|
@ -26,9 +26,4 @@ public class SimpleRoleInfo {
|
|||
*/
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 数据范围类型:10-仅本人数据,20-本部门数据,30-本部门及以下数据,40-指定部门数据,50-全部数据
|
||||
*/
|
||||
private Integer dataScopeType;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.menu.antd;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统菜单
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/7 15:18
|
||||
*/
|
||||
@Data
|
||||
public class AntdSysMenuResponse {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 父id,顶级节点的父id是-1
|
||||
*/
|
||||
private Long menuParentId;
|
||||
|
||||
/**
|
||||
* 菜单的名称
|
||||
*/
|
||||
private String menuName;
|
||||
|
||||
/**
|
||||
* 路由地址,浏览器显示的URL,例如/menu,适用于antd vue版本
|
||||
*/
|
||||
private String antdvRouter;
|
||||
|
||||
/**
|
||||
* 前端用路径,适用于antdvue版本
|
||||
*/
|
||||
private String antdvPath;
|
||||
|
||||
/**
|
||||
* 图标,适用于antd vue版本
|
||||
*/
|
||||
private String antdvIcon;
|
||||
|
||||
/**
|
||||
* 子节点(表中不存在,用于构造树)
|
||||
*/
|
||||
private List children;
|
||||
|
||||
/**
|
||||
* 菜单可以被那些角色访问
|
||||
*/
|
||||
private List<SimpleRoleInfo> roles;
|
||||
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.menu.response;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractTreeNode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统菜单
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/7 15:18
|
||||
*/
|
||||
@Data
|
||||
public class SysMenuResponse implements AbstractTreeNode {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 父id,顶级节点的父id是-1
|
||||
*/
|
||||
private Long menuParentId;
|
||||
|
||||
/**
|
||||
* 父id集合,中括号包住,逗号分隔
|
||||
*/
|
||||
private String menuPids;
|
||||
|
||||
/**
|
||||
* 菜单的名称
|
||||
*/
|
||||
private String menuName;
|
||||
|
||||
/**
|
||||
* 应用编码
|
||||
*/
|
||||
private String appCode;
|
||||
|
||||
/**
|
||||
* 是否可见:Y-是,N-否
|
||||
*/
|
||||
private String visible;
|
||||
|
||||
/**
|
||||
* 路由地址,浏览器显示的URL,例如/menu,适用于antd vue版本
|
||||
*/
|
||||
private String antdvRouter;
|
||||
|
||||
/**
|
||||
* 前端组件名,适用于antd vue版本
|
||||
*/
|
||||
private String antdvComponent;
|
||||
|
||||
/**
|
||||
* 图标,适用于antd vue版本
|
||||
*/
|
||||
private String antdvIcon;
|
||||
|
||||
/**
|
||||
* 外部链接打开方式:1-内置打开外链,2-新页面外链,适用于antd vue版本
|
||||
*/
|
||||
private Integer antdvLinkOpenType;
|
||||
|
||||
/**
|
||||
* 外部链接地址
|
||||
*/
|
||||
private String antdvLinkUrl;
|
||||
|
||||
/**
|
||||
* 子节点(表中不存在,用于构造树)
|
||||
*/
|
||||
private List children;
|
||||
|
||||
/**
|
||||
* 菜单可以被那些角色访问
|
||||
*/
|
||||
private List<SimpleRoleInfo> roles;
|
||||
|
||||
@Override
|
||||
public String getNodeId() {
|
||||
return menuId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeParentId() {
|
||||
return menuParentId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChildrenNodes(List childrenNodes) {
|
||||
this.children = childrenNodes;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.menu.modular.factory.AntdMenusFactory;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.pojo.AntdvMenuItem;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.service.SysMenuService;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
|
||||
|
@ -7,7 +9,7 @@ import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
|
|||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
@ -143,15 +145,16 @@ public class SysMenuController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取系统所有菜单
|
||||
* 获取系统所有菜单(适用于登录后获取左侧菜单)(适配antd vue版本)
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/1/7 15:17
|
||||
*/
|
||||
@GetResource(name = "获取菜单列表(包含菜单可以被那些角色访问)", path = "/sysMenu/getSystemAllMenus", requiredPermission = false)
|
||||
public ResponseData getSystemAllMenus() {
|
||||
List<SysMenuResponse> sysMenuResponses = sysMenuService.getSystemAllMenus();
|
||||
return new SuccessResponseData(sysMenuResponses);
|
||||
@GetResource(name = "获取系统所有菜单(适用于登录后获取左侧菜单)(适配antd vue版本)", path = "/sysMenu/getSystemAllMenusAntdv", requiredPermission = false)
|
||||
public ResponseData getSystemAllMenusAntdv() {
|
||||
List<AntdSysMenuResponse> sysMenuResponses = sysMenuService.getSystemAllMenusAntdv();
|
||||
List<AntdvMenuItem> totalMenus = AntdMenusFactory.createTotalMenus(sysMenuResponses);
|
||||
return new SuccessResponseData(totalMenus);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -101,10 +101,10 @@ public class SysMenu extends BaseEntity implements AbstractTreeNode {
|
|||
private String antdvRouter;
|
||||
|
||||
/**
|
||||
* 前端组件名,适用于antd vue版本
|
||||
* 前端用路径,适用于antdvue版本
|
||||
*/
|
||||
@TableField("antdv_component")
|
||||
private String antdvComponent;
|
||||
@TableField("antdv_path")
|
||||
private String antdvPath;
|
||||
|
||||
/**
|
||||
* 图标,适用于antd vue版本
|
||||
|
@ -112,6 +112,12 @@ public class SysMenu extends BaseEntity implements AbstractTreeNode {
|
|||
@TableField("antdv_icon")
|
||||
private String antdvIcon;
|
||||
|
||||
/**
|
||||
* 前端组件名,适用于antd vue版本
|
||||
*/
|
||||
@TableField("antdv_component")
|
||||
private String antdvComponent;
|
||||
|
||||
/**
|
||||
* 外部链接打开方式:1-内置打开外链,2-新页面外链,适用于antd vue版本
|
||||
*/
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.factory;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.pojo.AntdvMenuItem;
|
||||
import cn.stylefeng.roses.kernel.menu.modular.pojo.AuthorityItem;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
|
||||
import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdIndexMenuTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -16,6 +21,50 @@ import java.util.List;
|
|||
*/
|
||||
public class AntdMenusFactory {
|
||||
|
||||
/**
|
||||
* 组装antdv用的获取所有菜单列表详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/7 18:17
|
||||
*/
|
||||
public static List<AntdvMenuItem> createTotalMenus(List<AntdSysMenuResponse> antdSysMenuResponses) {
|
||||
|
||||
ArrayList<AntdvMenuItem> antdvMenuItems = new ArrayList<>(antdSysMenuResponses.size());
|
||||
|
||||
// 实体转化
|
||||
for (AntdSysMenuResponse antdSysMenuResponse : antdSysMenuResponses) {
|
||||
AntdvMenuItem antdvMenuItem = new AntdvMenuItem();
|
||||
|
||||
// 填充id pid name用于构建树
|
||||
antdvMenuItem.setMenuId(antdSysMenuResponse.getMenuId());
|
||||
antdvMenuItem.setMenuParentId(antdSysMenuResponse.getMenuParentId());
|
||||
antdvMenuItem.setName(antdSysMenuResponse.getMenuName());
|
||||
|
||||
// 填充路由等信息
|
||||
antdvMenuItem.setRouter(antdSysMenuResponse.getAntdvRouter());
|
||||
antdvMenuItem.setIcon(antdSysMenuResponse.getAntdvIcon());
|
||||
antdvMenuItem.setPath(antdSysMenuResponse.getAntdvPath());
|
||||
|
||||
// 填充哪个角色绑定了这个菜单
|
||||
List<SimpleRoleInfo> roles = antdSysMenuResponse.getRoles();
|
||||
AuthorityItem authorityItem = new AuthorityItem();
|
||||
if (roles != null) {
|
||||
ArrayList<String> auths = new ArrayList<>();
|
||||
for (SimpleRoleInfo role : roles) {
|
||||
auths.add(role.getRoleCode());
|
||||
}
|
||||
authorityItem.setPermission(auths);
|
||||
authorityItem.setRole(auths);
|
||||
antdvMenuItem.setAuthority(authorityItem);
|
||||
}
|
||||
|
||||
antdvMenuItems.add(antdvMenuItem);
|
||||
}
|
||||
|
||||
// 构造菜单树
|
||||
return new DefaultTreeBuildFactory<AntdvMenuItem>().doTreeBuild(antdvMenuItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据库表的菜单,转化为vue antd admin识别的菜单路由格式
|
||||
*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,10 +15,12 @@ import java.util.List;
|
|||
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
|
||||
/**
|
||||
* 获取系统所有菜单
|
||||
* 获取系统所有菜单(适用于登录后获取左侧菜单)(适配antd vue版本)
|
||||
*
|
||||
* @return 系统所有菜单问题
|
||||
* @author majianguo
|
||||
* @date 2021/1/7 15:27
|
||||
*/
|
||||
List<SysMenuResponse> getSystemAllMenus();
|
||||
List<AntdSysMenuResponse> getSystemAllMenus();
|
||||
|
||||
}
|
||||
|
|
|
@ -2,46 +2,35 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.menu.modular.mapper.SysMenuMapper">
|
||||
|
||||
<resultMap id="systemMenuAndRole" type="cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse">
|
||||
<resultMap id="systemMenuAndRole" type="cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse">
|
||||
<id column="menu_id" property="menuId"/>
|
||||
<result column="menu_parent_id" property="menuParentId"/>
|
||||
<result column="menu_pids" property="menuPids"/>
|
||||
<result column="menu_name" property="menuName"/>
|
||||
<result column="app_code" property="appCode"/>
|
||||
<result column="visible" property="visible"/>
|
||||
<result column="antdv_router" property="antdvRouter"/>
|
||||
<result column="antdv_component" property="antdvComponent"/>
|
||||
<result column="antdv_path" property="antdvPath"/>
|
||||
<result column="antdv_icon" property="antdvIcon"/>
|
||||
<result column="antdv_link_open_type" property="antdvLinkOpenType"/>
|
||||
<result column="antdv_link_url" property="antdvLinkUrl"/>
|
||||
<collection property="roles" ofType="cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo">
|
||||
<id column="role_id" property="roleId"/>
|
||||
<result column="role_name" property="roleName"/>
|
||||
<result column="role_code" property="roleCode"/>
|
||||
<result column="data_scope_type" property="dataScopeType"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="getSystemAllMenus" resultMap="systemMenuAndRole">
|
||||
SELECT sm.menu_id,
|
||||
sm.menu_parent_id,
|
||||
sm.menu_pids,
|
||||
sm.menu_name,
|
||||
sm.app_code,
|
||||
sm.visible,
|
||||
sm.antdv_router,
|
||||
sm.antdv_component,
|
||||
sm.antdv_path,
|
||||
sm.antdv_icon,
|
||||
sm.antdv_link_open_type,
|
||||
sm.antdv_link_url,
|
||||
sr.role_id,
|
||||
sr.role_name,
|
||||
sr.role_code,
|
||||
sr.data_scope_type
|
||||
sr.role_code
|
||||
FROM sys_menu sm
|
||||
LEFT JOIN sys_role_menu srm ON sm.menu_id = srm.menu_id
|
||||
LEFT JOIN sys_role sr ON srm.role_id = sr.role_id
|
||||
WHERE sm.del_flag = 'N'
|
||||
AND sm.status_flag = 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractTreeNode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用于antdv的菜单响应
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/7 18:09
|
||||
*/
|
||||
@Data
|
||||
public class AntdvMenuItem implements AbstractTreeNode {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 父id,顶级节点的父id是-1
|
||||
*/
|
||||
private Long menuParentId;
|
||||
|
||||
/**
|
||||
* 路由信息
|
||||
*/
|
||||
private String router;
|
||||
|
||||
/**
|
||||
* 图标信息
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 路径信息
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 路由信息
|
||||
*/
|
||||
private AuthorityItem authority;
|
||||
|
||||
/**
|
||||
* 子菜单集合
|
||||
*/
|
||||
private List<AntdvMenuItem> children;
|
||||
|
||||
@Override
|
||||
public String getNodeId() {
|
||||
return menuId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeParentId() {
|
||||
return menuParentId.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChildrenNodes(List childrenNodes) {
|
||||
this.children = childrenNodes;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cn.stylefeng.roses.kernel.menu.modular.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单被哪个权限绑定的详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/7 18:16
|
||||
*/
|
||||
@Data
|
||||
public class AuthorityItem {
|
||||
|
||||
/**
|
||||
* 权限编码
|
||||
*/
|
||||
private List<String> permission;
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*/
|
||||
private List<String> role;
|
||||
|
||||
}
|
|
@ -27,9 +27,9 @@ package cn.stylefeng.roses.kernel.menu.modular.service;
|
|||
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdIndexMenuTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiAppIndexMenus;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.other.MenuSelectTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
|
@ -163,10 +163,12 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||
List<MenuSelectTreeNode> treeForGrant(SysMenuRequest sysMenuRequest);
|
||||
|
||||
/**
|
||||
* 获取系统所有菜单
|
||||
* 获取系统所有菜单(适用于登录后获取左侧菜单)(适配antd vue版本)
|
||||
*
|
||||
* @return 系统所有菜单信息
|
||||
* @author majianguo
|
||||
* @date 2021/1/7 15:24
|
||||
*/
|
||||
List<SysMenuResponse> getSystemAllMenus();
|
||||
List<AntdSysMenuResponse> getSystemAllMenusAntdv();
|
||||
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ import cn.stylefeng.roses.kernel.system.exception.enums.SysMenuExceptionEnum;
|
|||
import cn.stylefeng.roses.kernel.system.exception.enums.SysUserExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdIndexMenuTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiAppIndexMenus;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.other.MenuSelectTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
|
@ -288,9 +288,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuResponse> getSystemAllMenus() {
|
||||
List<SysMenuResponse> responses = this.baseMapper.getSystemAllMenus();
|
||||
return new DefaultTreeBuildFactory<SysMenuResponse>().doTreeBuild(responses);
|
||||
public List<AntdSysMenuResponse> getSystemAllMenusAntdv() {
|
||||
return this.baseMapper.getSystemAllMenus();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue