mirror of https://gitee.com/maxjhandsome/pig
end: 支持服务端动态路由
This commit is contained in:
parent
607ada9079
commit
3021ab3341
|
@ -11,7 +11,6 @@ import com.github.pig.common.web.BaseController;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -34,7 +33,7 @@ public class MenuController extends BaseController {
|
|||
*/
|
||||
@GetMapping("/findMenuByRole/{role}")
|
||||
public Set<MenuVo> findMenuByRole(@PathVariable String role) {
|
||||
return menuService.findMenuByRole(role);
|
||||
return menuService.findMenuByRole(role, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,9 +53,9 @@ public class MenuController extends BaseController {
|
|||
*
|
||||
* @return 树形菜单
|
||||
*/
|
||||
@GetMapping(value = "/userTree")
|
||||
public List<Integer> userTree(HttpServletRequest request) {
|
||||
Set<MenuVo> menus = menuService.findMenuByRole(getRole().get(0));
|
||||
@GetMapping("/userTree/{type}")
|
||||
public List<Integer> userTree(@PathVariable Integer type) {
|
||||
Set<MenuVo> menus = menuService.findMenuByRole(getRole().get(0), type);
|
||||
List<Integer> menuList = new ArrayList<>();
|
||||
for (MenuVo menuVo : menus) {
|
||||
menuList.add(menuVo.getMenuId());
|
||||
|
@ -64,7 +63,6 @@ public class MenuController extends BaseController {
|
|||
return menuList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过ID查询菜单的详细信息
|
||||
*
|
||||
|
@ -123,11 +121,13 @@ public class MenuController extends BaseController {
|
|||
node = new MenuTree();
|
||||
node.setId(menu.getMenuId());
|
||||
node.setParentId(menu.getParentId());
|
||||
node.setTitle(menu.getName());
|
||||
node.setHref(menu.getUrl());
|
||||
node.setPath(menu.getUrl());
|
||||
node.setName(menu.getName());
|
||||
node.setUrl(menu.getUrl());
|
||||
node.setPath(menu.getPath());
|
||||
node.setCode(menu.getPermission());
|
||||
node.setLabel(menu.getName());
|
||||
node.setComponent(menu.getComponent());
|
||||
node.setIcon(menu.getIcon());
|
||||
trees.add(node);
|
||||
}
|
||||
return TreeUtil.bulid(trees, root);
|
||||
|
|
|
@ -6,8 +6,8 @@ package com.github.pig.admin.dto;
|
|||
*/
|
||||
public class MenuTree extends TreeNode {
|
||||
private String icon;
|
||||
private String title;
|
||||
private String href;
|
||||
private String name;
|
||||
private String url;
|
||||
private boolean spread = false;
|
||||
private String path;
|
||||
private String component;
|
||||
|
@ -72,14 +72,14 @@ public class MenuTree extends TreeNode {
|
|||
public MenuTree(int id, String name, int parentId) {
|
||||
this.id = id;
|
||||
this.parentId = parentId;
|
||||
this.title = name;
|
||||
this.name = name;
|
||||
this.label = name;
|
||||
}
|
||||
|
||||
public MenuTree(int id, String name, MenuTree parent) {
|
||||
this.id = id;
|
||||
this.parentId = parent.getId();
|
||||
this.title = name;
|
||||
this.name = name;
|
||||
this.label = name;
|
||||
}
|
||||
|
||||
|
@ -91,20 +91,20 @@ public class MenuTree extends TreeNode {
|
|||
this.icon = icon;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getHref() {
|
||||
return href;
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setHref(String href) {
|
||||
this.href = href;
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public boolean isSpread() {
|
||||
|
|
|
@ -82,6 +82,10 @@ public class SysMenu extends Model<SysMenu> {
|
|||
*/
|
||||
@TableField("del_flag")
|
||||
private String delFlag;
|
||||
/**
|
||||
* 前端URL
|
||||
*/
|
||||
private String path;
|
||||
|
||||
|
||||
public Integer getMenuId() {
|
||||
|
@ -188,6 +192,14 @@ public class SysMenu extends Model<SysMenu> {
|
|||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.menuId;
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.github.pig.admin.mapper;
|
|||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
||||
import com.github.pig.admin.entity.SysMenu;
|
||||
import com.github.pig.common.vo.MenuVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -20,7 +21,8 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
|||
* 通过角色名查询菜单
|
||||
*
|
||||
* @param role 角色名称
|
||||
* @param type 是不是查询全部
|
||||
* @return 菜单列表
|
||||
*/
|
||||
Set<MenuVo> findMenuByRoleName(String role);
|
||||
Set<MenuVo> findMenuByRoleName(@Param("role") String role, @Param("type") Integer type);
|
||||
}
|
|
@ -20,9 +20,10 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||
* 通过角色名称查询URL 权限
|
||||
*
|
||||
* @param role 角色名称
|
||||
* @param type 是否全部
|
||||
* @return 菜单列表
|
||||
*/
|
||||
Set<MenuVo> findMenuByRole(String role);
|
||||
Set<MenuVo> findMenuByRole(String role, Integer type);
|
||||
|
||||
/**
|
||||
* 通过角色获取菜单权限列表
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.github.pig.admin.service.SysMenuService;
|
|||
import com.github.pig.common.vo.MenuVo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
@ -27,16 +26,16 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
private SysMenuMapper sysMenuMapper;
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "menu_details", key = "#role +'_menu'")
|
||||
public Set<MenuVo> findMenuByRole(String role) {
|
||||
return sysMenuMapper.findMenuByRoleName(role);
|
||||
//@Cacheable(value = "menu_details", key = "#role +'_menu'")
|
||||
public Set<MenuVo> findMenuByRole(String role, Integer type) {
|
||||
return sysMenuMapper.findMenuByRoleName(role, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] findPermission(String[] roles) {
|
||||
Set<MenuVo> menuVoSet = new HashSet<>();
|
||||
for (String role : roles) {
|
||||
Set<MenuVo> menuVos = findMenuByRole(role);
|
||||
Set<MenuVo> menuVos = findMenuByRole(role, 0);
|
||||
menuVoSet.addAll(menuVos);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<result column="name" property="name" />
|
||||
<result column="permission" property="permission" />
|
||||
<result column="url" property="url" />
|
||||
<result column="path" property="path" />
|
||||
<result column="method" property="method" />
|
||||
<result column="parent_id" property="parentId" />
|
||||
<result column="icon" property="icon" />
|
||||
|
@ -45,7 +46,9 @@
|
|||
WHERE
|
||||
sys_role.del_flag = 0
|
||||
AND sys_menu.del_flag = 0
|
||||
AND sys_menu.url IS NOT NULL AND
|
||||
sys_role.role_code = #{role}
|
||||
AND sys_role.role_code = #{role}
|
||||
<if test="type == 0">
|
||||
AND sys_menu.url IS NOT NULL
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue