Browse Source

增加顶部菜单功能

test
smallchill 6 years ago
parent
commit
5b9041d6ed
  1. 20
      blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java
  2. 3
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java
  3. 15
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml
  4. 3
      blade-service/blade-system/src/main/java/org/springblade/system/service/IMenuService.java
  5. 4
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

20
blade-service/blade-system/src/main/java/org/springblade/system/controller/MenuController.java

@ -27,7 +27,9 @@ import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.entity.Menu;
import org.springblade.system.entity.TopMenu;
import org.springblade.system.service.IMenuService;
import org.springblade.system.service.ITopMenuService;
import org.springblade.system.vo.CheckedTreeVO;
import org.springblade.system.vo.GrantTreeVO;
import org.springblade.system.vo.MenuVO;
@ -55,6 +57,7 @@ import static org.springblade.core.cache.constant.CacheConstant.MENU_CACHE;
public class MenuController extends BladeController {
private IMenuService menuService;
private ITopMenuService topMenuService;
/**
* 详情
@ -131,8 +134,8 @@ public class MenuController extends BladeController {
@GetMapping("/routes")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "前端菜单数据", notes = "前端菜单数据")
public R<List<MenuVO>> routes(BladeUser user) {
List<MenuVO> list = menuService.routes((user == null) ? null : user.getRoleId());
public R<List<MenuVO>> routes(BladeUser user, Long topMenuId) {
List<MenuVO> list = menuService.routes((user == null) ? null : user.getRoleId(), topMenuId);
return R.data(list);
}
@ -210,11 +213,22 @@ public class MenuController extends BladeController {
return R.data(vo);
}
/**
* 顶部菜单数据
*/
@GetMapping("/top-menu")
@ApiOperationSupport(order = 12)
@ApiOperation(value = "顶部菜单数据", notes = "顶部菜单数据")
public R<List<TopMenu>> topMenu() {
List<TopMenu> list = topMenuService.list();
return R.data(list);
}
/**
* 获取配置的角色权限
*/
@GetMapping("auth-routes")
@ApiOperationSupport(order = 12)
@ApiOperationSupport(order = 13)
@ApiOperation(value = "菜单的角色权限")
public R<List<Kv>> authRoutes(BladeUser user) {
if (Func.isEmpty(user)) {

3
blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.java

@ -119,9 +119,10 @@ public interface MenuMapper extends BaseMapper<Menu> {
* 权限配置菜单
*
* @param roleId
* @param topMenuId
* @return
*/
List<Menu> roleMenu(List<Long> roleId);
List<Menu> roleMenu(List<Long> roleId, Long topMenuId);
/**
* 菜单树形结构

15
blade-service/blade-system/src/main/java/org/springblade/system/mapper/MenuMapper.xml

@ -40,12 +40,19 @@
</select>
<select id="roleMenu" resultMap="menuResultMap">
select * from blade_menu where is_deleted = 0 and id IN ( SELECT menu_id FROM blade_role_menu WHERE role_id IN
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
select * from blade_menu where is_deleted = 0 and id IN
( SELECT menu_id FROM blade_role_menu WHERE role_id IN
<foreach collection="param1" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach> )
</foreach>
)
<if test="param2!=null and param2>0">
AND id IN
(
SELECT menu_id FROM blade_top_menu_setting WHERE top_menu_id = #{param2}
)
</if>
</select>
<select id="routes" resultMap="menuResultMap">
SELECT
*

3
blade-service/blade-system/src/main/java/org/springblade/system/service/IMenuService.java

@ -45,9 +45,10 @@ public interface IMenuService extends IService<Menu> {
* 菜单树形结构
*
* @param roleId
* @param topMenuId
* @return
*/
List<MenuVO> routes(String roleId);
List<MenuVO> routes(String roleId, Long topMenuId);
/**
* 按钮树形结构

4
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/MenuServiceImpl.java

@ -66,12 +66,12 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
}
@Override
public List<MenuVO> routes(String roleId) {
public List<MenuVO> routes(String roleId, Long topMenuId) {
if (StringUtil.isBlank(roleId)) {
return null;
}
List<Menu> allMenus = baseMapper.allMenu();
List<Menu> roleMenus = baseMapper.roleMenu(Func.toLongList(roleId));
List<Menu> roleMenus = baseMapper.roleMenu(Func.toLongList(roleId), topMenuId);
return buildRoutes(allMenus, roleMenus);
}

Loading…
Cancel
Save